@@ -34,10 +34,35 @@ hooks:
3434 run : |
3535 Write-Host "Preparing deployment..." -ForegroundColor Cyan
3636
37- # Check if this is first run (ACR doesn't exist yet)
38- # Set AZURE_ENV_IMAGE_TAG='none' to skip ACI deployment until image is built
39- if (-not $env:AZURE_ENV_CONTAINER_REGISTRY_NAME) {
37+ # Check if image exists in the ACR (handles fresh deploy AND deployment mode switch)
38+ $acrName = azd env get-value AZURE_ENV_CONTAINER_REGISTRY_NAME 2>$null
39+ $global:LASTEXITCODE = 0
40+ $skipAci = $false
41+
42+ if (-not $acrName) {
4043 Write-Host "First deployment - ACI will be deployed after image build" -ForegroundColor Yellow
44+ $skipAci = $true
45+ } elseif ($acrName -eq 'contentgencontainerreg') {
46+ # Switching from standard (shared ACR) to custom (own ACR) deployment
47+ # Clear ACI name so postprovision deploys fresh with new ACR
48+ Write-Host "Switching to custom deployment - ACI will be redeployed with new ACR" -ForegroundColor Yellow
49+ azd env set CONTAINER_INSTANCE_NAME ""
50+ $skipAci = $true
51+ } else {
52+ # Custom ACR exists - check if image is present
53+ Write-Host "Checking for existing image in $acrName..." -ForegroundColor Cyan
54+ $imageCheck = az acr repository show --name $acrName --image "content-gen-api:latest" 2>$null
55+ $global:LASTEXITCODE = 0
56+
57+ if (-not $imageCheck) {
58+ Write-Host "Image not found in ACR - will build in postprovision" -ForegroundColor Yellow
59+ $skipAci = $true
60+ } else {
61+ Write-Host "Image found - ACI deployment will proceed" -ForegroundColor Green
62+ }
63+ }
64+
65+ if ($skipAci) {
4166 azd env set AZURE_ENV_IMAGE_TAG none
4267 }
4368 continueOnError : false
@@ -46,9 +71,31 @@ hooks:
4671 run : |
4772 echo "Preparing deployment..."
4873
49- # Check if this is first run (ACR doesn't exist yet)
50- if [ -z "$AZURE_ENV_CONTAINER_REGISTRY_NAME" ]; then
74+ # Check if image exists in the ACR (handles fresh deploy AND deployment mode switch)
75+ ACR_NAME=$(azd env get-value AZURE_ENV_CONTAINER_REGISTRY_NAME 2>/dev/null || echo "")
76+ SKIP_ACI=false
77+
78+ if [ -z "$ACR_NAME" ]; then
5179 echo "First deployment - ACI will be deployed after image build"
80+ SKIP_ACI=true
81+ elif [ "$ACR_NAME" = "contentgencontainerreg" ]; then
82+ # Switching from standard (shared ACR) to custom (own ACR) deployment
83+ # Clear ACI name so postprovision deploys fresh with new ACR
84+ echo "Switching to custom deployment - ACI will be redeployed with new ACR"
85+ azd env set CONTAINER_INSTANCE_NAME ""
86+ SKIP_ACI=true
87+ else
88+ # Custom ACR exists - check if image is present
89+ echo "Checking for existing image in $ACR_NAME..."
90+ if az acr repository show --name "$ACR_NAME" --image "content-gen-api:latest" >/dev/null 2>&1; then
91+ echo "Image found - ACI deployment will proceed"
92+ else
93+ echo "Image not found in ACR - will build in postprovision"
94+ SKIP_ACI=true
95+ fi
96+ fi
97+
98+ if [ "$SKIP_ACI" = "true" ]; then
5299 azd env set AZURE_ENV_IMAGE_TAG none
53100 fi
54101 continueOnError : false
@@ -113,13 +160,13 @@ hooks:
113160 }
114161 } else {
115162 Write-Host ""
116- Write-Host "Container Instance: $aciName" -ForegroundColor Cyan
163+ Write-Host "Restarting Container Instance to pick up new image..." -ForegroundColor Yellow
164+ az container restart --name $aciName --resource-group $resourceGroup 2>$null
165+ Write-Host "Container Instance: $aciName (restarted)" -ForegroundColor Cyan
117166 }
118167
119168 Write-Host ""
120169 Write-Host "===== Postprovision Complete - Frontend will deploy next =====" -ForegroundColor Green
121-
122- # Ensure postprovision exits successfully so frontend deploys
123170 exit 0
124171 interactive : true
125172 continueOnError : false
@@ -178,7 +225,9 @@ hooks:
178225 fi
179226 else
180227 echo ""
181- echo "Container Instance: $ACI_NAME"
228+ echo "Restarting Container Instance to pick up new image..."
229+ az container restart --name "$ACI_NAME" --resource-group "$RESOURCE_GROUP" 2>/dev/null
230+ echo "Container Instance: $ACI_NAME (restarted)"
182231 fi
183232
184233 echo ""
0 commit comments