Skip to content

Commit 7b04179

Browse files
chore: Add support for deploying local changes via azd up
2 parents 5dccce1 + 1cb6af4 commit 7b04179

8 files changed

Lines changed: 1588 additions & 47 deletions

File tree

azure_custom.yaml

Lines changed: 223 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,241 @@
1-
environment:
2-
name: document-generation
3-
location: eastus
4-
5-
name: document-generation
1+
name: content-generation
62
metadata:
7-
template: document-generation@1.0
3+
template: content-generation@1.22
84

95
requiredVersions:
106
azd: '>= 1.18.0 != 1.23.9'
117

12-
parameters:
13-
solutionPrefix:
14-
type: string
15-
default: bs-azdtest
16-
otherLocation:
17-
type: string
18-
default: eastus2
19-
baseUrl:
20-
type: string
21-
default: 'https://github.com/microsoft/document-generation-solution-accelerator'
8+
infra:
9+
path: ./infra
10+
module: main
2211

2312
services:
24-
webapp:
25-
project: ./src
26-
language: py
13+
frontend:
14+
project: ./src/app/frontend-server
15+
language: js
2716
host: appservice
2817
dist: ./dist
18+
resourceName: ${APP_SERVICE_NAME}
2919
hooks:
3020
prepackage:
3121
windows:
3222
shell: pwsh
33-
run: ../infra/scripts/package_webapp.ps1
34-
interactive: true
23+
run: ../../../infra/scripts/package_frontend.ps1
3524
continueOnError: false
3625
posix:
3726
shell: sh
38-
run: bash ../infra/scripts/package_webapp.sh
39-
interactive: true
27+
run: chmod +x ../../../infra/scripts/package_frontend.sh && ../../../infra/scripts/package_frontend.sh
4028
continueOnError: false
4129

