Skip to content

Commit 48fb8d6

Browse files
updated the infra code
1 parent 4c7cf14 commit 48fb8d6

4 files changed

Lines changed: 276 additions & 289 deletions

File tree

content-gen/azure.yaml

Lines changed: 166 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ environment:
22
name: content-generation
33
location: eastus
44

5-
name: content-generation
6-
metadata:
7-
template: content-generation@1.22
5+
# name: content-generation
6+
# metadata:
7+
# template: content-generation@1.22
88

99
requiredVersions:
1010
azd: '>= 1.18.0'
@@ -65,6 +65,10 @@ hooks:
6565
6666
# For private networking on first run, skip ACI (image not yet in ACR)
6767
$currentSkip = azd env get-value skipContainerDeployment 2>$null
68+
if (-not $?) {
69+
$currentSkip = ""
70+
$global:LASTEXITCODE = 0
71+
}
6872
if ($env:enablePrivateNetworking -eq 'true' -and -not $env:ACR_NAME -and $currentSkip -ne 'false') {
6973
Write-Host "Private networking enabled - skipping container deployment until image is built" -ForegroundColor Yellow
7074
azd env set skipContainerDeployment true
@@ -116,81 +120,97 @@ hooks:
116120
Write-Host " Cosmos DB role may already be assigned" -ForegroundColor Yellow
117121
}
118122
119-
# Build container image and deploy ACI if ACR exists and ACI was skipped
120-
$skipContainer = azd env get-value skipContainerDeployment 2>$null
121-
if ($env:ACR_NAME -and $skipContainer -eq 'true') {
122-
Write-Host ""
123-
Write-Host "===== Building Container Image =====" -ForegroundColor Yellow
124-
Write-Host "Building and pushing image to ACR: $env:ACR_NAME" -ForegroundColor Cyan
125-
126-
az acr build --registry $env:ACR_NAME --image content-gen-app:latest --file ./src/WebApp.Dockerfile ./src
127-
128-
if ($LASTEXITCODE -eq 0) {
129-
Write-Host "Container image built and pushed successfully!" -ForegroundColor Green
130-
131-
# Enable container deployment and re-provision
132-
Write-Host ""
133-
Write-Host "===== Deploying Container Instance =====" -ForegroundColor Yellow
134-
azd env set skipContainerDeployment false
135-
136-
Write-Host "Re-running provision to deploy ACI..." -ForegroundColor Cyan
137-
azd provision --no-prompt
138-
139-
if ($LASTEXITCODE -eq 0) {
140-
Write-Host "Container Instance deployed successfully!" -ForegroundColor Green
141-
} else {
142-
Write-Host "Container Instance deployment failed" -ForegroundColor Red
143-
}
144-
} else {
145-
Write-Host "Failed to build container image" -ForegroundColor Red
146-
}
147-
} elseif ($env:CONTAINER_INSTANCE_NAME) {
123+
# ============================================================
124+
# ACR Image Build - COMMENTED OUT
125+
# Images should be pre-built and pushed to ACR before deployment:
126+
# Frontend (App Service): content-gen-webapp:latest
127+
# Backend (ACI): content-gen-api:latest
128+
#
129+
# To build and push manually:
130+
# az acr build --registry $ACR_NAME --image content-gen-webapp:latest --file ./src/Frontend.Dockerfile ./src
131+
# az acr build --registry $ACR_NAME --image content-gen-api:latest --file ./src/backend/ApiApp.Dockerfile ./src
132+
# ============================================================
133+
134+
# # Build container image and deploy ACI if ACR exists and ACI was skipped
135+
# $skipContainer = azd env get-value skipContainerDeployment 2>$null
136+
# if ($env:ACR_NAME -and $skipContainer -eq 'true') {
137+
# Write-Host ""
138+
# Write-Host "===== Building Container Image =====" -ForegroundColor Yellow
139+
# Write-Host "Building and pushing image to ACR: $env:ACR_NAME" -ForegroundColor Cyan
140+
#
141+
# az acr build --registry $env:ACR_NAME --image content-gen-api:latest --file ./src/backend/ApiApp.Dockerfile ./src
142+
#
143+
# if ($LASTEXITCODE -eq 0) {
144+
# Write-Host "Container image built and pushed successfully!" -ForegroundColor Green
145+
#
146+
# # Enable container deployment and re-provision
147+
# Write-Host ""
148+
# Write-Host "===== Deploying Container Instance =====" -ForegroundColor Yellow
149+
# azd env set skipContainerDeployment false
150+
#
151+
# Write-Host "Re-running provision to deploy ACI..." -ForegroundColor Cyan
152+
# azd provision --no-prompt
153+
#
154+
# if ($LASTEXITCODE -eq 0) {
155+
# Write-Host "Container Instance deployed successfully!" -ForegroundColor Green
156+
# } else {
157+
# Write-Host "Container Instance deployment failed" -ForegroundColor Red
158+
# }
159+
# } else {
160+
# Write-Host "Failed to build container image" -ForegroundColor Red
161+
# }
162+
# }
163+
164+
if ($env:CONTAINER_INSTANCE_NAME) {
148165
Write-Host ""
149166
Write-Host "Container Instance: " -NoNewline
150167
Write-Host "$env:CONTAINER_INSTANCE_NAME" -ForegroundColor Cyan
151168
Write-Host "Container Private IP: " -NoNewline
152169
Write-Host "$env:CONTAINER_INSTANCE_PRIVATE_IP" -ForegroundColor Cyan
153-
} elseif ($env:ACR_NAME) {
154-
Write-Host ""
155-
Write-Host "Container Registry: " -NoNewline
156-
Write-Host "$env:ACR_NAME" -ForegroundColor Cyan
157170
}
158171
159-
# Build and deploy frontend to App Service
160172
Write-Host ""
161-
Write-Host "===== Building Frontend =====" -ForegroundColor Yellow
162-
Push-Location ./src/frontend
163-
npm install
164-
npm run build
173+
Write-Host "Container Registry: " -NoNewline
174+
Write-Host "$env:ACR_NAME" -ForegroundColor Cyan
165175
166-
if ($LASTEXITCODE -eq 0) {
167-
Write-Host "Frontend build completed!" -ForegroundColor Green
168-
169-
# Copy build to frontend-server
170-
Copy-Item -Path ../static/* -Destination ../frontend-server/static/ -Recurse -Force -ErrorAction SilentlyContinue
171-
172-
Push-Location ../frontend-server
173-
174-
# Create deployment package
175-
Write-Host "Creating deployment package..."
176-
Remove-Item -Path frontend-deploy.zip -Force -ErrorAction SilentlyContinue
177-
Compress-Archive -Path static, server.js, package.json, package-lock.json -DestinationPath frontend-deploy.zip -Force
178-
179-
Write-Host ""
180-
Write-Host "===== Deploying Frontend to App Service =====" -ForegroundColor Yellow
181-
az webapp deploy --resource-group $env:RESOURCE_GROUP_NAME --name $env:APP_SERVICE_NAME --src-path frontend-deploy.zip --type zip
182-
183-
if ($LASTEXITCODE -eq 0) {
184-
Write-Host "Frontend deployed successfully!" -ForegroundColor Green
185-
} else {
186-
Write-Host "Frontend deployment failed" -ForegroundColor Red
187-
}
188-
189-
Pop-Location
190-
} else {
191-
Write-Host "Frontend build failed" -ForegroundColor Red
192-
}
193-
Pop-Location
176+
# ============================================================
177+
# Frontend Build/Deploy - COMMENTED OUT (using pre-built ACR image)
178+
# ============================================================
179+
# # Build and deploy frontend to App Service
180+
# Write-Host ""
181+
# Write-Host "===== Building Frontend =====" -ForegroundColor Yellow
182+
# Push-Location ./src/frontend
183+
# npm install
184+
# npm run build
185+
#
186+
# if ($LASTEXITCODE -eq 0) {
187+
# Write-Host "Frontend build completed!" -ForegroundColor Green
188+
#
189+
# # Copy build to frontend-server
190+
# Copy-Item -Path ../static/* -Destination ../frontend-server/static/ -Recurse -Force -ErrorAction SilentlyContinue
191+
#
192+
# Push-Location ../frontend-server
193+
#
194+
# # Create deployment package
195+
# Write-Host "Creating deployment package..."
196+
# Remove-Item -Path frontend-deploy.zip -Force -ErrorAction SilentlyContinue
197+
# Compress-Archive -Path static, server.js, package.json, package-lock.json -DestinationPath frontend-deploy.zip -Force
198+
#
199+
# Write-Host ""
200+
# Write-Host "===== Deploying Frontend to App Service =====" -ForegroundColor Yellow
201+
# az webapp deploy --resource-group $env:RESOURCE_GROUP_NAME --name $env:APP_SERVICE_NAME --src-path frontend-deploy.zip --type zip
202+
#
203+
# if ($LASTEXITCODE -eq 0) {
204+
# Write-Host "Frontend deployed successfully!" -ForegroundColor Green
205+
# } else {
206+
# Write-Host "Frontend deployment failed" -ForegroundColor Red
207+
# }
208+
#
209+
# Pop-Location
210+
# } else {
211+
# Write-Host "Frontend build failed" -ForegroundColor Red
212+
# }
213+
# Pop-Location
194214
195215
# Run post-deploy script to upload sample data and create search index
196216
Write-Host ""
@@ -252,73 +272,89 @@ hooks:
252272
--principal-id "$signed_user_id" \
253273
--scope "/" 2>/dev/null && echo " Cosmos DB role assigned successfully" || echo " Cosmos DB role may already be assigned"
254274
255-
# Build container image and deploy ACI if ACR exists and ACI was skipped
256-
skip_container=$(azd env get-value skipContainerDeployment 2>/dev/null || echo "")
257-
if [ -n "$ACR_NAME" ] && [ "$skip_container" = "true" ]; then
258-
echo ""
259-
echo "===== Building Container Image ====="
260-
echo "Building and pushing image to ACR: $ACR_NAME"
261-
262-
if az acr build --registry "$ACR_NAME" --image content-gen-app:latest --file ./src/WebApp.Dockerfile ./src; then
263-
echo "Container image built and pushed successfully!"
264-
265-
# Enable container deployment and re-provision
266-
echo ""
267-
echo "===== Deploying Container Instance ====="
268-
azd env set skipContainerDeployment false
269-
270-
echo "Re-running provision to deploy ACI..."
271-
if azd provision --no-prompt; then
272-
echo "Container Instance deployed successfully!"
273-
else
274-
echo "Container Instance deployment failed"
275-
fi
276-
else
277-
echo "Failed to build container image"
278-
fi
279-
elif [ -n "$CONTAINER_INSTANCE_NAME" ]; then
275+
# ============================================================
276+
# ACR Image Build - COMMENTED OUT
277+
# Images should be pre-built and pushed to ACR before deployment:
278+
# Frontend (App Service): content-gen-webapp:latest
279+
# Backend (ACI): content-gen-api:latest
280+
#
281+
# To build and push manually:
282+
# az acr build --registry $ACR_NAME --image content-gen-webapp:latest --file ./src/Frontend.Dockerfile ./src
283+
# az acr build --registry $ACR_NAME --image content-gen-api:latest --file ./src/backend/ApiApp.Dockerfile ./src
284+
# ============================================================
285+
286+
# # Build container image and deploy ACI if ACR exists and ACI was skipped
287+
# skip_container=$(azd env get-value skipContainerDeployment 2>/dev/null || echo "")
288+
# if [ -n "$ACR_NAME" ] && [ "$skip_container" = "true" ]; then
289+
# echo ""
290+
# echo "===== Building Container Image ====="
291+
# echo "Building and pushing image to ACR: $ACR_NAME"
292+
#
293+
# if az acr build --registry "$ACR_NAME" --image content-gen-api:latest --file ./src/backend/ApiApp.Dockerfile ./src; then
294+
# echo "Container image built and pushed successfully!"
295+
#
296+
# # Enable container deployment and re-provision
297+
# echo ""
298+
# echo "===== Deploying Container Instance ====="
299+
# azd env set skipContainerDeployment false
300+
#
301+
# echo "Re-running provision to deploy ACI..."
302+
# if azd provision --no-prompt; then
303+
# echo "Container Instance deployed successfully!"
304+
# else
305+
# echo "Container Instance deployment failed"
306+
# fi
307+
# else
308+
# echo "Failed to build container image"
309+
# fi
310+
# fi
311+
312+
if [ -n "$CONTAINER_INSTANCE_NAME" ]; then
280313
echo ""
281314
echo "Container Instance: $CONTAINER_INSTANCE_NAME"
282315
echo "Container Private IP: $CONTAINER_INSTANCE_PRIVATE_IP"
283-
elif [ -n "$ACR_NAME" ]; then
284-
echo ""
285-
echo "Container Registry: $ACR_NAME"
286316
fi
287317
288-
# Build and deploy frontend to App Service
289318
echo ""
290-
echo "===== Building Frontend ====="
291-
cd ./src/frontend
292-
if npm install && npm run build; then
293-
echo "Frontend build completed!"
294-
295-
# Copy build to frontend-server
296-
cp -r ../static/* ../frontend-server/static/ 2>/dev/null || true
297-
298-
cd ../frontend-server
299-
300-
# Create deployment package
301-
echo "Creating deployment package..."
302-
rm -f frontend-deploy.zip
303-
zip -r frontend-deploy.zip static/ server.js package.json package-lock.json
304-
305-
echo ""
306-
echo "===== Deploying Frontend to App Service ====="
307-
if az webapp deploy \
308-
--resource-group "$RESOURCE_GROUP_NAME" \
309-
--name "$APP_SERVICE_NAME" \
310-
--src-path frontend-deploy.zip \
311-
--type zip; then
312-
echo "Frontend deployed successfully!"
313-
else
314-
echo "Frontend deployment failed"
315-
fi
316-
317-
cd ../..
318-
else
319-
echo "Frontend build failed"
320-
cd ../..
321-
fi
319+
echo "Container Registry: $ACR_NAME"
320+
321+
# ============================================================
322+
# Frontend Build/Deploy - COMMENTED OUT (using pre-built ACR image)
323+
# ============================================================
324+
# # Build and deploy frontend to App Service
325+
# echo ""
326+
# echo "===== Building Frontend ====="
327+
# cd ./src/frontend
328+
# if npm install && npm run build; then
329+
# echo "Frontend build completed!"
330+
#
331+
# # Copy build to frontend-server
332+
# cp -r ../static/* ../frontend-server/static/ 2>/dev/null || true
333+
#
334+
# cd ../frontend-server
335+
#
336+
# # Create deployment package
337+
# echo "Creating deployment package..."
338+
# rm -f frontend-deploy.zip
339+
# zip -r frontend-deploy.zip static/ server.js package.json package-lock.json
340+
#
341+
# echo ""
342+
# echo "===== Deploying Frontend to App Service ====="
343+
# if az webapp deploy \
344+
# --resource-group "$RESOURCE_GROUP_NAME" \
345+
# --name "$APP_SERVICE_NAME" \
346+
# --src-path frontend-deploy.zip \
347+
# --type zip; then
348+
# echo "Frontend deployed successfully!"
349+
# else
350+
# echo "Frontend deployment failed"
351+
# fi
352+
#
353+
# cd ../..
354+
# else
355+
# echo "Frontend build failed"
356+
# cd ../..
357+
# fi
322358
323359
# Run post-deploy script to upload sample data and create search index
324360
echo ""

0 commit comments

Comments
 (0)