๐ Azure Container Registry์ ์ด๋ฏธ์ง pushํ๋ GitHub Action ์ถ๊ฐ #5
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 ] # TODO(Godeok Kim): dev ๋ธ๋์น์ 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 }}/${{ secrets.ACR_REPOSITORY_NAME_TEST }} | |
| # ์์ ํ๊ทธ: 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..." | |
| az acr repository show-tags --name $(echo ${{ secrets.ACR_LOGIN_SERVER }} | cut -d'.' -f1) --repository ${{ secrets.ACR_REPOSITORY_NAME }} --output table |