2. Backend Deploy #122
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: Release Server CD | |
| on: | |
| push: | |
| branches: | |
| - "main" | |
| - "setting/#542-oracle_cloud" | |
| paths: | |
| - "backend/**" | |
| - ".github/workflows/**" | |
| workflow_dispatch: | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: "17" | |
| distribution: "temurin" | |
| cache: gradle # Gradle 캐싱 활성화 | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 # v4.0.0 | |
| - name: Cache Gradle dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.gradle/caches | |
| ~/.gradle/wrapper | |
| key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} | |
| restore-keys: | | |
| ${{ runner.os }}-gradle- | |
| - name: make application.properties | |
| run: | | |
| cd ./backend/src/main/resources | |
| echo "${{ secrets.APPLICATION_PROD_RELEASE }}" > ./application.properties | |
| - name: make firebase.json | |
| run: | | |
| cd ./backend/src/main/resources | |
| echo "${{ secrets.FIREBASE_PR_TEST }}" | base64 -d > ./firebase.json | |
| - name: Grant execute permission for gradlew | |
| run: chmod +x ./backend/gradlew | |
| - name: Build with Gradle | |
| run: | | |
| cd backend | |
| ./gradlew clean build -x test | |
| # Docker 인증 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.SERVER_DOCKER_USERNAME }} | |
| password: ${{ secrets.SERVER_DOCKER_PASSWORD }} | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v3 | |
| - name: Build and Push ARM64 Docker Image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: ./backend | |
| file: ./backend/Dockerfile | |
| platforms: linux/arm64,linux/amd64 | |
| push: true | |
| tags: | | |
| ${{ secrets.DOCKER_IMAGE_RELEASE }}:latest | |
| ${{ secrets.DOCKER_IMAGE_RELEASE }}:${{ github.sha }} | |
| deploy: | |
| name: Deploy | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: read | |
| packages: write | |
| needs: build | |
| steps: | |
| # oracle ssh 접속 후 배포 | |
| - name: Update Container on VM | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.ORACLE_INSTANCE_RELEASE_IP }} | |
| username: ${{ secrets.ORACLE_INSTANCE_USER }} | |
| key: ${{ secrets.ORACLE_INSTANCE_RELEASE_PRIVATE_KEY }} | |
| port: ${{ secrets.ORACLE_INSTANCE_RELEASE_PORT }} | |
| script: | | |
| docker pull ${{ secrets.DOCKER_IMAGE_RELEASE }}:latest | |
| export USERNAME=${{ secrets.ORACLE_INSTANCE_USER }} | |
| export DOCKER_APP_IMAGE=${{ secrets.DOCKER_IMAGE_RELEASE }}:latest | |
| sudo chmod +x /home/${{ secrets.ORACLE_INSTANCE_USER }}/deploy.sh | |
| sudo -E /home/${{ secrets.ORACLE_INSTANCE_USER }}/deploy.sh | |
| docker image prune -af |