Skip to content

Commit ff09a28

Browse files
feat: Add support for developer experience (#762)
* custom templates for developer experience * updated azure_custom.yaml * updated readme * updated template name * updated keyvault prefix to lower case * changes suggested by copilot * main.json * updated the approach * updated main_custom.bicep * added comment
1 parent 059dfa7 commit ff09a28

File tree

4 files changed

+676
-535
lines changed

4 files changed

+676
-535
lines changed

azure_custom.yaml

Lines changed: 23 additions & 312 deletions
Original file line numberDiff line numberDiff line change
@@ -9,319 +9,30 @@ metadata:
99
1010
1111

12-
hooks:
13-
# Pre-package hook to set container registry variables
14-
prepackage:
15-
windows:
16-
run: |
17-
Write-Host "Setting up container registry variables..." -ForegroundColor Green
18-
19-
# Get the ACR name from the deployed infrastructure
20-
$acrName = azd env get-values --output json | ConvertFrom-Json | Select-Object -ExpandProperty "AZURE_CONTAINER_REGISTRY_NAME" -ErrorAction SilentlyContinue
21-
22-
if ($acrName) {
23-
Write-Host "Using deployed ACR: $acrName" -ForegroundColor Cyan
24-
azd env set AZURE_CONTAINER_REGISTRY_ENDPOINT "$acrName.azurecr.io"
25-
azd env set AZURE_CONTAINER_REGISTRY_NAME $acrName
26-
} else {
27-
Write-Host "Warning: ACR not found in environment. Make sure infrastructure is deployed first." -ForegroundColor Yellow
28-
}
29-
shell: pwsh
30-
continueOnError: true
31-
32-
posix:
33-
run: |
34-
echo "Setting up container registry variables..."
35-
36-
# Get the ACR name from the deployed infrastructure
37-
ACR_NAME=$(azd env get-values --output json | jq -r '.AZURE_CONTAINER_REGISTRY_NAME // empty')
38-
39-
if [ ! -z "$ACR_NAME" ]; then
40-
echo "Using deployed ACR: $ACR_NAME"
41-
azd env set AZURE_CONTAINER_REGISTRY_ENDPOINT "$ACR_NAME.azurecr.io"
42-
azd env set AZURE_CONTAINER_REGISTRY_NAME "$ACR_NAME"
43-
else
44-
echo "Warning: ACR not found in environment. Make sure infrastructure is deployed first."
45-
fi
46-
shell: sh
47-
continueOnError: true
48-
49-
# Pre-deploy hook to build and push containers
50-
predeploy:
51-
windows:
52-
run: |
53-
Write-Host "🚀 Starting container deployment process..." -ForegroundColor Green
54-
55-
# Get environment variables from azd
56-
$acrName = azd env get-value AZURE_CONTAINER_REGISTRY_NAME
57-
$resourceGroup = azd env get-value AZURE_RESOURCE_GROUP
58-
$webAppName = azd env get-value WEB_APP_NAME
59-
$imageName = "byc-wa-app"
60-
$imageTag = "latest"
61-
62-
if (-not $acrName) {
63-
Write-Host "❌ Error: AZURE_CONTAINER_REGISTRY_NAME not set. Run 'azd provision' first." -ForegroundColor Red
64-
exit 1
65-
}
66-
67-
if (-not $resourceGroup) {
68-
Write-Host "❌ Error: AZURE_RESOURCE_GROUP not set. Run 'azd provision' first." -ForegroundColor Red
69-
exit 1
70-
}
71-
72-
if (-not $webAppName) {
73-
Write-Host "❌ Error: WEB_APP_NAME not set. Run 'azd provision' first." -ForegroundColor Red
74-
exit 1
75-
}
76-
77-
Write-Host "📋 Configuration:" -ForegroundColor Cyan
78-
Write-Host " ACR Name: $acrName" -ForegroundColor White
79-
Write-Host " Resource Group: $resourceGroup" -ForegroundColor White
80-
Write-Host " Web App: $webAppName" -ForegroundColor White
81-
Write-Host " Image: $imageName`:$imageTag" -ForegroundColor White
82-
83-
# Login to ACR
84-
Write-Host "🔐 Logging into ACR..." -ForegroundColor Yellow
85-
az acr login --name $acrName
86-
87-
if ($LASTEXITCODE -ne 0) {
88-
Write-Host "❌ Failed to login to ACR" -ForegroundColor Red
89-
exit 1
90-
}
91-
92-
# Build and push the container image
93-
Write-Host "🏗️ Building container image..." -ForegroundColor Yellow
94-
$fullImageName = "$acrName.azurecr.io/$imageName`:$imageTag"
95-
docker build -f "./src/App/WebApp.Dockerfile" -t $fullImageName "./src"
96-
97-
if ($LASTEXITCODE -ne 0) {
98-
Write-Host "❌ Failed to build container image" -ForegroundColor Red
99-
exit 1
100-
}
101-
102-
Write-Host "📤 Pushing container image to ACR..." -ForegroundColor Yellow
103-
docker push $fullImageName
104-
105-
if ($LASTEXITCODE -ne 0) {
106-
Write-Host "❌ Failed to push container image" -ForegroundColor Red
107-
exit 1
108-
}
109-
110-
# Update environment variables
111-
Write-Host "🔧 Updating azd environment variables..." -ForegroundColor Yellow
112-
azd env set CONTAINER_REGISTRY_HOSTNAME "$acrName.azurecr.io"
113-
azd env set CONTAINER_IMAGE_NAME $imageName
114-
azd env set IMAGE_TAG $imageTag
115-
116-
# Configure web app ACR authentication using managed identity
117-
Write-Host "🔑 Configuring ACR authentication for web app..." -ForegroundColor Yellow
118-
$webappIdentity = az webapp identity show --name $webAppName --resource-group $resourceGroup --query principalId --output tsv
119-
120-
if (-not $webappIdentity -or $webappIdentity -eq "null") {
121-
Write-Host "🔄 Enabling managed identity for web app..." -ForegroundColor Yellow
122-
$webappIdentity = az webapp identity assign --name $webAppName --resource-group $resourceGroup --query principalId --output tsv
123-
}
124-
125-
Write-Host " Web app identity: $webappIdentity" -ForegroundColor White
126-
127-
# Assign AcrPull role to web app managed identity
128-
Write-Host "🔐 Assigning AcrPull role to web app..." -ForegroundColor Yellow
129-
$acrResourceId = az acr show --name $acrName --resource-group $resourceGroup --query id --output tsv
130-
az role assignment create --assignee $webappIdentity --role AcrPull --scope $acrResourceId
131-
if ($LASTEXITCODE -ne 0) {
132-
Write-Host "⚠️ Role assignment may already exist" -ForegroundColor Yellow
133-
}
134-
135-
# Configure web app to use ACR with managed identity
136-
Write-Host "🔧 Configuring web app container settings..." -ForegroundColor Yellow
137-
az webapp config appsettings set --name $webAppName --resource-group $resourceGroup --settings `
138-
DOCKER_REGISTRY_SERVER_URL="https://$acrName.azurecr.io" `
139-
DOCKER_ENABLE_CI=true
140-
141-
# Configure web app to use managed identity for ACR authentication
142-
Write-Host "🔐 Enabling ACR managed identity authentication..." -ForegroundColor Yellow
143-
az webapp config set --name $webAppName --resource-group $resourceGroup --acr-use-identity true
144-
145-
# Update web app to use the new container image
146-
Write-Host "🚀 Updating web app container image..." -ForegroundColor Yellow
147-
$dockerImage = "DOCKER|$fullImageName"
148-
149-
# Use cmd to avoid PowerShell pipe interpretation issues
150-
$cmd = "az webapp config set --name `"$webAppName`" --resource-group `"$resourceGroup`" --linux-fx-version `"$dockerImage`""
151-
cmd /c $cmd
152-
153-
if ($LASTEXITCODE -ne 0) {
154-
Write-Host "❌ Failed to update web app configuration" -ForegroundColor Red
155-
exit 1
156-
}
157-
158-
# Restart the web app to ensure it picks up the new configuration
159-
Write-Host "🔄 Restarting web app..." -ForegroundColor Yellow
160-
az webapp restart --name $webAppName --resource-group $resourceGroup
161-
162-
Write-Host "✅ Container deployment completed successfully!" -ForegroundColor Green
163-
Write-Host "🌐 Web app URL: https://$webAppName.azurewebsites.net" -ForegroundColor Cyan
164-
Write-Host "📦 Container image: $fullImageName" -ForegroundColor Cyan
165-
166-
Write-Host ""
167-
Write-Host "⏳ The web app may take a few minutes to start up with the new container..." -ForegroundColor Yellow
168-
Write-Host " You can monitor the logs with:" -ForegroundColor White
169-
Write-Host " az webapp log tail --name $webAppName --resource-group $resourceGroup" -ForegroundColor Cyan
170-
shell: pwsh
171-
continueOnError: false
172-
173-
posix:
174-
run: |
175-
echo "🚀 Starting container deployment process..."
176-
177-
# Get environment variables from azd
178-
ACR_NAME=$(azd env get-value AZURE_CONTAINER_REGISTRY_NAME)
179-
RESOURCE_GROUP=$(azd env get-value AZURE_RESOURCE_GROUP)
180-
WEB_APP_NAME=$(azd env get-value WEB_APP_NAME)
181-
IMAGE_TAG="latest"
182-
IMAGE_NAME="byc-wa-app"
183-
184-
if [ -z "$ACR_NAME" ]; then
185-
echo "❌ Error: AZURE_CONTAINER_REGISTRY_NAME not set. Run 'azd provision' first."
186-
exit 1
187-
fi
188-
189-
if [ -z "$RESOURCE_GROUP" ]; then
190-
echo "❌ Error: AZURE_RESOURCE_GROUP not set. Run 'azd provision' first."
191-
exit 1
192-
fi
193-
194-
if [ -z "$WEB_APP_NAME" ]; then
195-
echo "❌ Error: WEB_APP_NAME not set. Run 'azd provision' first."
196-
exit 1
197-
fi
198-
199-
echo "📋 Configuration:"
200-
echo " ACR Name: $ACR_NAME"
201-
echo " Resource Group: $RESOURCE_GROUP"
202-
echo " Web App: $WEB_APP_NAME"
203-
echo " Image: $IMAGE_NAME:$IMAGE_TAG"
204-
205-
# Login to ACR
206-
echo "🔐 Logging into ACR..."
207-
az acr login --name $ACR_NAME
208-
209-
# Build and push the container image
210-
echo "🏗️ Building container image..."
211-
FULL_IMAGE_NAME="$ACR_NAME.azurecr.io/$IMAGE_NAME:$IMAGE_TAG"
212-
docker build -f "./src/App/WebApp.Dockerfile" -t $FULL_IMAGE_NAME "./src"
213-
214-
echo "📤 Pushing container image to ACR..."
215-
docker push $FULL_IMAGE_NAME
216-
217-
# Update environment variables
218-
echo "🔧 Updating azd environment variables..."
219-
azd env set CONTAINER_REGISTRY_HOSTNAME "$ACR_NAME.azurecr.io"
220-
azd env set CONTAINER_IMAGE_NAME $IMAGE_NAME
221-
azd env set IMAGE_TAG $IMAGE_TAG
222-
223-
# Configure web app ACR authentication using managed identity
224-
echo "🔑 Configuring ACR authentication for web app..."
225-
WEBAPP_IDENTITY=$(az webapp identity show --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP --query principalId --output tsv)
226-
227-
if [ -z "$WEBAPP_IDENTITY" ] || [ "$WEBAPP_IDENTITY" = "null" ]; then
228-
echo "🔄 Enabling managed identity for web app..."
229-
WEBAPP_IDENTITY=$(az webapp identity assign --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP --query principalId --output tsv)
230-
fi
231-
232-
echo " Web app identity: $WEBAPP_IDENTITY"
233-
234-
# Assign AcrPull role to web app managed identity
235-
echo "🔐 Assigning AcrPull role to web app..."
236-
ACR_RESOURCE_ID=$(az acr show --name $ACR_NAME --resource-group $RESOURCE_GROUP --query id --output tsv)
237-
az role assignment create --assignee $WEBAPP_IDENTITY --role AcrPull --scope $ACR_RESOURCE_ID || echo "⚠️ Role assignment may already exist"
238-
239-
# Configure web app to use ACR with managed identity
240-
echo "🔧 Configuring web app container settings..."
241-
az webapp config appsettings set --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP --settings \
242-
DOCKER_REGISTRY_SERVER_URL="https://$ACR_NAME.azurecr.io" \
243-
DOCKER_ENABLE_CI=true
244-
245-
# Configure web app to use managed identity for ACR authentication
246-
echo "🔐 Enabling ACR managed identity authentication..."
247-
az webapp config set --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP --acr-use-identity true
248-
249-
# Update web app to use the new container image
250-
echo "🚀 Updating web app container image..."
251-
DOCKER_IMAGE="DOCKER|$FULL_IMAGE_NAME"
252-
az webapp config set --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP --linux-fx-version "$DOCKER_IMAGE"
253-
254-
# Restart the web app to ensure it picks up the new configuration
255-
echo "🔄 Restarting web app..."
256-
az webapp restart --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP
257-
258-
echo "✅ Container deployment completed successfully!"
259-
echo "🌐 Web app URL: https://$WEB_APP_NAME.azurewebsites.net"
260-
echo "📦 Container image: $FULL_IMAGE_NAME"
261-
262-
echo ""
263-
echo "⏳ The web app may take a few minutes to start up with the new container..."
264-
echo " You can monitor the logs with:"
265-
echo " az webapp log tail --name $WEB_APP_NAME --resource-group $RESOURCE_GROUP"
266-
shell: sh
267-
continueOnError: false
268-
269-
postprovision:
270-
windows:
271-
run: |
272-
Write-Host "Deployment completed successfully!" -ForegroundColor Green
273-
Write-Host "Web app URL: " -NoNewline
274-
Write-Host "$env:WEB_APP_URL" -ForegroundColor Cyan
275-
Write-Host ""
276-
Write-Host "Container Registry: " -NoNewline
277-
Write-Host "$env:AZURE_CONTAINER_REGISTRY_NAME.azurecr.io" -ForegroundColor Cyan
278-
Write-Host ""
279-
Write-Host "Next step:" -ForegroundColor Yellow
280-
Write-Host " Run the following command to grant permissions and load sample data:" -ForegroundColor White
281-
Write-Host " bash ./infra/scripts/process_sample_data.sh $env:AZURE_RESOURCE_GROUP" -ForegroundColor Cyan
282-
Write-Host ""
283-
shell: pwsh
284-
continueOnError: false
285-
interactive: true
286-
287-
posix:
288-
run: |
289-
echo "Deployment completed successfully!"
290-
echo "Web app URL: $WEB_APP_URL"
291-
echo ""
292-
echo "Container Registry: $AZURE_CONTAINER_REGISTRY_NAME.azurecr.io"
293-
echo ""
294-
echo "Next step:"
295-
echo " Run the following command to grant permissions and load sample data:"
296-
echo " bash ./infra/scripts/process_sample_data.sh $AZURE_RESOURCE_GROUP"
297-
echo ""
298-
shell: sh
299-
continueOnError: false
300-
interactive: true
301-
302-
postdeploy:
303-
windows:
304-
run: |
305-
Write-Host "✅ Deployment completed! Container deployment was handled by predeploy hook." -ForegroundColor Green
306-
$webAppUrl = azd env get-value WEB_APP_URL
307-
Write-Host "🌐 Web app URL: $webAppUrl" -ForegroundColor Cyan
308-
shell: pwsh
309-
continueOnError: true
310-
311-
posix:
312-
run: |
313-
echo "✅ Deployment completed! Container deployment was handled by predeploy hook."
314-
WEB_APP_URL=$(azd env get-value WEB_APP_URL)
315-
echo "🌐 Web app URL: $WEB_APP_URL"
316-
shell: sh
317-
continueOnError: true
318-
31912
# Infrastructure configuration
32013
infra:
321-
provider: bicep
322-
path: infra
14+
path: ./infra
32315
module: main
32416
parameters:
325-
containerRegistryHostname: ${CONTAINER_REGISTRY_HOSTNAME=""}
326-
containerImageName: ${CONTAINER_IMAGE_NAME="byc-wa-app"}
327-
imageTag: ${IMAGE_TAG="latest"}
17+
solutionName: bs-azdtest
18+
cosmosLocation: eastus2
19+
baseUrl: 'https://github.com/microsoft/Build-your-own-copilot-Solution-Accelerator'
20+
21+
services:
22+
webapp:
23+
project: ./src/App
24+
language: py
25+
host: appservice
26+
dist: ./dist
27+
hooks:
28+
prepackage:
29+
windows:
30+
shell: pwsh
31+
run: ../../infra/scripts/package_webapp.ps1
32+
interactive: true
33+
continueOnError: false
34+
posix:
35+
shell: sh
36+
run: bash ../../infra/scripts/package_webapp.sh
37+
interactive: true
38+
continueOnError: false

0 commit comments

Comments
 (0)