Skip to content

Commit fd99dcb

Browse files
fix: update the local development scripts, readme and custom deployment pre provision hook
2 parents 39dab72 + 7719f85 commit fd99dcb

File tree

8 files changed

+548
-330
lines changed

8 files changed

+548
-330
lines changed

.env.sample

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ AZURE_OPENAI_MAX_TOKENS=2000
5353
# =============================================================================
5454
# Azure Cosmos DB
5555
# =============================================================================
56+
COSMOSDB_ACCOUNT_NAME=your-cosmos-account
5657
AZURE_COSMOS_ENDPOINT=https://your-cosmos.documents.azure.com:443/
5758
AZURE_COSMOS_DATABASE_NAME=content-generation
5859
AZURE_COSMOS_PRODUCTS_CONTAINER=products
@@ -106,6 +107,7 @@ BRAND_REQUIRED_DISCLOSURES=
106107
# =============================================================================
107108
# Application Settings
108109
# =============================================================================
110+
RESOURCE_GROUP_NAME=your-resource-group
109111
# Server configuration
110112
PORT=5000
111113
WORKERS=4

azure_custom.yaml

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -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 ""

docs/AZD_DEPLOYMENT.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ When `enablePrivateNetworking` is enabled:
309309
└─────────────────────────────────────────────────────────────────┘
310310
```
311311

312-
## Deploy Local Changes
312+
## Advanced: Deploy Local Changes
313313

314314
If you've made local modifications to the code and want to deploy them to Azure, follow these steps to swap the configuration files:
315315

0 commit comments

Comments
 (0)