๐ Main branch์์๋ ์ด๋ฏธ์ง push๊ฐ ๋๋ฏ๋ก ๊ด๋ จ ๋ด์ฉ ์ ๋ฐ์ดํธ #7
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: Build and Push Backend Image to ACR | |
| # ์ํฌํ๋ก์ฐ ํธ๋ฆฌ๊ฑฐ ์ค์ | |
| on: | |
| push: | |
| branches: [ dev-test, main ] # dev-test์ main ๋ธ๋์น์ push๋ ๋ ์คํ | |
| workflow_dispatch: {} # GitHub Actions ํญ์์ ์๋์ผ๋ก ์คํ ๊ฐ๋ฅ | |
| jobs: | |
| build-and-push: | |
| runs-on: ubuntu-latest # ์คํ ํ๊ฒฝ ์ง์ | |
| steps: | |
| # 1. ์์ค ์ฝ๋ ์ฒดํฌ์์ | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| # 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-test' && 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์์ ์์ฑ๋ ๋ผ๋ฒจ ์ฌ์ฉ | |
| # 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-test' && secrets.ACR_REPOSITORY_NAME_TEST || secrets.ACR_REPOSITORY_NAME }} --output table |