-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from studio-recoding/feat-prod-cicd
[feat] 개발용과 릴리즈용 CI/CD 구분
- Loading branch information
Showing
5 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
name: Deploy to Prod | ||
|
||
## main에 릴리즈가 일어날 때마다 빌드 및 배포 | ||
on: | ||
push: | ||
branches: [ main ] | ||
tags: [ "v*.*.*" ] | ||
|
||
jobs: | ||
build: | ||
## checkout 후 자바 17 버전으로 설정 | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: '17' | ||
distribution: 'temurin' | ||
|
||
## gradlew에 권한 부여 | ||
- name: Grant execute permission for gradlew | ||
run: chmod +x gradlew | ||
|
||
## Copy properties files | ||
- name: Make application-prod.yml | ||
run: | | ||
touch ./src/main/resources/application-prod.yml | ||
echo "$PROPERTIES_PROD" > ./src/main/resources/application-prod.yml | ||
# Make env file | ||
env: | ||
PROPERTIES_PROD: ${{ secrets.PROPERTIES_PROD }} | ||
|
||
## gradle build | ||
- name: Build with Gradle | ||
run: ./gradlew clean build | ||
|
||
## docker metadata(namespace/repository) | ||
- name: Docker meta | ||
id: docker_meta | ||
uses: crazy-max/ghaction-docker-meta@v1 | ||
with: | ||
images: jeonhaeseung/ness-server-prod | ||
tag-semver: | | ||
{{version}} | ||
{{major}}.{{minor}} | ||
## 멀티-플랫폼 빌드 도구 Buildx 사용 | ||
- name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v1 | ||
|
||
## DockerHub에 로그인 | ||
- name: Login to DockerHub | ||
uses: docker/login-action@v1 | ||
with: | ||
username: ${{ secrets.DOCKER_USERNAME }} | ||
password: ${{ secrets.DOCKER_PASSWORD }} | ||
|
||
## 위에서 설정한 테그를 참고해 push | ||
- name: Docker build & push | ||
uses: docker/build-push-action@v2 | ||
with: | ||
context: . | ||
file: ./Dockerfile.prod | ||
platforms: linux/amd64 | ||
push: true | ||
tags: ${{ steps.docker_meta.outputs.tags }} | ||
labels: ${{ steps.docker_meta.outputs.labels }} | ||
|
||
## 원격에 접속 및 디렉토리 생성 | ||
- name: create remote directory | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.HOST_PROD }} | ||
username: ${{ secrets.USER_PROD }} | ||
key: ${{ secrets.KEY_PROD }} | ||
script: mkdir -p ./prod | ||
|
||
## 소스 코드 복사 붙여넣기 | ||
- name: copy source via ssh key | ||
uses: burnett01/[email protected] | ||
with: | ||
switches: -avzr --delete | ||
remote_path: ./prod | ||
remote_host: ${{ secrets.HOST_PROD }} | ||
remote_user: ${{ secrets.USER_PROD }} | ||
remote_key: ${{ secrets.KEY_PROD }} | ||
|
||
## EC2에 배포(CD) | ||
- name: executing remote ssh commands using password | ||
uses: appleboy/ssh-action@master | ||
with: | ||
host: ${{ secrets.HOST_PROD }} | ||
username: ${{ secrets.USER_PROD }} | ||
key: ${{ secrets.KEY_PROD }} | ||
script: | | ||
sh ./prod/config/scripts/deploy.sh | ||
sudo docker stop $(sudo docker ps -a -q) | ||
sudo docker rm $(sudo docker ps -a -q) | ||
sudo docker rmi $(sudo docker images -q) | ||
docker pull jeonhaeseung/ness-server-prod:prod | ||
docker run -d --name backend-server -p 8080:8080 --restart unless-stopped jeonhaeseung/ness-server-prod:prod |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,4 +37,5 @@ out/ | |
.vscode/ | ||
|
||
### Secrets ### | ||
application-dev.yml | ||
application-dev.yml | ||
application-prod.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
FROM openjdk:17-alpine AS builder | ||
ARG JAR_FILE=build/libs/*.jar | ||
COPY ${JAR_FILE} app.jar | ||
ENTRYPOINT ["java","-jar","/app.jar"] | ||
ENTRYPOINT ["java","-jar", "-Dspring.profiles.active=dev", "/app.jar"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
FROM openjdk:17-alpine AS builder | ||
ARG JAR_FILE=build/libs/*.jar | ||
COPY ${JAR_FILE} app.jar | ||
ENTRYPOINT ["java","-jar", "-Dspring.profiles.active=prod", "/app.jar"] |