|
1 | | -environment: |
2 | | - name: document-generation |
3 | | - location: eastus |
4 | | - |
5 | | -name: document-generation |
| 1 | +name: content-generation |
6 | 2 | metadata: |
7 | | - template: document-generation@1.0 |
| 3 | + template: content-generation@1.22 |
8 | 4 |
|
9 | 5 | requiredVersions: |
10 | 6 | azd: '>= 1.18.0 != 1.23.9' |
11 | 7 |
|
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 |
22 | 11 |
|
23 | 12 | services: |
24 | | - webapp: |
25 | | - project: ./src |
26 | | - language: py |
| 13 | + frontend: |
| 14 | + project: ./src/app/frontend-server |
| 15 | + language: js |
27 | 16 | host: appservice |
28 | 17 | dist: ./dist |
| 18 | + resourceName: ${APP_SERVICE_NAME} |
29 | 19 | hooks: |
30 | 20 | prepackage: |
31 | 21 | windows: |
32 | 22 | shell: pwsh |
33 | | - run: ../infra/scripts/package_webapp.ps1 |
34 | | - interactive: true |
| 23 | + run: ../../../infra/scripts/package_frontend.ps1 |
35 | 24 | continueOnError: false |
36 | 25 | posix: |
37 | 26 | 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 |
40 | 28 | continueOnError: false |
41 | 29 |
|
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 |
0 commit comments