|
| 1 | +name: Deploy |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + workflow_dispatch: |
| 7 | + |
| 8 | +permissions: |
| 9 | + id-token: write |
| 10 | + contents: read |
| 11 | + |
| 12 | +env: |
| 13 | + AZURE_RG: rg-apm-demo-001 |
| 14 | + APP_NAME: apm-demo-app-001 |
| 15 | + LOCATION: canadacentral |
| 16 | + |
| 17 | +jobs: |
| 18 | + deploy: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + environment: prod |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + |
| 24 | + - name: Azure Login |
| 25 | + uses: azure/login@v2 |
| 26 | + with: |
| 27 | + client-id: ${{ secrets.AZURE_CLIENT_ID }} |
| 28 | + tenant-id: ${{ secrets.AZURE_TENANT_ID }} |
| 29 | + subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} |
| 30 | + |
| 31 | + - name: Create Resource Group |
| 32 | + run: az group create --name ${{ env.AZURE_RG }} --location ${{ env.LOCATION }} |
| 33 | + |
| 34 | + - name: Deploy Infrastructure |
| 35 | + id: infra |
| 36 | + run: | |
| 37 | + outputs=$(az deployment group create \ |
| 38 | + --resource-group ${{ env.AZURE_RG }} \ |
| 39 | + --template-file infra/main.bicep \ |
| 40 | + --parameters appName=${{ env.APP_NAME }} \ |
| 41 | + --query 'properties.outputs' -o json) |
| 42 | + echo "acrName=$(echo $outputs | jq -r '.acrName.value')" >> $GITHUB_OUTPUT |
| 43 | + echo "appServiceName=$(echo $outputs | jq -r '.appServiceName.value')" >> $GITHUB_OUTPUT |
| 44 | +
|
| 45 | + - name: Build and Push to ACR |
| 46 | + run: | |
| 47 | + az acr build \ |
| 48 | + --registry ${{ steps.infra.outputs.acrName }} \ |
| 49 | + --image ${{ env.APP_NAME }}:${{ github.sha }} \ |
| 50 | + --image ${{ env.APP_NAME }}:latest \ |
| 51 | + . |
| 52 | +
|
| 53 | + - name: Deploy to Web App for Containers |
| 54 | + uses: azure/webapps-deploy@v3 |
| 55 | + with: |
| 56 | + app-name: ${{ steps.infra.outputs.appServiceName }} |
| 57 | + images: ${{ steps.infra.outputs.acrName }}.azurecr.io/${{ env.APP_NAME }}:${{ github.sha }} |
| 58 | + |
| 59 | + - name: Health Check |
| 60 | + run: | |
| 61 | + APP_URL=$(az webapp show -g ${{ env.AZURE_RG }} -n ${{ steps.infra.outputs.appServiceName }} --query defaultHostName -o tsv) |
| 62 | + sleep 30 |
| 63 | + curl -sf --retry 5 --retry-delay 10 "https://$APP_URL" || exit 1 |
| 64 | +
|
| 65 | + - name: Summary |
| 66 | + run: | |
| 67 | + APP_URL=$(az webapp show -g ${{ env.AZURE_RG }} -n ${{ steps.infra.outputs.appServiceName }} --query defaultHostName -o tsv) |
| 68 | + echo "### ✅ ${{ env.APP_NAME }}" >> $GITHUB_STEP_SUMMARY |
| 69 | + echo "Deployed to: https://$APP_URL" >> $GITHUB_STEP_SUMMARY |
0 commit comments