Skip to content

Commit

Permalink
[BE] Env/#545 무중단 배포를 위한 구성 파일 작성 (#571)
Browse files Browse the repository at this point in the history
* feat: 무중단 배포를 위한 구성 파일 작성

Co-authored-by: kpeel5839 <89840550+kpeel5839@users.noreply.github.com>

* feat: datasource docker url로 수정

* feat: 도커 이미지 빌드를 위한 파일 작성

Co-authored-by: kpeel5839 <89840550+kpeel5839@users.noreply.github.com>

* feat: 개발서버, 운영서버 콘솔 로그 추가

Co-authored-by: kpeel5839 <89840550+kpeel5839@users.noreply.github.com>

* feat: 무중단 배포를 위한 워크플로우 수정 및 작성

Co-authored-by: kpeel5839 <89840550+kpeel5839@users.noreply.github.com>

---------

Co-authored-by: kpeel5839 <89840550+kpeel5839@users.noreply.github.com>
  • Loading branch information
yoondgu and kpeel5839 authored Oct 13, 2023
1 parent 2e1befb commit 2617795
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 37 deletions.
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

0 comments on commit 2617795

Please sign in to comment.