Skip to content

Commit

Permalink
merge: Feature/#177 production develop 서버 배포 자동화 스크립트 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
hyeonjerry authored Aug 2, 2023
2 parents 1692fda + 29c4177 commit 5db9a0e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 33 deletions.
64 changes: 32 additions & 32 deletions .github/workflows/backend-dev-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,9 @@ name: Kerdy Backend Dev Server CI/CD
on:
workflow_dispatch:

permissions:
contents: read

jobs:
build-and-upload:
build:
name: 빌드
runs-on: ubuntu-22.04
defaults:
run:
Expand All @@ -25,57 +23,59 @@ jobs:
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- name: 선택된 브랜치로 checkout
- name: workflow_dispatch에서 지정한 branch로 checkout
uses: actions/checkout@v3
with:
token: ${{ secrets.SUBMODULE_TOKEN }}
submodules: true

- name: JDK 11로 설정
uses: actions/setup-java@v3
with:
java-version: 11
distribution: 'temurin'
distribution: 'corretto'

- name: Gradle에 실행 권한 부여
run: chmod +x gradlew

- name: Gradle 캐싱
- name: Actions/Caches에 Gradle 라이브러리 캐싱
id: cache-gradle
uses: actions/cache@v3
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: |
${{ runner.os }}-gradle-
restore-keys: ${{ runner.os }}-gradle-
# RestDocs의 index.html 업데이트 반영을 위해 2번 build하도록 함
- name: gradle 빌드
run: ./gradlew build && ./gradlew build

- name: 도커 빌더 생성 및 부팅
uses: docker/setup-buildx-action@v2

- name: jar artifact에 업로드
uses: actions/upload-artifact@v3
- name: 도커 허브에 로그인
uses: docker/login-action@v2
with:
name: BackendApplicationJar
path: backend/emm-sale/build/libs/*.jar

deploy:
runs-on: self-hosted
needs: build-and-upload
steps:
- name: 구버전 jar 삭제
run: rm -rf /home/ubuntu/backend/build/emm-sale-*.jar
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: artifact에서 jar파일 다운 받기
uses: actions/download-artifact@v3
- name: 도커 이미지 빌드 및 푸시
uses: docker/build-push-action@v4
with:
name: BackendApplicationJar
path: /home/ubuntu/backend/build/

- name: 권한부여
run: chmod +x /home/ubuntu/backend/build/emm-sale-*.jar
context: backend/emm-sale
file: backend/emm-sale/Dockerfile-dev
platforms: linux/arm64/v8
push: true
tags: ${{ secrets.DOCKERHUB_USERNAME }}/kerdy-dev:latest

- name: 배포하기
run: /home/ubuntu/backend/build/deploy.sh
deploy:
needs: build
name: 배포
runs-on: [ self-hosted, label-dev ]
steps:
- name: 도커 실행
run: |
docker stop kerdy && docker rm kerdy && docker rmi ${{ secrets.DOCKERHUB_USERNAME }}/kerdy-dev
docker run -d -p 8080:8080 --name kerdy ${{ secrets.DOCKERHUB_USERNAME }}/kerdy-dev
- name: 슬랙 메시지 보내기
uses: 8398a7/action-slack@v3
Expand Down
12 changes: 12 additions & 0 deletions .github/workflows/backend-prod-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ on:

jobs:
build:
name: 빌드
runs-on: ubuntu-22.04
defaults:
run:
Expand Down Expand Up @@ -82,3 +83,14 @@ jobs:
run: |
docker stop kerdy && docker rm kerdy && docker rmi ${{ secrets.DOCKERHUB_USERNAME }}/kerdy
docker run -d -p 8080:8080 --name kerdy ${{ secrets.DOCKERHUB_USERNAME }}/kerdy
- name: 슬랙 메시지 보내기
uses: 8398a7/action-slack@v3
with:
mention: 'here'
if_mention: failure
status: ${{ job.status }}
fields: workflow,job,commit,message,ref,author,took
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
if: always()
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:11 as build
ARG JAR_FILE=build/libs/*.jar
COPY ${JAR_FILE} kerdy.jar
ENTRYPOINT ["java","-jar","/kerdy.jar"]
ENTRYPOINT ["java","-Dspring.profiles.active=dev","-jar","/kerdy.jar"]

0 comments on commit 5db9a0e

Please sign in to comment.