Deploy API Image to Azure App Service #52
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: Deploy API Image to Azure App Service | |
| on: | |
| workflow_run: | |
| workflows: ["Build and Push Docker Images"] | |
| types: [ completed ] | |
| branches: [ main ] | |
| workflow_dispatch: | |
| env: | |
| AZURE_WEBAPP_NAME: tps-app-scripting-editor | |
| AZURE_RESOURCE_GROUP: tps-app-scripting-rg | |
| REGISTRY: tpsappscriptingacr.azurecr.io | |
| IMAGE_API: app-scripting-editor-api | |
| # optional: use your Front Door host for health check; leave blank to use default *.azurewebsites.net | |
| FRONTDOOR_HOST: app-scripting-editor.trackmangolfdev.com | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| id-token: write | |
| contents: read | |
| steps: | |
| - name: Checkout | |
| 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: Set API image on App Service | |
| run: | | |
| az webapp config container set --name "${{ env.AZURE_WEBAPP_NAME }}" --resource-group "${{ env.AZURE_RESOURCE_GROUP }}" --docker-custom-image-name "${{ env.REGISTRY }}/${{ env.IMAGE_API }}:latest" --docker-registry-server-url "https://${{ env.REGISTRY }}" --docker-registry-server-user "${{ secrets.ACR_USERNAME }}" --docker-registry-server-password "${{ secrets.ACR_PASSWORD }}" | |
| - name: Ensure WEBSITES_PORT=4000 (Express listens here) | |
| run: | | |
| az webapp config appsettings set --name "${{ env.AZURE_WEBAPP_NAME }}" --resource-group "${{ env.AZURE_RESOURCE_GROUP }}" --settings WEBSITES_PORT=4000 | |
| - name: Restart App | |
| run: | | |
| az webapp restart --name "${{ env.AZURE_WEBAPP_NAME }}" --resource-group "${{ env.AZURE_RESOURCE_GROUP }}" | |
| - name: Determine public host for health check | |
| id: host | |
| run: | | |
| if [ -n "${{ env.FRONTDOOR_HOST }}" ]; then | |
| echo "host=${{ env.FRONTDOOR_HOST }}" >> "$GITHUB_OUTPUT" | |
| else | |
| host=$(az webapp show --name "${{ env.AZURE_WEBAPP_NAME }}" --resource-group "${{ env.AZURE_RESOURCE_GROUP }}" --query defaultHostName -o tsv) | |
| echo "host=${host}" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Wait for /api/health = 200 | |
| run: | | |
| set -e | |
| url="https://${{ steps.host.outputs.host }}/api/health" | |
| echo "Checking $url ..." | |
| for i in {1..20}; do | |
| code=$(curl -s -o /dev/null -w "%{http_code}" "$url" || echo "000") | |
| echo "Attempt $i -> $code" | |
| if [ "$code" = "200" ]; then | |
| echo "Healthy." | |
| exit 0 | |
| fi | |
| sleep 5 | |
| done | |
| echo "ERROR: health never reached 200" | |
| exit 1 |