Deploy Dev #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy Dev | |
| on: | |
| workflow_run: | |
| workflows: [ "CI" ] | |
| branches: [ dev ] | |
| types: [ completed ] | |
| permissions: | |
| contents: read | |
| env: | |
| IMAGE_REPOSITORY: ${{ secrets.DOCKERHUB_REPOSITORY }} | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| if: > | |
| github.event.workflow_run.conclusion == 'success' && | |
| github.event.workflow_run.event == 'push' && | |
| github.event.workflow_run.head_branch == 'dev' | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_sha }} | |
| - name: Set up JDK 21 | |
| uses: actions/setup-java@v5 | |
| with: | |
| distribution: temurin | |
| java-version: "21" | |
| cache: gradle | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x gradlew | |
| - name: Build JAR | |
| run: ./gradlew clean build -x test --no-daemon | |
| # ARM Docker Build 설정 | |
| - name: Set up QEMU | |
| uses: docker/setup-qemu-action@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push dev image | |
| uses: docker/build-push-action@v6 | |
| with: | |
| context: . | |
| file: ./Dockerfile | |
| platforms: linux/arm64 # t4g small 배포를 위한 arm platform 설정 | |
| push: true | |
| tags: | | |
| ${{ env.IMAGE_REPOSITORY }}:dev-latest | |
| ${{ env.IMAGE_REPOSITORY }}:dev-${{ github.event.workflow_run.head_sha }} | |
| deploy: | |
| needs: build | |
| runs-on: ubuntu-latest | |
| if: needs.build.result == 'success' | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v6 | |
| with: | |
| ref: ${{ github.event.workflow_run.head_sha }} | |
| # /infra/dev 하위 파일 EC2로 복사 | |
| - name: Upload deployment files to EC2 | |
| uses: appleboy/scp-action@v1 | |
| with: | |
| host: ${{ secrets.DEV_EC2_HOST }} | |
| username: ${{ secrets.DEV_EC2_USER }} | |
| key: ${{ secrets.DEV_EC2_SSH_KEY }} | |
| source: "infra/dev" | |
| target: "${{ secrets.DEV_DEPLOY_DIR }}" | |
| - name: Deploy to dev server | |
| uses: appleboy/ssh-action@v1.2.0 | |
| with: | |
| host: ${{ secrets.DEV_EC2_HOST }} | |
| username: ${{ secrets.DEV_EC2_USER }} | |
| key: ${{ secrets.DEV_EC2_SSH_KEY }} | |
| script: | | |
| set -euo pipefail | |
| DEPLOY_DIR="${{ secrets.DEV_DEPLOY_DIR }}/infra/dev" | |
| chmod +x "$DEPLOY_DIR/scripts/deploy.sh" | |
| APP_IMAGE="${{ env.IMAGE_REPOSITORY }}:dev-${{ github.event.workflow_run.head_sha }}" \ | |
| DOMAIN="${{ secrets.DEV_DOMAIN }}" \ | |
| DEPLOY_DIR="$DEPLOY_DIR" \ | |
| "$DEPLOY_DIR/scripts/deploy.sh" |