๐๏ธ ์ต์ ์ฝ๋ ๋ฐ์ ์๋๋ ๋ฌธ์ ํด๊ฒฐ #32
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: Build, Push Backend Image to ACR and Trigger Deployment | |
| # ์ํฌํ๋ก์ฐ ํธ๋ฆฌ๊ฑฐ ์ค์ | |
| on: | |
| push: | |
| branches: [ dev, main ] # dev์ main ๋ธ๋์น์ push๋ ๋ ์คํ | |
| workflow_dispatch: {} # GitHub Actions ํญ์์ ์๋์ผ๋ก ์คํ ๊ฐ๋ฅ | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest # ์คํ ํ๊ฒฝ ์ง์ | |
| outputs: | |
| commit_sha: ${{ github.sha }} | |
| steps: | |
| # 1. ์์ค ์ฝ๋ ์ฒดํฌ์์ | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 # ๋ชจ๋ ํ์คํ ๋ฆฌ ๊ฐ์ ธ์ค๊ธฐ | |
| ref: ${{ github.ref }} # ํ์ฌ ๋ธ๋์น์ ์ต์ ์ปค๋ฐ ์ฌ์ฉ | |
| clean: true # ์์ ๋๋ ํ ๋ฆฌ ์ ๋ฆฌ | |
| # 2. Azure ๋ก๊ทธ์ธ (Service Principal ์ฌ์ฉ) | |
| - name: Log in to Azure | |
| uses: azure/login@v1 | |
| with: | |
| creds: ${{ secrets.AZURE_CREDENTIALS }} | |
| # 3. ACR ๋ก๊ทธ์ธ (Azure ์๊ฒฉ ์ฆ๋ช ์ฌ์ฉ) | |
| - name: Log in to ACR | |
| uses: azure/docker-login@v1 | |
| with: | |
| login-server: ${{ secrets.ACR_LOGIN_SERVER }} | |
| username: ${{ secrets.ACR_USERNAME }} | |
| password: ${{ secrets.ACR_PASSWORD }} | |
| # 4. Docker ์ด๋ฏธ์ง ๋ฉํ๋ฐ์ดํฐ ์ถ์ถ (ํ๊ทธ ์์ฑ ๋ฑ) | |
| - name: Extract metadata (tags, labels) for Docker | |
| id: meta # ์ด step์ ์ถ๋ ฅ์ ์ฐธ์กฐํ๊ธฐ ์ํ ID | |
| uses: docker/metadata-action@v5 | |
| with: | |
| images: ${{ secrets.ACR_LOGIN_SERVER }}/${{ github.ref == 'refs/heads/dev' && secrets.ACR_REPOSITORY_NAME_TEST || secrets.ACR_REPOSITORY_NAME }} | |
| # ์์ ํ๊ทธ: main ๋ธ๋์น๋ฉด latest, ๊ทธ ์ธ์๋ ๋ธ๋์น๋ช , ๊ทธ๋ฆฌ๊ณ ํญ์ Git SHA ํ๊ทธ ์ถ๊ฐ | |
| tags: | | |
| type=ref,event=branch | |
| type=ref,event=pr | |
| type=sha | |
| type=raw,value=latest,enable={{is_default_branch}} | |
| # 5. Docker ์ด๋ฏธ์ง ๋น๋ ๋ฐ ACR์ ํธ์ | |
| - name: Build and push Docker image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . # Dockerfile์ด ์๋ ๊ฒฝ๋ก | |
| file: ./Dockerfile # Dockerfile ๊ฒฝ๋ก ๋ช ์ (๊ธฐ๋ณธ๊ฐ) | |
| push: true # ๋น๋ ํ ํธ์ ์คํ | |
| tags: ${{ steps.meta.outputs.tags }} # ์ metadata step์์ ์์ฑ๋ ํ๊ทธ ์ฌ์ฉ | |
| labels: ${{ steps.meta.outputs.labels }} # ์ metadata step์์ ์์ฑ๋ ๋ผ๋ฒจ ์ฌ์ฉ | |
| no-cache: true # ์บ์ ๋นํ์ฑํ | |
| build-args: | | |
| BUILD_DATE=$(date +%Y%m%d%H%M%S) # ๋น๋ ์๊ฐ์ ์ธ์๋ก ์ ๋ฌ | |
| # 6. ACR์ ํธ์๋ ์ด๋ฏธ์ง ํ์ธ | |
| - name: Verify pushed image | |
| run: | | |
| echo "Pushed image tags:" | |
| echo "${{ steps.meta.outputs.tags }}" | |
| echo "Checking image in ACR..." | |
| echo "Basic tag information:" | |
| az acr repository show-tags --name ${{ secrets.ACR_LOGIN_SERVER }} --repository ${{ github.ref == 'refs/heads/dev' && secrets.ACR_REPOSITORY_NAME_TEST || secrets.ACR_REPOSITORY_NAME }} --output table | |
| call-deploy-workflow: | |
| name: Trigger ACA Deployment | |
| needs: build-and-push | |
| uses: 9git9git/9git-devops/.github/workflows/deploy_to_aca.yml@main | |
| with: | |
| commit_sha: ${{ needs.build-and-push.outputs.commit_sha }} | |
| target_environment: ${{ (github.ref_name == 'main' && 'production') || 'test' }} | |
| app_type: 'backend' | |
| secrets: inherit | |
| # main ๋๋ dev ๋ธ๋์น์ push๋ ๋๋ง ๋ฐฐํฌ ์คํ | |
| if: github.event_name == 'push' && (github.ref_name == 'main' || github.ref_name == 'dev') |