42-
deployment:
43-
mode: Incremental
44-
template: ./infra/main.bicep # Path to the main.bicep file inside the 'deployment' folder
45-
parameters:
46-
solutionPrefix: ${parameters.solutionPrefix}
47-
otherLocation: ${parameters.otherLocation}
48-
baseUrl: ${parameters.baseUrl}
30+
hooks:
31+
preprovision:
32+
windows:
33+
shell: pwsh
34+
run: |
35+
Write-Host "Preparing deployment..." -ForegroundColor Cyan
36+
37+
# Check if this is first run (ACR doesn't exist yet)
38+
# Set IMAGE_TAG='none' to skip ACI deployment until image is built
39+
$currentTag = azd env get-value IMAGE_TAG 2>$null
40+
$global:LASTEXITCODE = 0
41+
42+
if (-not $env:AZURE_CONTAINER_REGISTRY_NAME -and $currentTag -ne 'latest') {
43+
Write-Host "First deployment - ACI will be deployed after image build" -ForegroundColor Yellow
44+
azd env set IMAGE_TAG none
45+
}
46+
continueOnError: false
47+
posix:
48+
shell: sh
49+
run: |
50+
echo "Preparing deployment..."
51+
52+
# Check if this is first run (ACR doesn't exist yet)
53+
current_tag=$(azd env get-value IMAGE_TAG 2>/dev/null || echo "")
54+
55+
if [ -z "$AZURE_CONTAINER_REGISTRY_NAME" ] && [ "$current_tag" != "latest" ]; then
56+
echo "First deployment - ACI will be deployed after image build"
57+
azd env set IMAGE_TAG none
58+
fi
59+
continueOnError: false
60+
61+
postprovision:
62+
windows:
63+
shell: pwsh
64+
run: |
65+
$acrName = $env:AZURE_CONTAINER_REGISTRY_NAME
66+
$resourceGroup = $env:RESOURCE_GROUP_NAME
67+
$backendImage = $env:BACKEND_IMAGE_NAME
68+
$appServiceName = $env:APP_SERVICE_NAME
69+
70+
if (-not $acrName -or -not $resourceGroup -or -not $appServiceName) {
71+
Write-Host "ERROR: Missing required environment variables" -ForegroundColor Red
72+
exit 1
73+
}
74+
75+
# Check if ACI already exists (reads from persisted azd env)
76+
$aciName = azd env get-value CONTAINER_INSTANCE_NAME 2>$null
77+
$global:LASTEXITCODE = 0
78+
79+
# ===== Build Backend Image (ACR Build) =====
80+
Write-Host ""
81+
Write-Host "===== Building Backend Image =====" -ForegroundColor Yellow
82+
Write-Host "Registry: $acrName" -ForegroundColor Cyan
83+
Write-Host "Image: ${backendImage}:latest" -ForegroundColor Cyan
84+
85+
az acr login --name $acrName 2>$null
86+
az acr build --registry $acrName --image "${backendImage}:latest" --file ./src/backend/ApiApp.Dockerfile ./src/backend
87+
if ($LASTEXITCODE -ne 0) {
88+
Write-Host "Failed to build container image" -ForegroundColor Red
89+
exit 1
90+
}
91+
Write-Host "Container image built and pushed successfully!" -ForegroundColor Green
92+
93+
# ===== Deploy ACI if not already deployed =====
94+
if (-not $aciName) {
95+
Write-Host ""
96+
Write-Host "===== Deploying Container Instance =====" -ForegroundColor Yellow
97+
azd env set IMAGE_TAG latest
98+
99+
# Use az deployment instead of azd provision to avoid hook recursion
100+
# Pass parameters inline (main.parameters.json uses AZD ${VAR} syntax not supported by az CLI)
101+
Write-Host "Deploying ACI via Bicep..." -ForegroundColor Cyan
102+
103+
az deployment group create `
104+
--resource-group $resourceGroup `
105+
--template-file ./infra/main.bicep `
106+
--parameters solutionName=$env:AZURE_ENV_NAME `
107+
--parameters location=$env:AZURE_LOCATION `
108+
--parameters azureAiServiceLocation=$env:AZURE_ENV_OPENAI_LOCATION `
109+
--parameters imageTag=latest `
110+
--query "properties.outputs" -o json | Out-Null
111+
112+
if ($LASTEXITCODE -eq 0) {
113+
# Refresh azd env with new outputs
114+
azd env refresh --no-prompt 2>$null
115+
Write-Host "Container Instance deployed successfully!" -ForegroundColor Green
116+
} else {
117+
Write-Host "Container Instance deployment failed" -ForegroundColor Red
118+
}
119+
} else {
120+
Write-Host ""
121+
Write-Host "Container Instance: $aciName" -ForegroundColor Cyan
122+
}
123+
124+
Write-Host ""
125+
Write-Host "===== Postprovision Complete - Frontend will deploy next =====" -ForegroundColor Green
126+
127+
# Ensure postprovision exits successfully so frontend deploys
128+
exit 0
129+
interactive: true
130+
continueOnError: false
131+
132+
posix:
133+
shell: sh
134+
run: |
135+
ACR_NAME="$AZURE_CONTAINER_REGISTRY_NAME"
136+
RESOURCE_GROUP="$RESOURCE_GROUP_NAME"
137+
BACKEND_IMAGE="$BACKEND_IMAGE_NAME"
138+
APP_SERVICE="$APP_SERVICE_NAME"
139+
140+
if [ -z "$ACR_NAME" ] || [ -z "$RESOURCE_GROUP" ] || [ -z "$APP_SERVICE" ]; then
141+
echo "ERROR: Missing required environment variables"
142+
exit 1
143+
fi
144+
145+
# Check if ACI already exists (reads from persisted azd env)
146+
ACI_NAME=$(azd env get-value CONTAINER_INSTANCE_NAME 2>/dev/null || echo "")
147+
148+
# ===== Build Backend Image (ACR Build) =====
149+
echo ""
150+
echo "===== Building Backend Image ====="
151+
echo "Registry: $ACR_NAME"
152+
echo "Image: $BACKEND_IMAGE:latest"
153+
154+
if az acr build --registry "$ACR_NAME" --image "$BACKEND_IMAGE:latest" --file ./src/backend/ApiApp.Dockerfile ./src/backend; then
155+
echo "Container image built and pushed successfully!"
156+
else
157+
echo "Failed to build container image"
158+
exit 1
159+
fi
160+
161+
# ===== Deploy ACI if not already deployed =====
162+
if [ -z "$ACI_NAME" ]; then
163+
echo ""
164+
echo "===== Deploying Container Instance ====="
165+
azd env set IMAGE_TAG latest
166+
167+
# Use az deployment instead of azd provision to avoid hook recursion
168+
# Pass parameters inline (main.parameters.json uses AZD ${VAR} syntax not supported by az CLI)
169+
echo "Deploying ACI via Bicep..."
170+
if az deployment group create \
171+
--resource-group "$RESOURCE_GROUP" \
172+
--template-file ./infra/main.bicep \
173+
--parameters solutionName="$AZURE_ENV_NAME" \
174+
--parameters location="$AZURE_LOCATION" \
175+
--parameters azureAiServiceLocation="$AZURE_ENV_OPENAI_LOCATION" \
176+
--parameters imageTag=latest \
177+
--query "properties.outputs" -o json > /dev/null; then
178+
# Refresh azd env with new outputs
179+
azd env refresh --no-prompt 2>/dev/null
180+
echo "Container Instance deployed successfully!"
181+
else
182+
echo "Container Instance deployment failed"
183+
fi
184+
else
185+
echo ""
186+
echo "Container Instance: $ACI_NAME"
187+
fi
188+
189+
echo ""
190+
echo "===== Postprovision Complete - Frontend will deploy next ====="
191+
192+
# Ensure postprovision exits successfully so frontend deploys
193+
exit 0
194+
interactive: true
195+
continueOnError: false
196+
197+
postdeploy:
198+
windows:
199+
shell: pwsh
200+
run: |
201+
Write-Host "===== Running Post-Deploy Script =====" -ForegroundColor Yellow
202+
$python = "python"
203+
if (Test-Path "./.venv/Scripts/python.exe") { $python = "./.venv/Scripts/python.exe" }
204+
& $python -m pip install -r ./scripts/requirements-post-deploy.txt --quiet 2>$null
205+
206+
if (Test-Path "./scripts/post_deploy.py") {
207+
& $python ./scripts/post_deploy.py --skip-tests
208+
if ($LASTEXITCODE -eq 0) {
209+
Write-Host "Post-deploy script completed successfully!" -ForegroundColor Green
210+
} else {
211+
Write-Host "Post-deploy script completed with warnings" -ForegroundColor Yellow
212+
}
213+
}
214+
215+
Write-Host ""
216+
Write-Host "===== Deployment Complete =====" -ForegroundColor Green
217+
Write-Host "Access the web application:" -ForegroundColor White
218+
Write-Host " $env:WEB_APP_URL" -ForegroundColor Cyan
219+
interactive: true
220+
continueOnError: false
221+
222+
posix:
223+
shell: sh
224+
run: |
225+
echo "===== Running Post-Deploy Script ====="
226+
PYTHON="python3"
227+
if [ -f "./.venv/bin/python" ]; then PYTHON="./.venv/bin/python"; fi
228+
$PYTHON -m pip install -r ./scripts/requirements-post-deploy.txt --quiet 2>/dev/null
229+
230+
if [ -f "./scripts/post_deploy.py" ]; then
231+
$PYTHON ./scripts/post_deploy.py --skip-tests \
232+
&& echo "Post-deploy script completed successfully!" \
233+
|| echo "Post-deploy script completed with warnings"
234+
fi
235+
236+
echo ""
237+
echo "===== Deployment Complete ====="
238+
echo "Access the web application:"
239+
echo " $WEB_APP_URL"
240+
interactive: true
241+
continueOnError: false

docs/AZD_DEPLOYMENT.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,39 @@ When `enablePrivateNetworking` is enabled:
309309
└─────────────────────────────────────────────────────────────────┘
310310
```
311311

312+
## Deploy Local Changes
313+
314+
If you've made local modifications to the code and want to deploy them to Azure, follow these steps to swap the configuration files:
315+
316+
> **Note**: To set up and run the application locally for development, see the [Local Development Guide](LocalDevelopmentSetup.md).
317+
318+
### Step 1: Rename Azure Configuration Files
319+
320+
In the root directory:
321+
322+
1. Rename `azure.yaml` to `azure_custom2.yaml`
323+
2. Rename `azure_custom.yaml` to `azure.yaml`
324+
325+
### Step 2: Rename Infrastructure Files
326+
327+
In the `infra` directory:
328+
329+
1. Rename `main.bicep` to `main_custom2.bicep`
330+
2. Rename `main_custom.bicep` to `main.bicep`
331+
332+
### Step 3: Deploy Changes
333+
334+
Run the deployment command:
335+
336+
```bash
337+
azd up
338+
```
339+
340+
> **Note**: These custom files are configured to deploy your local code changes instead of pulling from the GitHub repository.
341+
312342
## Related Documentation
313343

314344
- [Deployment Guide](DEPLOYMENT.md)
345+
- [Local Development Guide](LocalDevelopmentSetup.md)
315346
- [Image Generation Configuration](IMAGE_GENERATION.md)
316347
- [Azure Developer CLI Documentation](https://learn.microsoft.com/azure/developer/azure-developer-cli/)
File renamed without changes.

docs/TECHNICAL_GUIDE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ BRAND_SECONDARY_COLOR=#107C10
179179

180180
## Documentation
181181

182-
- [Local Development Guide](./LOCAL_DEPLOYMENT.md) - Run locally for development
182+
- [Local Development Guide](./LocalDevelopmentSetup.md) - Run locally for development
183183
- [AZD Deployment Guide](./AZD_DEPLOYMENT.md) - Deploy with Azure Developer CLI
184184
- [Manual Deployment Guide](./DEPLOYMENT.md) - Step-by-step manual deployment
185185
- [Image Generation Configuration](./IMAGE_GENERATION.md) - GPT image model setup

0 commit comments

Comments
 (0)