Skip to content

Commit db13a89

Browse files
authored
feat: Container app revision verification on deploy (#392)
1 parent 651db2c commit db13a89

File tree

4 files changed

+67
-2
lines changed

4 files changed

+67
-2
lines changed

.azure/containerApp/createExternal.bicep

+1
Original file line numberDiff line numberDiff line change
@@ -210,5 +210,6 @@ output identityPrincipalIds array = [
210210

211211
output containerAppEnvName string = containerAppEnv.name
212212
output webApiSoName string = webapiSo.name
213+
output webApiSoRevisionName string = webapiSo.properties.latestRevisionName
213214
output webApiEuName string = webapiEu.name
214215
output migrationJobName string = migrationJob.name

.azure/main.bicep

+1
Original file line numberDiff line numberDiff line change
@@ -333,3 +333,4 @@ module keyVaultReaderAccessPolicy 'keyvault/addReaderRoles.bicep' = {
333333

334334
output migrationJobName string = containerAppsExternal.outputs.migrationJobName
335335
output resourceGroupName string = resourceGroup.name
336+
output webapiSoRevisionName string = containerAppsExternal.outputs.webApiSoRevisionName

.github/tools/revisionVerifier.sh

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
if [ -z "$1" ]; then
2+
echo "Usage: $0 <revision-name>"
3+
exit 1
4+
fi
5+
6+
if [ -z "$2" ]; then
7+
echo "Usage: $0 <resource-group-name>"
8+
exit 1
9+
fi
10+
11+
revision_name="$1"
12+
resource_group="$2"
13+
query_filter="{name:name, runningState:properties.runningState, healthState:properties.healthState}"
14+
15+
verify_revision() {
16+
local json_output
17+
18+
# Fetch app revision
19+
json_output=$(az containerapp revision show -g "$resource_group" --revision "$revision_name" --query "$query_filter" 2>/dev/null)
20+
21+
health_state=$(echo $json_output | jq -r '.healthState')
22+
running_state=$(echo $json_output | jq -r '.runningState')
23+
24+
echo "Revision $revision_name status:"
25+
echo "-----------------------------"
26+
echo "Health state: $health_state"
27+
echo "Running state: $running_state"
28+
echo " "
29+
30+
# Check health and running status
31+
if [[ $health_state == "Healthy" && ($running_state == "Running" || $running_state == "RunningAtMaxScale") ]]; then
32+
return 0 # OK!
33+
else
34+
return 1 # Not OK!
35+
fi
36+
}
37+
38+
attempt=1
39+
40+
# Loop until verified (GitHub action will do a timeout)
41+
while true; do
42+
if verify_revision; then
43+
echo "Revision $revision_name is healthy and running"
44+
break
45+
else
46+
echo "Attempt $attempt: Waiting for revision $revision_name ..."
47+
sleep 10 # Sleep for 10 seconds
48+
attempt=$((attempt+1))
49+
fi
50+
done

.github/workflows/action-deploy.yml

+15-2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
on:
44
workflow_call:
5+
env:
6+
AZ_CLI_VERSION: 2.56.0
7+
58
secrets:
69
AZURE_CLIENT_ID:
710
required: true
@@ -56,7 +59,7 @@ jobs:
5659
uses: azure/CLI@v1
5760
id: keyvault-keys
5861
with:
59-
azcliversion: 2.56.0
62+
azcliversion: ${{ env.AZ_CLI_VERSION }}
6063
inlineScript: |
6164
KEY_VAULT_KEYS=$(az keyvault secret list --vault-name ${{ secrets.AZURE_SOURCE_KEY_VAULT_NAME }} --subscription ${{ secrets.AZURE_SOURCE_KEY_VAULT_SUBSCRIPTION_ID }} --query "[].name" -o json | tr -d '\n')
6265
echo "::set-output name=key-vault-keys::$KEY_VAULT_KEYS"
@@ -98,10 +101,20 @@ jobs:
98101
uses: azure/CLI@v1
99102
if: ${{!inputs.dryRun}}
100103
with:
101-
azcliversion: 2.56.0
104+
azcliversion: ${{ env.AZ_CLI_VERSION }}
102105
inlineScript: |
103106
az containerapp job start -n ${{ steps.deploy.outputs.migrationJobName }} -g ${{ steps.deploy.outputs.resourceGroupName }}
104107
108+
- name: Verify deployment running
109+
timeout-minutes: 3
110+
uses: azure/CLI@v1
111+
id: verify-deployment
112+
with:
113+
azcliversion: ${{ env.AZ_CLI_VERSION }}
114+
inlineScript: |
115+
./.github/tools/revisionVerifier.sh "${{ steps.deploy.outputs.webApiSoRevisionName }} ${{ steps.deploy.outputs.resourceGroupName }}"
116+
117+
105118
- name: Logout from azure
106119
if: ${{failure() || success()}}
107120
continue-on-error: true

0 commit comments

Comments
 (0)