11name : Deploy API Image to Azure App Service
22
33on :
4+ # Run automatically after the build workflow completes on main
45 workflow_run :
56 workflows : ["Build and Push Docker Images"]
6- types : [ completed ]
7- branches : [ main ]
7+ types : [completed]
8+ branches : [main]
9+ # Allow manual runs
810 workflow_dispatch :
911
1012env :
1113 AZURE_WEBAPP_NAME : tps-app-scripting-editor
1214 AZURE_RESOURCE_GROUP : tps-app-scripting-rg
1315 REGISTRY : tpsappscriptingacr.azurecr.io
1416 IMAGE_API : app-scripting-editor-api
15- # optional: use your Front Door host for health check; leave blank to use default *.azurewebsites.net
17+ # If you want the health check to go via Front Door, keep this.
18+ # Leave empty to use the default *.azurewebsites.net host instead.
1619 FRONTDOOR_HOST : app-scripting-editor.trackmangolfdev.com
1720
1821jobs :
@@ -26,43 +29,70 @@ jobs:
2629 - name : Checkout
2730 uses : actions/checkout@v4
2831
29- - name : Azure login (OIDC)
32+ # ==== Azure Auth (Service Principal JSON) ====
33+ # Create once via:
34+ # SUB_ID=$(az account show --query id -o tsv)
35+ # az ad sp create-for-rbac \
36+ # --name "gh-actions-tps-app-scripting" \
37+ # --role Contributor \
38+ # --scopes "/subscriptions/$SUB_ID/resourceGroups/tps-app-scripting-rg" \
39+ # --sdk-auth
40+ # Put the full JSON in a repo secret named AZURE_CREDENTIALS.
41+ - name : Azure login (SPN JSON)
3042 uses : azure/login@v2
3143 with :
32- client-id : ${{ secrets.AZURE_CLIENT_ID }}
33- tenant-id : ${{ secrets.AZURE_TENANT_ID }}
34- subscription-id : ${{ secrets.AZURE_SUBSCRIPTION_ID }}
44+ creds : ${{ secrets.AZURE_CREDENTIALS }}
3545
46+ # Point the Web App at the API image and ensure it can pull from ACR
3647 - name : Set API image on App Service
3748 run : |
38- 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 }}"
49+ az webapp config container set \
50+ --name "${{ env.AZURE_WEBAPP_NAME }}" \
51+ --resource-group "${{ env.AZURE_RESOURCE_GROUP }}" \
52+ --docker-custom-image-name "${{ env.REGISTRY }}/${{ env.IMAGE_API }}:latest" \
53+ --docker-registry-server-url "https://${{ env.REGISTRY }}" \
54+ --docker-registry-server-user "${{ secrets.ACR_USERNAME }}" \
55+ --docker-registry-server-password "${{ secrets.ACR_PASSWORD }}"
3956
40- - name : Ensure WEBSITES_PORT=4000 (Express listens here)
57+ # Make sure App Service routes to your Express port
58+ - name : Ensure WEBSITES_PORT=4000
4159 run : |
42- az webapp config appsettings set --name "${{ env.AZURE_WEBAPP_NAME }}" --resource-group "${{ env.AZURE_RESOURCE_GROUP }}" --settings WEBSITES_PORT=4000
60+ az webapp config appsettings set \
61+ --name "${{ env.AZURE_WEBAPP_NAME }}" \
62+ --resource-group "${{ env.AZURE_RESOURCE_GROUP }}" \
63+ --settings WEBSITES_PORT=4000
4364
4465 - name : Restart App
4566 run : |
46- az webapp restart --name "${{ env.AZURE_WEBAPP_NAME }}" --resource-group "${{ env.AZURE_RESOURCE_GROUP }}"
67+ az webapp restart \
68+ --name "${{ env.AZURE_WEBAPP_NAME }}" \
69+ --resource-group "${{ env.AZURE_RESOURCE_GROUP }}"
4770
71+ # Work out which host to health check (Front Door or default host)
4872 - name : Determine public host for health check
4973 id : host
74+ shell : bash
5075 run : |
5176 if [ -n "${{ env.FRONTDOOR_HOST }}" ]; then
5277 echo "host=${{ env.FRONTDOOR_HOST }}" >> "$GITHUB_OUTPUT"
5378 else
54- host=$(az webapp show --name "${{ env.AZURE_WEBAPP_NAME }}" --resource-group "${{ env.AZURE_RESOURCE_GROUP }}" --query defaultHostName -o tsv)
79+ host=$(az webapp show \
80+ --name "${{ env.AZURE_WEBAPP_NAME }}" \
81+ --resource-group "${{ env.AZURE_RESOURCE_GROUP }}" \
82+ --query defaultHostName -o tsv)
5583 echo "host=${host}" >> "$GITHUB_OUTPUT"
5684 fi
5785
86+ # Poll /api/health until it returns 200
5887 - name : Wait for /api/health = 200
88+ shell : bash
5989 run : |
6090 set -e
6191 url="https://${{ steps.host.outputs.host }}/api/health"
6292 echo "Checking $url ..."
6393 for i in {1..20}; do
6494 code=$(curl -s -o /dev/null -w "%{http_code}" "$url" || echo "000")
65- echo "Attempt $i -> $code"
95+ echo "Attempt $i -> HTTP $code"
6696 if [ "$code" = "200" ]; then
6797 echo "Healthy."
6898 exit 0
0 commit comments