Merge pull request #1318 from Moadong/hotfix/app-init-fail #131
Workflow file for this run
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: "2. Backend Deploy" | |
| on: | |
| push: | |
| tags: | |
| - "backend/v*" | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: "배포할 버전 (예: 1.2.3)" | |
| required: true | |
| permissions: | |
| contents: read | |
| packages: write | |
| concurrency: | |
| group: backend-deploy | |
| cancel-in-progress: false | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| image_tag: v${{ steps.version.outputs.version }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Extract version from tag | |
| id: version | |
| run: | | |
| # backend/v1.2.3 → 1.2.3 | |
| if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then | |
| version="${{ github.event.inputs.version }}" | |
| else | |
| version="${GITHUB_REF_NAME#backend/v}" | |
| fi | |
| echo "version=$version" >> $GITHUB_OUTPUT | |
| echo "Building version: $version" | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v4 | |
| with: | |
| java-version: "17" | |
| distribution: "temurin" | |
| cache: gradle | |
| - name: Setup Gradle | |
| uses: gradle/actions/setup-gradle@af1da67850ed9a4cedd57bfd976089dd991e2582 | |
| - 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: Create application.properties | |
| run: | | |
| cd ./backend/src/main/resources | |
| echo "${{ secrets.APPLICATION_PROD_RELEASE }}" > ./application.properties | |
| - name: Create 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 | |
| - 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 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 }}:v${{ steps.version.outputs.version }} | |
| update-deployment-file: | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: Checkout deploy-manifests repository | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: Moadong/gitops-moadong | |
| token: ${{ secrets.PAT }} | |
| ref: main | |
| path: gitops-moadong | |
| - name: Update image tag in kustomize | |
| run: | | |
| cd gitops-moadong/backend/prod | |
| kustomize edit set image ${{ secrets.DOCKER_IMAGE_RELEASE }}=${{ secrets.DOCKER_IMAGE_RELEASE }}:${{ needs.build.outputs.image_tag }} | |
| - name: Commit and Push changes | |
| run: | | |
| cd gitops-moadong | |
| git config --global user.email "${{ secrets.EMAIL }}" | |
| git config --global user.name "${{ secrets.USERNAME }}" | |
| git add . | |
| git diff --cached --quiet && echo "No changes" && exit 0 | |
| git commit -m "chore(prod): backend image tag update ${{ needs.build.outputs.image_tag }}" | |
| git push |