-
Notifications
You must be signed in to change notification settings - Fork 1
1533 lines (1320 loc) · 62.9 KB
/
deploy-azd.yml
File metadata and controls
1533 lines (1320 loc) · 62.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
name: deploy-azd
on:
workflow_dispatch:
inputs:
environment:
description: Deployment environment name (for azd -e)
required: true
default: dev
location:
description: Azure location
required: true
default: centralus
projectName:
description: Project prefix used by naming convention
required: true
default: holidaypeakhub
imageTag:
description: Image tag to deploy
required: true
default: latest
deployStatic:
description: Provision static web app resources
required: true
type: boolean
default: true
uiOnly:
description: Deploy only the UI using SWA token (skips provision and Azure login jobs)
required: true
type: boolean
default: false
apiBaseUrl:
description: Optional API base URL for UI build override
required: false
default: ''
seedDemoData:
description: Run demo faker seed job after deployment (non-prod only)
required: true
type: boolean
default: true
deployChangedOnly:
description: Legacy flag (changed-app-only deployment is always enforced)
required: true
type: boolean
default: true
forceApimSync:
description: Force APIM sync and smoke checks even when no changed services are detected
required: true
type: boolean
default: false
permissions:
id-token: write
contents: read
concurrency:
group: deploy-azd-${{ inputs.environment }}
cancel-in-progress: false
jobs:
detect-changes:
if: ${{ !inputs.uiOnly }}
runs-on: ubuntu-latest
outputs:
crud_changed: ${{ steps.detect.outputs.crud_changed }}
ui_changed: ${{ steps.detect.outputs.ui_changed }}
agents_changed: ${{ steps.detect.outputs.agents_changed }}
changed_agents_matrix: ${{ steps.detect.outputs.changed_agents_matrix }}
changed_agent_services_csv: ${{ steps.detect.outputs.changed_agent_services_csv }}
changed_aks_services_csv: ${{ steps.detect.outputs.changed_aks_services_csv }}
lib_changed: ${{ steps.detect.outputs.lib_changed }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Detect changed services
id: detect
shell: bash
run: |
set -euo pipefail
DEFAULT_BRANCH="${{ github.event.repository.default_branch }}"
git fetch origin "$DEFAULT_BRANCH" --depth=1
CHANGED_FILES=$(git diff --name-only "origin/$DEFAULT_BRANCH...HEAD")
mapfile -t AGENT_SERVICES < <(python3 - <<'PY'
import re
with open('azure.yaml', encoding='utf-8') as f:
lines = f.readlines()
in_services = False
current_service = None
current_host = None
services = []
for raw in lines:
line = raw.rstrip('\n')
if not in_services:
if re.match(r'^services:\s*$', line):
in_services = True
continue
if re.match(r'^[^\s]', line):
break
service_match = re.match(r'^ ([a-z0-9\-]+):\s*$', line)
if service_match:
if current_service and current_host == 'aks' and current_service != 'crud-service':
services.append(current_service)
current_service = service_match.group(1)
current_host = None
continue
host_match = re.match(r'^ host:\s*(\S+)\s*$', line)
if host_match:
current_host = host_match.group(1)
if current_service and current_host == 'aks' and current_service != 'crud-service':
services.append(current_service)
for service in services:
print(service)
PY
)
CRUD_CHANGED=false
if echo "$CHANGED_FILES" | grep -Eq '^apps/crud-service/'; then
CRUD_CHANGED=true
fi
UI_CHANGED=false
if echo "$CHANGED_FILES" | grep -Eq '^apps/ui/'; then
UI_CHANGED=true
fi
LIB_CHANGED=false
if echo "$CHANGED_FILES" | grep -Eq '^lib/'; then
LIB_CHANGED=true
fi
AGENTS_CHANGED=false
MATRIX='[]'
CHANGED_AGENTS=()
for service in "${AGENT_SERVICES[@]}"; do
if echo "$CHANGED_FILES" | grep -Eq "^apps/$service/"; then
CHANGED_AGENTS+=("$service")
fi
done
# If lib/ changed, all agent services need rebuild
if [ "$LIB_CHANGED" = true ]; then
CHANGED_AGENTS=("${AGENT_SERVICES[@]}")
CRUD_CHANGED=true
fi
if [ ${#CHANGED_AGENTS[@]} -gt 0 ]; then
AGENTS_CHANGED=true
MATRIX=$(printf '%s\n' "${CHANGED_AGENTS[@]}" | jq -R . | jq -s 'map({service: .})')
fi
CHANGED_AGENT_SERVICES_CSV=""
if [ ${#CHANGED_AGENTS[@]} -gt 0 ]; then
CHANGED_AGENT_SERVICES_CSV=$(IFS=,; echo "${CHANGED_AGENTS[*]}")
fi
CHANGED_AKS_SERVICES_CSV="$CHANGED_AGENT_SERVICES_CSV"
if [ "$CRUD_CHANGED" = true ]; then
if [ -n "$CHANGED_AKS_SERVICES_CSV" ]; then
CHANGED_AKS_SERVICES_CSV="crud-service,$CHANGED_AKS_SERVICES_CSV"
else
CHANGED_AKS_SERVICES_CSV="crud-service"
fi
fi
echo "crud_changed=$CRUD_CHANGED" >> "$GITHUB_OUTPUT"
echo "ui_changed=$UI_CHANGED" >> "$GITHUB_OUTPUT"
echo "agents_changed=$AGENTS_CHANGED" >> "$GITHUB_OUTPUT"
echo "changed_agents_matrix=$MATRIX" >> "$GITHUB_OUTPUT"
echo "changed_agent_services_csv=$CHANGED_AGENT_SERVICES_CSV" >> "$GITHUB_OUTPUT"
echo "changed_aks_services_csv=$CHANGED_AKS_SERVICES_CSV" >> "$GITHUB_OUTPUT"
echo "lib_changed=$LIB_CHANGED" >> "$GITHUB_OUTPUT"
provision:
if: ${{ !inputs.uiOnly }}
needs: detect-changes
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
outputs:
AI_SERVICES_NAME: ${{ steps.outputs.outputs.AI_SERVICES_NAME }}
PROJECT_ENDPOINT: ${{ steps.outputs.outputs.PROJECT_ENDPOINT }}
PROJECT_NAME: ${{ steps.outputs.outputs.PROJECT_NAME }}
APIM_GATEWAY_URL: ${{ steps.outputs.outputs.APIM_GATEWAY_URL }}
COSMOS_ACCOUNT_URI: ${{ steps.outputs.outputs.COSMOS_ACCOUNT_URI }}
COSMOS_DATABASE: ${{ steps.outputs.outputs.COSMOS_DATABASE }}
KEY_VAULT_URI: ${{ steps.outputs.outputs.KEY_VAULT_URI }}
REDIS_HOST: ${{ steps.outputs.outputs.REDIS_HOST }}
EVENT_HUB_NAMESPACE: ${{ steps.outputs.outputs.EVENT_HUB_NAMESPACE }}
APPLICATIONINSIGHTS_CONNECTION_STRING: ${{ steps.outputs.outputs.APPLICATIONINSIGHTS_CONNECTION_STRING }}
POSTGRES_HOST: ${{ steps.outputs.outputs.POSTGRES_HOST }}
POSTGRES_USER: ${{ steps.outputs.outputs.POSTGRES_USER }}
POSTGRES_ADMIN_USER: ${{ steps.outputs.outputs.POSTGRES_ADMIN_USER }}
POSTGRES_AUTH_MODE: ${{ steps.outputs.outputs.POSTGRES_AUTH_MODE }}
POSTGRES_DATABASE: ${{ steps.outputs.outputs.POSTGRES_DATABASE }}
env:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
steps:
- uses: actions/checkout@v4
- name: Azure login (OIDC)
uses: azure/login@v2
with:
client-id: ${{ env.AZURE_CLIENT_ID }}
tenant-id: ${{ env.AZURE_TENANT_ID }}
subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }}
- name: Setup azd
uses: Azure/setup-azd@v2
- name: Authenticate azd (OIDC)
run: |
azd auth login \
--client-id "${AZURE_CLIENT_ID}" \
--tenant-id "${AZURE_TENANT_ID}" \
--federated-credential-provider github \
--no-prompt
- name: Configure azd environment context
run: |
azd env set AZURE_SUBSCRIPTION_ID "${AZURE_SUBSCRIPTION_ID}" -e "${{ inputs.environment }}"
azd env set AZURE_LOCATION "${{ inputs.location }}" -e "${{ inputs.environment }}"
azd env set AZURE_ENV_NAME "${{ inputs.environment }}" -e "${{ inputs.environment }}"
azd env set AZURE_RESOURCE_GROUP "${{ inputs.projectName }}-${{ inputs.environment }}-rg" -e "${{ inputs.environment }}"
azd env set resourceGroupName "${{ inputs.projectName }}-${{ inputs.environment }}-rg" -e "${{ inputs.environment }}"
azd env set AZURE_AKS_CLUSTER_NAME "${{ inputs.projectName }}-${{ inputs.environment }}-aks" -e "${{ inputs.environment }}"
azd env set AKS_CLUSTER_NAME "${{ inputs.projectName }}-${{ inputs.environment }}-aks" -e "${{ inputs.environment }}"
azd env set AZURE_CONTAINER_REGISTRY_ENDPOINT "${{ inputs.projectName }}${{ inputs.environment }}acr.azurecr.io" -e "${{ inputs.environment }}"
- name: Install kubelogin
run: |
for attempt in 1 2 3 4 5; do
if az aks install-cli --kubelogin-version latest; then
exit 0
fi
echo "kubelogin install failed on attempt ${attempt}; retrying..."
sleep 15
done
echo "kubelogin install failed after retries"
exit 1
- name: Ensure hook scripts executable
run: chmod +x ./.infra/azd/hooks/*.sh
- name: Ensure AKS cluster is running
run: |
AKS_RG="${{ inputs.projectName }}-${{ inputs.environment }}-rg"
AKS_NAME="${{ inputs.projectName }}-${{ inputs.environment }}-aks"
if az aks show --resource-group "$AKS_RG" --name "$AKS_NAME" >/dev/null 2>&1; then
POWER_STATE=$(az aks show --resource-group "$AKS_RG" --name "$AKS_NAME" --query "powerState.code" -o tsv 2>/dev/null || true)
if [ "$POWER_STATE" = "Stopped" ]; then
echo "AKS cluster is stopped. Starting $AKS_NAME..."
az aks start --resource-group "$AKS_RG" --name "$AKS_NAME"
for _ in $(seq 1 40); do
CURRENT_STATE=$(az aks show --resource-group "$AKS_RG" --name "$AKS_NAME" --query "powerState.code" -o tsv 2>/dev/null || true)
if [ "$CURRENT_STATE" = "Running" ]; then
echo "AKS cluster is running."
break
fi
sleep 30
done
fi
else
echo "AKS cluster does not exist yet. Continuing."
fi
- name: Install kubelogin
run: |
for attempt in 1 2 3 4 5; do
if az aks install-cli --kubelogin-version latest; then
exit 0
fi
echo "kubelogin install failed on attempt ${attempt}; retrying..."
sleep 15
done
echo "kubelogin install failed after retries"
exit 1
- name: Ensure hook scripts executable
run: chmod +x ./.infra/azd/hooks/*.sh
- name: Configure azd environment
run: |
azd env set AZURE_SUBSCRIPTION_ID "${AZURE_SUBSCRIPTION_ID}" -e "${{ inputs.environment }}"
azd env set AZURE_LOCATION "${{ inputs.location }}" -e "${{ inputs.environment }}"
azd env set AZURE_ENV_NAME "${{ inputs.environment }}" -e "${{ inputs.environment }}"
azd env set AZURE_RESOURCE_GROUP "${{ inputs.projectName }}-${{ inputs.environment }}-rg" -e "${{ inputs.environment }}"
azd env set resourceGroupName "${{ inputs.projectName }}-${{ inputs.environment }}-rg" -e "${{ inputs.environment }}"
azd env set AZURE_AKS_CLUSTER_NAME "${{ inputs.projectName }}-${{ inputs.environment }}-aks" -e "${{ inputs.environment }}"
azd env set AKS_CLUSTER_NAME "${{ inputs.projectName }}-${{ inputs.environment }}-aks" -e "${{ inputs.environment }}"
azd env set AZURE_CONTAINER_REGISTRY_ENDPOINT "${{ inputs.projectName }}${{ inputs.environment }}acr.azurecr.io" -e "${{ inputs.environment }}"
azd env set deployShared true -e "${{ inputs.environment }}"
azd env set deployStatic "${{ inputs.deployStatic }}" -e "${{ inputs.environment }}"
azd env set environment "${{ inputs.environment }}" -e "${{ inputs.environment }}"
azd env set location "${{ inputs.location }}" -e "${{ inputs.environment }}"
azd env set projectName "${{ inputs.projectName }}" -e "${{ inputs.environment }}"
azd env set IMAGE_PREFIX "ghcr.io/${{ github.repository_owner }}" -e "${{ inputs.environment }}"
azd env set IMAGE_TAG "${{ inputs.imageTag }}" -e "${{ inputs.environment }}"
azd env set K8S_NAMESPACE holiday-peak -e "${{ inputs.environment }}"
azd env set KEDA_ENABLED false -e "${{ inputs.environment }}"
- name: Ensure deploy principal has AKS RBAC Cluster Admin
shell: bash
run: |
set -euo pipefail
AKS_RG="${{ inputs.projectName }}-${{ inputs.environment }}-rg"
DEPLOY_SP_OBJECT_ID=$(az ad sp show --id "${AZURE_CLIENT_ID}" --query id -o tsv)
RG_ID=$(az group show --name "$AKS_RG" --query id -o tsv)
EXISTING=$(az role assignment list \
--scope "$RG_ID" \
--assignee-object-id "$DEPLOY_SP_OBJECT_ID" \
--query "[?roleDefinitionName=='Azure Kubernetes Service RBAC Cluster Admin'] | length(@)" -o tsv)
if [ "$EXISTING" = "0" ]; then
echo "Assigning Azure Kubernetes Service RBAC Cluster Admin to deploy principal at RG scope $AKS_RG."
az role assignment create \
--assignee-object-id "$DEPLOY_SP_OBJECT_ID" \
--assignee-principal-type ServicePrincipal \
--role "Azure Kubernetes Service RBAC Cluster Admin" \
--scope "$RG_ID"
else
echo "Deploy principal already has Azure Kubernetes Service RBAC Cluster Admin at RG scope $AKS_RG."
fi
VERIFIED=$(az role assignment list \
--scope "$RG_ID" \
--assignee-object-id "$DEPLOY_SP_OBJECT_ID" \
--query "[?roleDefinitionName=='Azure Kubernetes Service RBAC Cluster Admin'] | length(@)" -o tsv)
if [ "$VERIFIED" = "0" ]; then
echo "Failed to verify Azure Kubernetes Service RBAC Cluster Admin assignment for deploy principal at scope $AKS_RG."
exit 1
fi
- name: Preflight drift remediation (non-prod)
if: ${{ inputs.environment != 'prod' && inputs.environment != 'production' }}
shell: bash
run: |
set -euo pipefail
RG_NAME="${{ inputs.projectName }}-${{ inputs.environment }}-rg"
KEY_VAULT_NAME="${{ inputs.projectName }}-${{ inputs.environment }}-kv"
POSTGRES_SERVER_NAME="${{ inputs.projectName }}-${{ inputs.environment }}-postgres"
DESIRED_LOCATION="$(echo "${{ inputs.location }}" | tr '[:upper:]' '[:lower:]')"
echo "Running non-prod preflight drift remediation for environment '${{ inputs.environment }}'."
# Remediate soft-deleted Key Vault name conflicts that can block azd provision.
if az keyvault show --name "$KEY_VAULT_NAME" --resource-group "$RG_NAME" >/dev/null 2>&1; then
CURRENT_KV_LOCATION=$(az keyvault show \
--name "$KEY_VAULT_NAME" \
--resource-group "$RG_NAME" \
--query location -o tsv | tr '[:upper:]' '[:lower:]')
if [ "$CURRENT_KV_LOCATION" != "$DESIRED_LOCATION" ]; then
LOCATION_SUFFIX=$(echo "$DESIRED_LOCATION" | tr -cd '[:alnum:]' | cut -c1-4)
KEY_VAULT_OVERRIDE=$(echo "${{ inputs.projectName }}-${{ inputs.environment }}-kv-${LOCATION_SUFFIX}" | tr '[:upper:]' '[:lower:]' | cut -c1-24)
KEY_VAULT_OVERRIDE="${KEY_VAULT_OVERRIDE%-}"
echo "Key Vault location mismatch detected for $KEY_VAULT_NAME ($CURRENT_KV_LOCATION vs $DESIRED_LOCATION)."
echo "Setting keyVaultNameOverride to $KEY_VAULT_OVERRIDE for this deployment."
azd env set keyVaultNameOverride "$KEY_VAULT_OVERRIDE" -e "${{ inputs.environment }}"
else
echo "Key Vault $KEY_VAULT_NAME already exists in $RG_NAME with matching location $CURRENT_KV_LOCATION."
fi
else
DELETED_KV_LOCATION=$(az keyvault list-deleted \
--query "[?name=='$KEY_VAULT_NAME'] | [0].properties.location" \
-o tsv)
if [ -n "$DELETED_KV_LOCATION" ]; then
echo "Recovering soft-deleted Key Vault $KEY_VAULT_NAME."
if az keyvault recover --name "$KEY_VAULT_NAME" >/dev/null 2>&1; then
echo "Recovery initiated for $KEY_VAULT_NAME."
else
echo "Recovery failed for $KEY_VAULT_NAME. Attempting purge fallback from $DELETED_KV_LOCATION."
az keyvault purge --name "$KEY_VAULT_NAME" --location "$DELETED_KV_LOCATION"
fi
for _ in $(seq 1 20); do
if az keyvault show --name "$KEY_VAULT_NAME" --resource-group "$RG_NAME" >/dev/null 2>&1; then
echo "Key Vault $KEY_VAULT_NAME is now available in $RG_NAME."
break
fi
sleep 10
done
else
echo "No soft-deleted Key Vault conflict found for $KEY_VAULT_NAME."
fi
fi
# Start stopped PostgreSQL Flexible Server so provisioning can reconcile state.
if az postgres flexible-server show --resource-group "$RG_NAME" --name "$POSTGRES_SERVER_NAME" >/dev/null 2>&1; then
POSTGRES_STATE=$(az postgres flexible-server show \
--resource-group "$RG_NAME" \
--name "$POSTGRES_SERVER_NAME" \
--query state -o tsv)
if [ "$POSTGRES_STATE" = "Stopped" ]; then
echo "PostgreSQL server $POSTGRES_SERVER_NAME is stopped. Starting..."
az postgres flexible-server start --resource-group "$RG_NAME" --name "$POSTGRES_SERVER_NAME"
POSTGRES_READY=false
for _ in $(seq 1 40); do
CURRENT_STATE=$(az postgres flexible-server show \
--resource-group "$RG_NAME" \
--name "$POSTGRES_SERVER_NAME" \
--query state -o tsv)
if [ "$CURRENT_STATE" = "Ready" ]; then
echo "PostgreSQL server is ready."
POSTGRES_READY=true
break
fi
sleep 15
done
if [ "$POSTGRES_READY" != "true" ]; then
echo "PostgreSQL server $POSTGRES_SERVER_NAME did not reach Ready state in time."
exit 1
fi
else
echo "PostgreSQL server $POSTGRES_SERVER_NAME state is $POSTGRES_STATE. No start needed."
fi
else
echo "PostgreSQL server $POSTGRES_SERVER_NAME does not exist yet. Continuing."
fi
- name: Validate truth Event Hubs IaC declarations
shell: bash
run: |
set -euo pipefail
BICEP_FILE=".infra/modules/shared-infrastructure/shared-infrastructure.bicep"
for hub in ingest-jobs enrichment-jobs export-jobs hitl-jobs; do
if ! grep -q "'$hub'" "$BICEP_FILE"; then
echo "Missing required truth Event Hub declaration in $BICEP_FILE: $hub" >&2
exit 1
fi
done
for group in ingestion-group enrichment-engine export-engine hitl-service; do
if ! grep -q "'$group'" "$BICEP_FILE"; then
echo "Missing required truth consumer group declaration in $BICEP_FILE: $group" >&2
exit 1
fi
done
echo "Truth Event Hub and consumer group declarations are present in IaC."
- name: Provision infrastructure
run: azd provision --no-prompt -e "${{ inputs.environment }}"
- name: Ensure AKS identity can read Key Vault secrets
run: |
AKS_RG="${{ inputs.projectName }}-${{ inputs.environment }}-rg"
AKS_NAME="${{ inputs.projectName }}-${{ inputs.environment }}-aks"
KEY_VAULT_NAME="${{ inputs.projectName }}-${{ inputs.environment }}-kv"
KUBELET_OBJECT_ID=$(az aks show \
--resource-group "$AKS_RG" \
--name "$AKS_NAME" \
--query "identityProfile.kubeletidentity.objectId" -o tsv)
KEY_VAULT_ID=$(az keyvault show \
--resource-group "$AKS_RG" \
--name "$KEY_VAULT_NAME" \
--query id -o tsv)
EXISTING=$(az role assignment list \
--assignee-object-id "$KUBELET_OBJECT_ID" \
--scope "$KEY_VAULT_ID" \
--query "[?roleDefinitionName=='Key Vault Secrets User'] | length(@)" -o tsv)
if [ "$EXISTING" = "0" ]; then
az role assignment create \
--assignee-object-id "$KUBELET_OBJECT_ID" \
--assignee-principal-type ServicePrincipal \
--role "Key Vault Secrets User" \
--scope "$KEY_VAULT_ID"
fi
- name: Export provisioned outputs
id: outputs
run: |
eval "$(azd env get-values -e '${{ inputs.environment }}' | sed 's/^/export /')"
APIM_GATEWAY_URL_VALUE="${APIM_GATEWAY_URL:-${apimGatewayUrl:-}}"
{
echo "AI_SERVICES_NAME=${AI_SERVICES_NAME}"
echo "PROJECT_ENDPOINT=${PROJECT_ENDPOINT}"
echo "PROJECT_NAME=${PROJECT_NAME}"
echo "APIM_GATEWAY_URL=${APIM_GATEWAY_URL_VALUE}"
echo "COSMOS_ACCOUNT_URI=${COSMOS_ACCOUNT_URI}"
echo "COSMOS_DATABASE=${COSMOS_DATABASE}"
echo "KEY_VAULT_URI=${KEY_VAULT_URI}"
echo "REDIS_HOST=${REDIS_HOST}"
echo "EVENT_HUB_NAMESPACE=${EVENT_HUB_NAMESPACE}"
echo "APPLICATIONINSIGHTS_CONNECTION_STRING=${APPLICATIONINSIGHTS_CONNECTION_STRING}"
echo "POSTGRES_HOST=${POSTGRES_HOST}"
echo "POSTGRES_USER=${POSTGRES_USER}"
echo "POSTGRES_ADMIN_USER=${POSTGRES_ADMIN_USER}"
echo "POSTGRES_AUTH_MODE=${POSTGRES_AUTH_MODE}"
echo "POSTGRES_DATABASE=${POSTGRES_DATABASE}"
} >> "$GITHUB_OUTPUT"
deploy-foundry-models:
runs-on: ubuntu-latest
needs: provision
environment: ${{ inputs.environment }}
env:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
steps:
- uses: actions/checkout@v4
- name: Azure login (OIDC)
uses: azure/login@v2
with:
client-id: ${{ env.AZURE_CLIENT_ID }}
tenant-id: ${{ env.AZURE_TENANT_ID }}
subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }}
- name: Deploy AI model deployments
run: |
bash .infra/azd/hooks/deploy-foundry-models.sh \
"${{ inputs.projectName }}-${{ inputs.environment }}-rg" \
"${{ needs.provision.outputs.AI_SERVICES_NAME }}"
env:
AZURE_RESOURCE_GROUP: ${{ inputs.projectName }}-${{ inputs.environment }}-rg
AI_SERVICES_NAME: ${{ needs.provision.outputs.AI_SERVICES_NAME }}
deploy-crud:
runs-on: ubuntu-latest
needs:
- provision
- detect-changes
if: ${{ !inputs.uiOnly && needs.detect-changes.outputs.crud_changed == 'true' }}
environment: ${{ inputs.environment }}
env:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
steps:
- uses: actions/checkout@v4
- name: Azure login (OIDC)
uses: azure/login@v2
with:
client-id: ${{ env.AZURE_CLIENT_ID }}
tenant-id: ${{ env.AZURE_TENANT_ID }}
subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }}
- name: Setup azd
uses: Azure/setup-azd@v2
- name: Authenticate azd (OIDC)
run: |
azd auth login \
--client-id "${AZURE_CLIENT_ID}" \
--tenant-id "${AZURE_TENANT_ID}" \
--federated-credential-provider github \
--no-prompt
- name: Configure azd environment context
run: |
azd env set AZURE_SUBSCRIPTION_ID "${AZURE_SUBSCRIPTION_ID}" -e "${{ inputs.environment }}"
azd env set AZURE_LOCATION "${{ inputs.location }}" -e "${{ inputs.environment }}"
azd env set AZURE_ENV_NAME "${{ inputs.environment }}" -e "${{ inputs.environment }}"
azd env set AZURE_RESOURCE_GROUP "${{ inputs.projectName }}-${{ inputs.environment }}-rg" -e "${{ inputs.environment }}"
azd env set resourceGroupName "${{ inputs.projectName }}-${{ inputs.environment }}-rg" -e "${{ inputs.environment }}"
azd env set AZURE_AKS_CLUSTER_NAME "${{ inputs.projectName }}-${{ inputs.environment }}-aks" -e "${{ inputs.environment }}"
azd env set AKS_CLUSTER_NAME "${{ inputs.projectName }}-${{ inputs.environment }}-aks" -e "${{ inputs.environment }}"
azd env set AZURE_CONTAINER_REGISTRY_ENDPOINT "${{ inputs.projectName }}${{ inputs.environment }}acr.azurecr.io" -e "${{ inputs.environment }}"
- name: Install kubelogin
run: |
for attempt in 1 2 3 4 5; do
if az aks install-cli --kubelogin-version latest; then
exit 0
fi
echo "kubelogin install failed on attempt ${attempt}; retrying..."
sleep 15
done
echo "kubelogin install failed after retries"
exit 1
- name: Ensure hook scripts executable
run: chmod +x ./.infra/azd/hooks/*.sh
- name: Configure azd environment context
run: |
azd env set AZURE_SUBSCRIPTION_ID "${AZURE_SUBSCRIPTION_ID}" -e "${{ inputs.environment }}"
azd env set AZURE_LOCATION "${{ inputs.location }}" -e "${{ inputs.environment }}"
azd env set AZURE_ENV_NAME "${{ inputs.environment }}" -e "${{ inputs.environment }}"
azd env set AZURE_RESOURCE_GROUP "${{ inputs.projectName }}-${{ inputs.environment }}-rg" -e "${{ inputs.environment }}"
azd env set resourceGroupName "${{ inputs.projectName }}-${{ inputs.environment }}-rg" -e "${{ inputs.environment }}"
azd env set AZURE_AKS_CLUSTER_NAME "${{ inputs.projectName }}-${{ inputs.environment }}-aks" -e "${{ inputs.environment }}"
azd env set AKS_CLUSTER_NAME "${{ inputs.projectName }}-${{ inputs.environment }}-aks" -e "${{ inputs.environment }}"
azd env set AZURE_CONTAINER_REGISTRY_ENDPOINT "${{ inputs.projectName }}${{ inputs.environment }}acr.azurecr.io" -e "${{ inputs.environment }}"
- name: Get AKS credentials
run: |
az aks get-credentials \
--resource-group "${{ inputs.projectName }}-${{ inputs.environment }}-rg" \
--name "${{ inputs.projectName }}-${{ inputs.environment }}-aks" \
--overwrite-existing
- name: Resolve AKS managed identity client ID
run: |
AKS_MI_CLIENT_ID=$(az aks show \
--resource-group "${{ inputs.projectName }}-${{ inputs.environment }}-rg" \
--name "${{ inputs.projectName }}-${{ inputs.environment }}-aks" \
--query "identityProfile.kubeletidentity.clientId" -o tsv)
echo "WORKLOAD_AZURE_CLIENT_ID=${AKS_MI_CLIENT_ID}" >> "$GITHUB_ENV"
- name: Resolve ingress class
shell: bash
run: |
set -euo pipefail
kubectl get ingressclass -o wide || true
if [ -n "${INGRESS_CLASS_NAME:-}" ] && kubectl get ingressclass "${INGRESS_CLASS_NAME}" >/dev/null 2>&1; then
echo "Using preconfigured ingress class: ${INGRESS_CLASS_NAME}"
echo "INGRESS_CLASS_NAME=${INGRESS_CLASS_NAME}" >> "$GITHUB_ENV"
exit 0
fi
for cls in webapprouting.kubernetes.azure.com nginx azure-application-gateway; do
if kubectl get ingressclass "$cls" >/dev/null 2>&1; then
echo "Using detected ingress class: $cls"
echo "INGRESS_CLASS_NAME=$cls" >> "$GITHUB_ENV"
exit 0
fi
done
echo "No supported IngressClass found. Enable AKS Web App Routing or provide INGRESS_CLASS_NAME." >&2
exit 1
- name: Preflight ACR data-plane accessibility
shell: bash
run: |
set -euo pipefail
RG_NAME="${{ inputs.projectName }}-${{ inputs.environment }}-rg"
ACR_NAME=$(echo "${{ inputs.projectName }}${{ inputs.environment }}acr" | tr -cd '[:alnum:]' | tr '[:upper:]' '[:lower:]')
if ! az acr show --resource-group "$RG_NAME" --name "$ACR_NAME" >/dev/null 2>&1; then
echo "ACR preflight could not find registry '$ACR_NAME' in resource group '$RG_NAME'." >&2
echo "Verify naming convention or set AZURE_CONTAINER_REGISTRY_ENDPOINT in azd env before deploy." >&2
exit 1
fi
ACR_LOGIN_SERVER=$(az acr show \
--resource-group "$RG_NAME" \
--name "$ACR_NAME" \
--query "loginServer" -o tsv)
STATUS_CODE=$(curl -sS -o /tmp/acr-v2-probe.txt -w "%{http_code}" --max-time 25 "https://${ACR_LOGIN_SERVER}/v2/" || true)
if [ "$STATUS_CODE" = "200" ] || [ "$STATUS_CODE" = "401" ]; then
echo "ACR preflight passed: ${ACR_LOGIN_SERVER} is reachable from this runner (HTTP $STATUS_CODE)."
exit 0
fi
RUNNER_IP=$(curl -sS --max-time 10 https://api.ipify.org || true)
echo "ACR preflight failed: ${ACR_LOGIN_SERVER}/v2/ returned HTTP ${STATUS_CODE}." >&2
if [ "$STATUS_CODE" = "403" ]; then
echo "Likely cause: ACR firewall/network rules are blocking this GitHub-hosted runner." >&2
fi
if [ -n "$RUNNER_IP" ]; then
echo "Runner egress IP detected: $RUNNER_IP" >&2
echo "Action: allow this IP (or CIDR) on ACR '$ACR_NAME' or use a self-hosted runner in an allowed network." >&2
echo "Example: az acr network-rule add --name '$ACR_NAME' --resource-group '$RG_NAME' --ip-address '$RUNNER_IP'" >&2
else
echo "Action: check ACR firewall/network rules for GitHub runner egress and retry." >&2
fi
exit 1
- name: Deploy CRUD service
timeout-minutes: 25
shell: bash
run: |
set -euo pipefail
max_attempts=4
for attempt in $(seq 1 "$max_attempts"); do
echo "Deploy attempt ${attempt}/${max_attempts}"
if azd deploy --service crud-service --no-prompt -e "${{ inputs.environment }}"; then
echo "CRUD deploy succeeded."
exit 0
fi
echo "Attempt ${attempt} failed; collecting ingress diagnostics..."
kubectl get ingressclass -o wide || true
kubectl get ingress -n holiday-peak -o wide || true
kubectl get pods -n app-routing-system -o wide || true
kubectl get pods -n ingress-nginx -o wide || true
if [ "$attempt" -eq "$max_attempts" ]; then
echo "CRUD deploy failed after ${max_attempts} attempts." >&2
exit 1
fi
backoff=$((attempt * 45))
echo "Retrying after ${backoff}s..."
sleep "$backoff"
done
env:
INGRESS_CLASS_NAME: ${{ env.INGRESS_CLASS_NAME }}
AZURE_CLIENT_ID: ${{ env.WORKLOAD_AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ env.AZURE_TENANT_ID }}
PROJECT_ENDPOINT: ${{ needs.provision.outputs.PROJECT_ENDPOINT }}
PROJECT_NAME: ${{ needs.provision.outputs.PROJECT_NAME }}
MODEL_DEPLOYMENT_NAME_FAST: gpt-5-nano
MODEL_DEPLOYMENT_NAME_RICH: gpt-5-nano
POSTGRES_AUTH_MODE: ${{ needs.provision.outputs.POSTGRES_AUTH_MODE }}
COSMOS_ACCOUNT_URI: ${{ needs.provision.outputs.COSMOS_ACCOUNT_URI }}
COSMOS_DATABASE: ${{ needs.provision.outputs.COSMOS_DATABASE }}
REDIS_HOST: ${{ needs.provision.outputs.REDIS_HOST }}
EVENT_HUB_NAMESPACE: ${{ needs.provision.outputs.EVENT_HUB_NAMESPACE }}
KEY_VAULT_URI: ${{ needs.provision.outputs.KEY_VAULT_URI }}
APPLICATIONINSIGHTS_CONNECTION_STRING: ${{ needs.provision.outputs.APPLICATIONINSIGHTS_CONNECTION_STRING }}
POSTGRES_HOST: ${{ needs.provision.outputs.POSTGRES_HOST }}
POSTGRES_USER: ${{ needs.provision.outputs.POSTGRES_AUTH_MODE == 'password' && needs.provision.outputs.POSTGRES_ADMIN_USER || needs.provision.outputs.POSTGRES_USER }}
POSTGRES_DATABASE: ${{ needs.provision.outputs.POSTGRES_DATABASE }}
- name: Gate CRUD readiness (/ready)
shell: bash
run: |
set -euo pipefail
APIM_BASE="${{ needs.provision.outputs.APIM_GATEWAY_URL }}"
APIM_BASE="${APIM_BASE%/}"
APIM_READY_URL="${APIM_BASE}/api/ready"
SERVICE_READY_URL="http://127.0.0.1:18080/ready"
check_ready() {
local url="$1"
local label="$2"
for attempt in $(seq 1 24); do
STATUS_CODE=$(curl -sS -o /tmp/crud-ready.json -w "%{http_code}" "$url" || true)
if [ "$STATUS_CODE" = "200" ]; then
echo "[OK] ${label} ready on attempt ${attempt}: ${url}"
return 0
fi
echo "Attempt ${attempt}/24: ${label} returned HTTP ${STATUS_CODE}"
sleep 10
done
echo "[FAIL] ${label} readiness did not return HTTP 200: ${url}" >&2
cat /tmp/crud-ready.json 2>/dev/null || true
return 1
}
APIM_READY=false
if [ -n "$APIM_BASE" ]; then
if check_ready "$APIM_READY_URL" "APIM /api/ready"; then
APIM_READY=true
fi
else
echo "APIM gateway URL not provided by provision outputs; skipping APIM /api/ready check."
fi
kubectl port-forward svc/crud-service 18080:8000 -n holiday-peak >/tmp/crud-port-forward.log 2>&1 &
PF_PID=$!
trap 'kill "$PF_PID" >/dev/null 2>&1 || true' EXIT
sleep 3
SERVICE_READY=false
if check_ready "$SERVICE_READY_URL" "service /ready"; then
SERVICE_READY=true
fi
if [ "$APIM_READY" != "true" ] && [ "$SERVICE_READY" != "true" ]; then
echo "CRUD readiness gate failed: both APIM and direct service /ready checks are unhealthy." >&2
echo "Port-forward log:" >&2
cat /tmp/crud-port-forward.log 2>/dev/null || true
exit 1
fi
deploy-ui:
runs-on: ubuntu-latest
if: ${{ always() && inputs.deployStatic && !inputs.uiOnly && needs.detect-changes.outputs.ui_changed == 'true' && (needs.deploy-crud.result == 'success' || needs.deploy-crud.result == 'skipped') && (needs.deploy-agents.result == 'success' || needs.deploy-agents.result == 'skipped') && (needs.sync-apim.result == 'success' || needs.sync-apim.result == 'skipped') && (needs.ensure-foundry-agents.result == 'success' || needs.ensure-foundry-agents.result == 'skipped') && (needs.smoke-apim.result == 'success' || needs.smoke-apim.result == 'skipped') }}
needs:
- provision
- detect-changes
- deploy-crud
- deploy-agents
- sync-apim
- ensure-foundry-agents
- smoke-apim
environment: ${{ inputs.environment }}
env:
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
steps:
- uses: actions/checkout@v4
- name: Azure login (OIDC)
uses: azure/login@v2
with:
client-id: ${{ env.AZURE_CLIENT_ID }}
tenant-id: ${{ env.AZURE_TENANT_ID }}
subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }}
- name: Setup azd
uses: Azure/setup-azd@v2
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Resolve API URL
id: api
shell: bash
run: |
set -euo pipefail
RESOURCE_GROUP="${{ inputs.projectName }}-${{ inputs.environment }}-rg"
EXPECTED_APIM_URL="${{ needs.provision.outputs.APIM_GATEWAY_URL }}"
if [ -z "$EXPECTED_APIM_URL" ]; then
echo "Provision output APIM_GATEWAY_URL is empty. Cannot safely propagate API URL to UI build." >&2
exit 1
fi
APIM_URL=$(az apim show \
--name "${{ inputs.projectName }}-${{ inputs.environment }}-apim" \
--resource-group "$RESOURCE_GROUP" \
--query "gatewayUrl" -o tsv)
APIM_URL="$(echo "$APIM_URL" | xargs)"
EXPECTED_APIM_URL="$(echo "$EXPECTED_APIM_URL" | xargs)"
APIM_URL="${APIM_URL%/}"
EXPECTED_APIM_URL="${EXPECTED_APIM_URL%/}"
if [ -z "$APIM_URL" ]; then
echo "Failed to resolve APIM gatewayUrl for resource group $RESOURCE_GROUP. Ensure APIM exists and is provisioned before deploying UI." >&2
exit 1
fi
if [ "$APIM_URL" != "$EXPECTED_APIM_URL" ]; then
echo "APIM URL drift detected between provision output and live APIM gateway URL." >&2
echo "Expected: $EXPECTED_APIM_URL" >&2
echo "Actual: $APIM_URL" >&2
exit 1
fi
echo "api_url=$EXPECTED_APIM_URL" >> "$GITHUB_OUTPUT"
echo "crud_api_url=$EXPECTED_APIM_URL" >> "$GITHUB_OUTPUT"
- name: Smoke test APIM API health before UI deploy
shell: bash
run: |
set -euo pipefail
API_BASE_URL="${{ steps.api.outputs.api_url }}"
API_BASE_URL="${API_BASE_URL%/}"
smoke_endpoint() {
local url="$1"
local label="$2"
for attempt in $(seq 1 20); do
STATUS_CODE=$(curl -sS -o /tmp/api-health.json -w "%{http_code}" "$url" || true)
if [ "$STATUS_CODE" = "200" ]; then
echo "[OK] $label: $url"
return 0
fi
echo "Attempt $attempt/20: $label returned HTTP $STATUS_CODE"
sleep 10
done
echo "[FAIL] $label: $url" >&2
cat /tmp/api-health.json 2>/dev/null || true
return 1
}
smoke_endpoint "${API_BASE_URL}/api/health" "crud-health"
smoke_endpoint "${API_BASE_URL}/api/products?limit=1" "crud-products"
smoke_endpoint "${API_BASE_URL}/api/categories" "crud-categories"
- name: Resolve SWA deployment token
id: swa
shell: bash
run: |
set -euo pipefail
RESOURCE_GROUP="${{ inputs.projectName }}-${{ inputs.environment }}-rg"
EXPECTED_SWA_NAME="${{ inputs.projectName }}-ui-${{ inputs.environment }}"
SWA_NAME=""
if az staticwebapp show --name "$EXPECTED_SWA_NAME" --resource-group "$RESOURCE_GROUP" >/dev/null 2>&1; then
SWA_NAME="$EXPECTED_SWA_NAME"
else
SWA_NAME=$(az staticwebapp list \
--resource-group "$RESOURCE_GROUP" \
--query "[?starts_with(defaultHostname, '${EXPECTED_SWA_NAME}.')].name | [0]" -o tsv)
if [ -z "$SWA_NAME" ]; then
COUNT=$(az staticwebapp list --resource-group "$RESOURCE_GROUP" --query "length(@)" -o tsv)
if [ "$COUNT" = "1" ]; then
SWA_NAME=$(az staticwebapp list --resource-group "$RESOURCE_GROUP" --query "[0].name" -o tsv)
fi
fi
fi
if [ -z "$SWA_NAME" ]; then
echo "Could not deterministically resolve Static Web App in $RESOURCE_GROUP." >&2
echo "Expected name: $EXPECTED_SWA_NAME" >&2
echo "Action: align SWA naming with IaC convention or keep exactly one SWA in the resource group." >&2
exit 1
fi
SWA_TOKEN=$(az staticwebapp secrets list \
--name "$SWA_NAME" \
--resource-group "$RESOURCE_GROUP" \
--query "properties.apiKey" -o tsv)
if [ -z "$SWA_TOKEN" ]; then
echo "Failed to resolve deployment token for SWA $SWA_NAME"
exit 1
fi
echo "::add-mask::$SWA_TOKEN"
echo "swa_name=$SWA_NAME" >> "$GITHUB_OUTPUT"
echo "swa_token=$SWA_TOKEN" >> "$GITHUB_OUTPUT"
- name: Deploy UI via Static Web Apps action
uses: Azure/static-web-apps-deploy@v1
with:
action: upload
azure_static_web_apps_api_token: ${{ steps.swa.outputs.swa_token }}
app_location: apps/ui
output_location: ''
skip_api_build: true
app_build_command: yarn install --frozen-lockfile && yarn build
env:
NEXT_PUBLIC_API_URL: ${{ steps.api.outputs.api_url }}
NEXT_PUBLIC_CRUD_API_URL: ${{ steps.api.outputs.crud_api_url }}
NEXT_PUBLIC_ENTRA_CLIENT_ID: ${{ secrets.NEXT_PUBLIC_ENTRA_CLIENT_ID }}
NEXT_PUBLIC_ENTRA_TENANT_ID: ${{ secrets.NEXT_PUBLIC_ENTRA_TENANT_ID }}
- name: Smoke test UI host and API health after deploy
shell: bash
run: |
set -euo pipefail
RESOURCE_GROUP="${{ inputs.projectName }}-${{ inputs.environment }}-rg"
SWA_NAME="${{ steps.swa.outputs.swa_name }}"
API_BASE_URL="${{ steps.api.outputs.api_url }}"
SWA_HOSTNAME=$(az staticwebapp show \
--name "$SWA_NAME" \
--resource-group "$RESOURCE_GROUP" \
--query "defaultHostname" -o tsv)
SWA_HOSTNAME="$(echo "$SWA_HOSTNAME" | xargs)"
if [ -z "$SWA_HOSTNAME" ]; then
echo "Could not resolve Static Web App hostname for $SWA_NAME" >&2
exit 1
fi
UI_URL="https://$SWA_HOSTNAME"
for attempt in $(seq 1 20); do
STATUS_CODE=$(curl -sS -o /tmp/ui-homepage.html -w "%{http_code}" "$UI_URL" || true)
if [ "$STATUS_CODE" = "200" ]; then
echo "UI homepage is reachable: $UI_URL"
break
fi
if [ "$attempt" -eq 20 ]; then
echo "UI smoke test failed with HTTP $STATUS_CODE at $UI_URL" >&2
exit 1
fi
sleep 10