From 9f80bf2293bdfd02c536a19ba980ba779a268309 Mon Sep 17 00:00:00 2001 From: HyeonjaeKwon Date: Wed, 2 Aug 2023 14:38:57 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20prod=20=ED=99=98=EA=B2=BD=20CICD=20wor?= =?UTF-8?q?kflow=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/backend-prod-deploy.yml | 86 +++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 .github/workflows/backend-prod-deploy.yml diff --git a/.github/workflows/backend-prod-deploy.yml b/.github/workflows/backend-prod-deploy.yml new file mode 100644 index 000000000..dcc91d652 --- /dev/null +++ b/.github/workflows/backend-prod-deploy.yml @@ -0,0 +1,86 @@ +name: Kerdy Backend Prod Server CI/CD + +on: + workflow_dispatch: + push: + branches: [ Feature/#164-DEV_PROD_YML_분리_및_서브모듈_적용 ] + +jobs: + build: + runs-on: ubuntu-22.04 + defaults: + run: + working-directory: backend/emm-sale + services: + mysql: + image: mysql:8.0.28 + env: + MYSQL_USER: user + MYSQL_PASSWORD: password + MYSQL_ROOT_PASSWORD: 1234 + MYSQL_DATABASE: kerdy + ports: + - 3306:3306 + options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3 + + steps: + - name: workflow_dispatch에서 지정한 branch로 checkout + uses: actions/checkout@v3 + with: + token: ${{ secrets.SUBMODULE_TOKEN }} + submodules: true + + - name: firebase key 생성 + run: | + echo "${{ secrets.FIREBASE_KEY }}" > firebase-kerdy.json + - name: firebase key 이동 + run: | + cp firebase-kerdy.json src/main/resources + + - name: JDK 11로 설정 + uses: actions/setup-java@v3 + with: + java-version: 11 + distribution: 'corretto' + + - name: Gradle에 실행 권한 부여 + run: chmod +x gradlew + + - 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- + # RestDocs의 index.html 업데이트 반영을 위해 2번 build하도록 함 + - name: gradle 빌드 + run: ./gradlew build && ./gradlew build + + - name: 도커 빌더 생성 및 부팅 + uses: docker/setup-buildx-action@v2 + + - name: 도커 허브에 로그인 + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: 도커 이미지 빌드 및 푸시 + uses: docker/build-push-action@v4 + with: + context: backend/emm-sale + file: backend/emm-sale/Dockerfile-prod + platforms: linux/arm64/v8 + push: true + tags: ${{ secrets.DOCKERHUB_USERNAME }}/kerdy:latest + + deploy: + needs: build + name: 배포 + runs-on: [ self-hosted, label-prod ] + steps: + - name: 도커 실행 + 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