6. Automate with GitHub Actions
Build the image in ACR and roll out a new revision on every push to main, authenticating with OpenID Connect (no stored passwords).
1. Create a federated identity for GitHub
Create a Microsoft Entra app registration (or user-assigned managed identity) and add a federated credential for your repository and branch. Then grant it permissions:
az role assignment create --assignee APP_CLIENT_ID --role Contributor \
--scope /subscriptions/SUBSCRIPTION_ID/resourceGroups/$RG
Store these as GitHub repository secrets: AZURE_CLIENT_ID, AZURE_TENANT_ID, AZURE_SUBSCRIPTION_ID.
2. Add the workflow
Save as .github/workflows/deploy.yml:
name: build-and-deploy
on:
push:
branches: [ main ]
permissions:
id-token: write
contents: read
env:
RG: rg-containerdemo
ACR_NAME: acrcontainerdemo12345
IMAGE: azure-container-guide
CONTAINER_APP: ca-containerdemo
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Azure login (OIDC)
uses: azure/login@v2
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Build image in ACR
run: |
az acr build --registry $ACR_NAME --image $IMAGE:${{ github.sha }} ./AzureContainerGuide
- name: Deploy new revision
run: |
az containerapp update \
--name $CONTAINER_APP \
--resource-group $RG \
--image $ACR_NAME.azurecr.io/$IMAGE:${{ github.sha }}
Deploying to App Service instead?
Replace the last step with:
az webapp config container set \
--name APP_NAME \
--resource-group $RG \
--container-image-name $ACR_NAME.azurecr.io/$IMAGE:${{ github.sha }}
Tagging images with the commit SHA makes every deployment traceable and every rollback a one-line change.