From 5e760a54cd6023ccfc5b3ed91de253294b28331a Mon Sep 17 00:00:00 2001 From: Wonchae Yang <79977182+ywonchae1@users.noreply.github.com> Date: Wed, 6 Nov 2024 14:53:24 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=84=9C=EB=B2=84=20=EB=B0=B0=ED=8F=AC?= =?UTF-8?q?=20(#90)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: CICD 파이프라인 구축 (#86) (KAN-150) * feat: CICD 파이프라인 구축 (#86) (KAN-150) --- .github/workflows/deploy.yml | 167 ++++++++++++++++++----------------- 1 file changed, 88 insertions(+), 79 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 9117286e..b3232010 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,91 +1,100 @@ - name: Production 배포 -runs-on: ubuntu-latest +on: + push: + branches: + - main +env: + DOCKERHUB_USERNAME: meonghanyang + DOCKERHUB_IMAGE_NAME: server + +jobs: + build-deploy: + name: Production 배포 + runs-on: ubuntu-latest -steps: - - name: 기본 체크아웃 - uses: actions/checkout@v3 + steps: + - name: 기본 체크아웃 + uses: actions/checkout@v3 - - name: JDK 21 버전 설정 - uses: actions/setup-java@v3 - with: - distribution: 'corretto' - java-version: '21' + - name: JDK 21 버전 설정 + uses: actions/setup-java@v3 + with: + distribution: 'corretto' + java-version: '21' - - name: Gradlew 실행 권한 설정 - run: chmod +x ./gradlew + - name: Gradlew 실행 권한 설정 + run: chmod +x ./gradlew - - name: Gradle 빌드 - id: gradle - uses: gradle/gradle-build-action@v2 - with: - arguments: | - build - --scan - -x test - cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }} + - name: Gradle 빌드 + id: gradle + uses: gradle/gradle-build-action@v2 + with: + arguments: | + build + --scan + -x test + cache-read-only: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/develop' }} - - name: Dockerhub 로그인 - uses: docker/login-action@v3 - with: - username: ${{ env.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }} + - name: Dockerhub 로그인 + uses: docker/login-action@v3 + with: + username: ${{ env.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }} - - name: Docker 메타데이터 추출 - id: metadata - uses: docker/metadata-action@v5.5.0 - env: - DOCKERHUB_IMAGE_FULL_NAME: ${{ env.DOCKERHUB_USERNAME }}/${{ env.DOCKERHUB_IMAGE_NAME }} - with: - images: ${{ env.DOCKERHUB_IMAGE_FULL_NAME }} - tags: - ${{ github.run_number }} - flavor: | - latest=false + - name: Docker 메타데이터 추출 + id: metadata + uses: docker/metadata-action@v5.5.0 + env: + DOCKERHUB_IMAGE_FULL_NAME: ${{ env.DOCKERHUB_USERNAME }}/${{ env.DOCKERHUB_IMAGE_NAME }} + with: + images: ${{ env.DOCKERHUB_IMAGE_FULL_NAME }} + tags: + ${{ github.run_number }} + flavor: | + latest=false - - name: Docker 이미지 빌드 및 도커허브로 푸시 - uses: docker/build-push-action@v6.0.1 - with: - file: scripts/Dockerfile - context: . - push: true - tags: ${{ steps.metadata.outputs.tags }} + - name: Docker 이미지 빌드 및 도커허브로 푸시 + uses: docker/build-push-action@v6.0.1 + with: + file: scripts/Dockerfile + context: . + push: true + tags: ${{ steps.metadata.outputs.tags }} - - name: 환경변수 주입 - run: | - echo "${{ secrets.APPLICATION_SECRETS }}" > .env + - name: 환경변수 주입 + run: | + echo "${{ secrets.APPLICATION_SECRETS }}" > .env - - name: 서버로 .env 파일 전송 - uses: burnett01/rsync-deployments@7.0.1 - with: - switches: -avzr --delete - remote_host: ${{ secrets.EC2_HOST }} - remote_user: ${{ secrets.EC2_USERNAME }} - remote_key: ${{ secrets.EC2_PRIVATE_KEY }} - path: .env - remote_path: /home/${{ secrets.EC2_USERNAME }}/ + - name: 서버로 .env 파일 전송 + uses: burnett01/rsync-deployments@7.0.1 + with: + switches: -avzr --delete + remote_host: ${{ secrets.EC2_HOST }} + remote_user: ${{ secrets.EC2_USERNAME }} + remote_key: ${{ secrets.EC2_PRIVATE_KEY }} + path: .env + remote_path: /home/${{ secrets.EC2_USERNAME }}/ - - name: 서버로 docker compose 파일 전송 - uses: burnett01/rsync-deployments@7.0.1 - with: - switches: -avzr --delete - remote_host: ${{ secrets.EC2_HOST }} - remote_user: ${{ secrets.EC2_USERNAME }} - remote_key: ${{ secrets.EC2_PRIVATE_KEY }} - path: scripts/docker-compose.yml - remote_path: /home/${{ secrets.EC2_USERNAME }}/ + - name: 서버로 docker compose 파일 전송 + uses: burnett01/rsync-deployments@7.0.1 + with: + switches: -avzr --delete + remote_host: ${{ secrets.EC2_HOST }} + remote_user: ${{ secrets.EC2_USERNAME }} + remote_key: ${{ secrets.EC2_PRIVATE_KEY }} + path: scripts/docker-compose.yml + remote_path: /home/${{ secrets.EC2_USERNAME }}/ - - name: EC2로 배포 - uses: appleboy/ssh-action@master - env: - IMAGE_FULL_URL: ${{ steps.metadata.outputs.tags }} - with: - host: ${{ secrets.EC2_HOST }} - username: ${{ secrets.EC2_USERNAME }} - key: ${{ secrets.EC2_PRIVATE_KEY }} - envs: IMAGE_FULL_URL, DOCKERHUB_IMAGE_NAME - script: | - echo "${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" | docker login -u "${{ env.DOCKERHUB_USERNAME }}" --password-stdin - docker compose down --remove-orphans - docker system prune -f - docker compose up --build -d \ No newline at end of file + - name: EC2로 배포 + uses: appleboy/ssh-action@master + env: + IMAGE_FULL_URL: ${{ steps.metadata.outputs.tags }} + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USERNAME }} + key: ${{ secrets.EC2_PRIVATE_KEY }} + envs: IMAGE_FULL_URL, DOCKERHUB_IMAGE_NAME + script: | + echo "${{ secrets.DOCKERHUB_ACCESS_TOKEN }}" | docker login -u "${{ env.DOCKERHUB_USERNAME }}" --password-stdin + docker compose down --remove-orphans + docker compose up --build -d \ No newline at end of file