Build and Push Image to ACR #21
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 Image to ACR | |
| on: | |
| push: | |
| branches: | |
| - main | |
| workflow_run: | |
| workflows: ["Terraform infrastructure provision"] | |
| types: | |
| - completed | |
| permissions: | |
| id-token: write | |
| contents: read | |
| jobs: | |
| build-and-push: | |
| if: ${{ github.event_name != 'workflow_run' || github.event.workflow_run.conclusion == 'success' }} | |
| runs-on: ubuntu-latest | |
| env: | |
| ACR_NAME: uksouthacrprod001 | |
| IMAGE_NAME: nodejs-app | |
| IMAGE_TAG: ${{ github.sha }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Log in to Azure | |
| uses: azure/login@v2 | |
| with: | |
| client-id: ${{ secrets.AZURE_CLIENT_ID }} | |
| tenant-id: ${{ secrets.AZURE_TENANT_ID }} | |
| subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} | |
| - name: Log in to ACR | |
| run: | | |
| az acr login --name ${ACR_NAME} | |
| - name: Docker build and push Docker image to ACR | |
| run: | | |
| docker build -t ${ACR_NAME}.azurecr.io/${IMAGE_NAME}:${IMAGE_TAG} ./nodejs-demoapp | |
| docker push ${ACR_NAME}.azurecr.io/${IMAGE_NAME}:${IMAGE_TAG} |