Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] Env/#545 무중단 배포를 위한 구성 파일 작성 #571

Merged
merged 5 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions .github/workflows/be-merge-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,22 @@ jobs:
- name: Gradle build 시작
run: ./gradlew clean build
working-directory: backend

- name: jar 파일 artifact에 업로드
uses: actions/upload-artifact@v3

- name: Docker buildx 설치
uses: docker/setup-buildx-action@v2.9.1

- name: Docker Hub 로그인
uses: docker/login-action@v2.2.0
with:
name: BackendApplication
path: backend/build/libs/mapbefine.jar
username: ${{ secrets.DOCKERHUB_DEV_USERNAME }}
password: ${{ secrets.DOCKERHUB_DEV_TOKEN }}

- name: Docker Image Build
working-directory: backend
run: docker build --platform linux/arm64/v8 -t mapbefine/mapbefine -f Dockerfile-dev .

- name: Docker Hub Push
run: docker push mapbefine/mapbefine

deploy:
if: github.event.pull_request.merged
Expand All @@ -54,17 +64,15 @@ jobs:
needs: build-and-upload

steps:
- name: 구버전 jar 파일 삭제
run: rm -rf /home/ubuntu/backend/build/*.jar

- name: jar파일 artifact에서 다운로드
uses: actions/download-artifact@v3
with:
name: BackendApplication
path: /home/ubuntu/backend/build/
- name: 최신 Docker Image 가져오기
run: |
sudo docker login --username ${{ secrets.DOCKERHUB_DEV_USERNAME }} --password ${{ secrets.DOCKERHUB_DEV_TOKEN }}
sudo docker pull mapbefine/mapbefine:latest

- name: 배포하기
run: /home/ubuntu/backend/deploy.sh
- name: Docker Compose
run: |
sudo sh /home/ubuntu/backend/zero-downtime-deploy.sh
sudo docker image prune -af

- name: 슬랙 메시지 보내기

Expand Down
50 changes: 29 additions & 21 deletions .github/workflows/be-merge-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ name: Backend production CI/CD

on:
workflow_dispatch:

pull_request:
branches: [ main ]
types: [ closed ]
paths: backend/**

permissions:
contents: read

jobs:
build-and-upload:
build-and-upload:
if: github.event.pull_request.merged

runs-on: ubuntu-22.04

steps:
Expand All @@ -41,30 +41,38 @@ jobs:
run: ./gradlew clean build
working-directory: backend

- name: jar 파일 artifact에 업로드
uses: actions/upload-artifact@v3
- name: Docker buildx 설치
uses: docker/setup-buildx-action@v2.9.1

- name: Docker Hub 로그인
uses: docker/login-action@v2.2.0
with:
name: BackendApplication
path: backend/build/libs/mapbefine.jar
username: ${{ secrets.DOCKERHUB_DEV_USERNAME }}
password: ${{ secrets.DOCKERHUB_DEV_TOKEN }}

- name: Docker Image Build
working-directory: backend
run: docker build --platform linux/arm64/v8 -t mapbefine/mapbefine -f Dockerfile-dev .

- name: Docker Hub Push
run: docker push mapbefine/mapbefine

deploy:
if: github.event.pull_request.merged

runs-on: [ self-hosted, prod ]
needs: build-and-upload

if: github.event.pull_request.merged

steps:
- name: 구버전 jar 파일 삭제
run: rm -rf /home/ubuntu/backend/build/*.jar

- name: jar파일 artifact에서 다운로드
uses: actions/download-artifact@v3
with:
name: BackendApplication
path: /home/ubuntu/backend/build/
steps:
- name: 최신 Docker Image 가져오기
run: |
sudo docker login --username ${{ secrets.DOCKERHUB_DEV_USERNAME }} --password ${{ secrets.DOCKERHUB_DEV_TOKEN }}
sudo docker pull mapbefine/mapbefine:latest

- name: 배포하기
run: /home/ubuntu/backend/deploy.sh
- name: Docker Compose
run: |
sudo sh /home/ubuntu/backend/zero-downtime-deploy.sh
sudo docker image prune -af

- name: 슬랙 메시지 보내기

Expand Down
3 changes: 3 additions & 0 deletions backend/Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM openjdk:17
COPY build/libs/mapbefine.jar mapbefine.jar
ENTRYPOINT ["java", "-jar","-Dspring.profiles.active=dev", "mapbefine.jar"]
3 changes: 3 additions & 0 deletions backend/Dockerfile-prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM openjdk:17
COPY build/libs/mapbefine.jar mapbefine.jar
ENTRYPOINT ["java", "-jar","-Dspring.profiles.active=prod", "mapbefine.jar"]
2 changes: 1 addition & 1 deletion backend/src/main/resources/config
4 changes: 4 additions & 0 deletions backend/src/main/resources/logback-spring.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
</springProfile>

<springProfile name="dev">
<include resource="logback/console-appender.xml"/>
<include resource="logback/file-hibernate-appender.xml"/>
<include resource="logback/file-debug-appender.xml"/>
<include resource="logback/file-warn-appender.xml"/>
<include resource="logback/file-error-appender.xml"/>

<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE_WARN"/>
<appender-ref ref="FILE_ERROR"/>
</root>
Expand All @@ -36,12 +38,14 @@
</springProfile>

<springProfile name="prod">
<include resource="logback/console-appender.xml"/>
<include resource="logback/file-info-appender.xml"/>
<include resource="logback/file-warn-appender.xml"/>
<include resource="logback/file-error-appender.xml"/>
<include resource="logback/slack-error-appender.xml"/>

<root level="INFO">
<appender-ref ref="CONSOLE"/>
<appender-ref ref="FILE_WARN"/>
<appender-ref ref="FILE_ERROR"/>
<appender-ref ref="SLACK_ERROR"/>
Expand Down