Skip to content

Commit 1b7ba07

Browse files
authored
Merge pull request #233 from Azure-Samples/azd_fixes
fix: infra fixes for terraform and bicep
2 parents d5b0130 + 918b353 commit 1b7ba07

28 files changed

Lines changed: 739 additions & 370 deletions

.github/workflows/test-e2e-main.yaml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,19 @@ jobs:
5151
- name: Turn on Helm support for azd
5252
run: azd config set alpha.aks.helm on
5353

54+
- name: Swap azd config files to build from source
55+
run: |
56+
mv azure.yaml azure.yaml.bak
57+
mv azure-build-from-source.yaml azure.yaml
58+
5459
- name: Provision and deploy
5560
id: provision_deploy
5661
continue-on-error: true
5762
run: |
5863
azd env new ${{ vars.AZURE_ENV_NAME }}
59-
azd env set AKS_NODE_POOL_VM_SIZE Standard_D2_v4
60-
azd env set BUILD_CONTAINERS false
6164
azd env set DEPLOY_AZURE_CONTAINER_REGISTRY true
6265
azd env set DEPLOY_AZURE_OPENAI true
6366
azd env set AZURE_OPENAI_LOCATION ${{ vars.AZURE_LOCATION }}
64-
azd env set DEPLOY_AZURE_OPENAI_DALL_E_MODEL false
6567
azd env set DEPLOY_AZURE_SERVICE_BUS true
6668
azd env set DEPLOY_AZURE_COSMOSDB true
6769
azd env set AZURE_COSMOSDB_ACCOUNT_KIND MongoDB

azd-hooks/postdeploy.ps1

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env pwsh
2+
3+
############################################
4+
# Delete custom-values.yaml
5+
############################################
6+
Remove-Item -Path custom-values.yaml -ErrorAction SilentlyContinue

azd-hooks/postdeploy.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/bash
2+
3+
############################################
4+
# Delete custom-values.yaml
5+
############################################
6+
rm custom-values.yaml

azd-hooks/postprovision.ps1

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env pwsh
2+
3+
$services=@("ai-service", "makeline-service", "order-service", "product-service", "store-admin", "store-front", "virtual-customer", "virtual-worker")
4+
5+
if (($env:DEPLOY_AZURE_CONTAINER_REGISTRY -like "true") -and ($env:BUILD_CONTAINERS -like "true")) {
6+
echo "Build container images"
7+
foreach ($service in $services) {
8+
echo "Building aks-store-demo/${service}:latest"
9+
az acr build --registry $env:AZURE_CONTAINER_REGISTRY_NAME --image aks-store-demo/${service}:latest ./src/${service}/
10+
}
11+
}
12+
elseif (($env:DEPLOY_AZURE_CONTAINER_REGISTRY -like "true") -and ((-not $env:BUILD_CONTAINERS) -or ($env:BUILD_CONTAINERS -like "false"))) {
13+
echo "Import container images"
14+
foreach ($service in $services) {
15+
echo "Importing aks-store-demo/${service}:latest"
16+
az acr import --name $env:AZURE_CONTAINER_REGISTRY_NAME --source ghcr.io/azure-samples/aks-store-demo/${service}:latest --image aks-store-demo/${service}:latest
17+
}
18+
}
19+
else {
20+
echo "No BUILD_CONTAINERS variable set, skipping container build/import"
21+
}
22+

azd-hooks/postprovision.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
services=("ai-service" "makeline-service" "order-service" "product-service" "store-admin" "store-front" "virtual-customer" "virtual-worker")
4+
5+
if [ "$DEPLOY_AZURE_CONTAINER_REGISTRY" == "true" ] && [ "$BUILD_CONTAINERS" == "true" ]; then
6+
echo "Build container images"
7+
for service in "${services[@]}"; do
8+
echo "Building aks-store-demo/${service}:latest"
9+
az acr build --registry ${AZURE_CONTAINER_REGISTRY_NAME} --image aks-store-demo/${service}:latest ./src/${service}/
10+
done
11+
elif [ "$DEPLOY_AZURE_CONTAINER_REGISTRY" == "true" ] && ([ -z "$BUILD_CONTAINERS" ] || [ "$BUILD_CONTAINERS" == "false" ]); then
12+
echo "Import container images"
13+
for service in "${services[@]}"; do
14+
echo "Importing aks-store-demo/${service}:latest"
15+
az acr import --name ${AZURE_CONTAINER_REGISTRY_NAME} --source ghcr.io/azure-samples/aks-store-demo/${service}:latest --image aks-store-demo/${service}:latest
16+
done
17+
else
18+
echo "No BUILD_CONTAINERS variable set, skipping container build/import"
19+
fi

azd-hooks/predeploy.ps1

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
#!/usr/bin/env pwsh
2+
3+
##########################################################
4+
# Ensure Helm and Kustomize support is enabled
5+
##########################################################
6+
azd config set alpha.aks.helm on
7+
azd config set alpha.aks.kustomize on
8+
9+
##########################################################
10+
# Check kubelogin and install if not exists
11+
##########################################################
12+
if (-not (Get-Command kubelogin -ErrorAction SilentlyContinue)) {
13+
az aks install-cli
14+
}
15+
16+
###########################################################
17+
# Create the custom-values.yaml file
18+
###########################################################
19+
@"
20+
namespace: ${env:AZURE_AKS_NAMESPACE}
21+
"@ | Out-File -FilePath custom-values.yaml -Encoding utf8
22+
23+
###########################################################
24+
# Add Azure Managed Identity and set to use AzureAD auth
25+
###########################################################
26+
if (![string]::IsNullOrEmpty($env:AZURE_IDENTITY_CLIENT_ID) -and ![string]::IsNullOrEmpty($env:AZURE_IDENTITY_NAME)) {
27+
@"
28+
useAzureAd: true
29+
managedIdentityName: $($env:AZURE_IDENTITY_NAME)
30+
managedIdentityClientId: $($env:AZURE_IDENTITY_CLIENT_ID)
31+
"@ | Out-File -FilePath custom-values.yaml -Append -Encoding utf8
32+
}
33+
34+
###########################################################
35+
# Add base images
36+
###########################################################
37+
@"
38+
productService:
39+
image:
40+
repository: ${env:SOURCE_REGISTRY}/aks-store-demo/product-service
41+
storeAdmin:
42+
image:
43+
repository: ${env:SOURCE_REGISTRY}/aks-store-demo/store-admin
44+
storeFront:
45+
image:
46+
repository: ${env:SOURCE_REGISTRY}/aks-store-demo/store-front
47+
virtualCustomer:
48+
image:
49+
repository: ${env:SOURCE_REGISTRY}/aks-store-demo/virtual-customer
50+
virtualWorker:
51+
image:
52+
repository: ${env:SOURCE_REGISTRY}/aks-store-demo/virtual-worker
53+
"@ | Out-File -FilePath custom-values.yaml -Append -Encoding utf8
54+
55+
###########################################################
56+
# Add ai-service if Azure OpenAI endpoint is provided
57+
###########################################################
58+
if ($env:AZURE_OPENAI_ENDPOINT) {
59+
@"
60+
aiService:
61+
image:
62+
repository: ${env:SOURCE_REGISTRY}/aks-store-demo/ai-service
63+
create: true
64+
modelDeploymentName: ${env:AZURE_OPENAI_MODEL_NAME}
65+
openAiEndpoint: ${env:AZURE_OPENAI_ENDPOINT}
66+
useAzureOpenAi: true
67+
"@ | Out-File -FilePath custom-values.yaml -Append -Encoding utf8
68+
69+
# If DALL-E model endpoint and name exist
70+
if ($env:AZURE_OPENAI_DALL_E_ENDPOINT -and $env:AZURE_OPENAI_DALL_E_MODEL_NAME) {
71+
@"
72+
openAiDalleEndpoint: ${env:AZURE_OPENAI_DALL_E_ENDPOINT}
73+
openAiDalleModelName: ${env:AZURE_OPENAI_DALL_E_MODEL_NAME}
74+
"@ | Out-File -FilePath custom-values.yaml -Append -Encoding utf8
75+
}
76+
}
77+
78+
###########################################################
79+
# Add order-service
80+
###########################################################
81+
@"
82+
orderService:
83+
image:
84+
repository: ${env:SOURCE_REGISTRY}/aks-store-demo/order-service
85+
"@ | Out-File -FilePath custom-values.yaml -Append -Encoding utf8
86+
87+
# Add Azure Service Bus to order-service if provided
88+
if ($env:AZURE_SERVICE_BUS_HOST) {
89+
@"
90+
queueHost: ${env:AZURE_SERVICE_BUS_HOST}
91+
"@ | Out-File -FilePath custom-values.yaml -Append -Encoding utf8
92+
}
93+
94+
###########################################################
95+
# Add makeline-service
96+
###########################################################
97+
@"
98+
makelineService:
99+
image:
100+
repository: ${env:SOURCE_REGISTRY}/aks-store-demo/makeline-service
101+
"@ | Out-File -FilePath custom-values.yaml -Append -Encoding utf8
102+
103+
# Add Azure Service Bus to makeline-service if provided
104+
# (Parity with bash: check HOST presence and write HOST value)
105+
if ($env:AZURE_SERVICE_BUS_HOST) {
106+
@"
107+
orderQueueHost: ${env:AZURE_SERVICE_BUS_HOST}
108+
"@ | Out-File -FilePath custom-values.yaml -Append -Encoding utf8
109+
}
110+
111+
# Add Azure Cosmos DB to makeline-service if provided
112+
if ($env:AZURE_COSMOS_DATABASE_URI) {
113+
@"
114+
orderDBApi: ${env:AZURE_DATABASE_API}
115+
orderDBUri: ${env:AZURE_COSMOS_DATABASE_URI}
116+
"@ | Out-File -FilePath custom-values.yaml -Append -Encoding utf8
117+
}
118+
119+
###########################################################
120+
# Do not deploy RabbitMQ when using Azure Service Bus
121+
###########################################################
122+
if ($env:AZURE_SERVICE_BUS_HOST) {
123+
@"
124+
useRabbitMQ: false
125+
"@ | Out-File -FilePath custom-values.yaml -Append -Encoding utf8
126+
}
127+
128+
###########################################################
129+
# Do not deploy MongoDB when using Azure Cosmos DB
130+
###########################################################
131+
if ($env:AZURE_COSMOS_DATABASE_URI) {
132+
@"
133+
useMongoDB: false
134+
"@ | Out-File -FilePath custom-values.yaml -Append -Encoding utf8
135+
}

azd-hooks/predeploy.sh

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
#!/usr/bin/env sh
2+
3+
##########################################################
4+
# Ensure Helm and Kustomize support is enabled
5+
##########################################################
6+
azd config set alpha.aks.helm on
7+
azd config set alpha.aks.kustomize on
8+
9+
# Check kubelogin and install if not exists
10+
##########################################################
11+
if ! command -v kubelogin >/dev/null 2>&1; then
12+
echo "kubelogin could not be found. Installing kubelogin..."
13+
az aks install-cli
14+
fi
15+
16+
##########################################################
17+
# Create the custom-values.yaml file
18+
##########################################################
19+
cat << EOF > custom-values.yaml
20+
namespace: ${AZURE_AKS_NAMESPACE}
21+
EOF
22+
23+
###########################################################
24+
# Add Azure Managed Identity and set to use AzureAD auth
25+
###########################################################
26+
if [ -n "${AZURE_IDENTITY_CLIENT_ID}" ] && [ -n "${AZURE_IDENTITY_NAME}" ]; then
27+
cat << EOF >> custom-values.yaml
28+
useAzureAd: true
29+
managedIdentityName: ${AZURE_IDENTITY_NAME}
30+
managedIdentityClientId: ${AZURE_IDENTITY_CLIENT_ID}
31+
EOF
32+
fi
33+
34+
##########################################################
35+
# Add base images
36+
##########################################################
37+
cat << EOF >> custom-values.yaml
38+
productService:
39+
image:
40+
repository: ${SOURCE_REGISTRY}/aks-store-demo/product-service
41+
storeAdmin:
42+
image:
43+
repository: ${SOURCE_REGISTRY}/aks-store-demo/store-admin
44+
storeFront:
45+
image:
46+
repository: ${SOURCE_REGISTRY}/aks-store-demo/store-front
47+
virtualCustomer:
48+
image:
49+
repository: ${SOURCE_REGISTRY}/aks-store-demo/virtual-customer
50+
virtualWorker:
51+
image:
52+
repository: ${SOURCE_REGISTRY}/aks-store-demo/virtual-worker
53+
EOF
54+
55+
###########################################################
56+
# Add ai-service if Azure OpenAI endpoint is provided
57+
###########################################################
58+
59+
if [ -n "${AZURE_OPENAI_ENDPOINT}" ]; then
60+
cat << EOF >> custom-values.yaml
61+
aiService:
62+
image:
63+
repository: ${SOURCE_REGISTRY}/aks-store-demo/ai-service
64+
create: true
65+
modelDeploymentName: ${AZURE_OPENAI_MODEL_NAME}
66+
openAiEndpoint: ${AZURE_OPENAI_ENDPOINT}
67+
useAzureOpenAi: true
68+
EOF
69+
70+
# If DALL-E model endpoint and name exists
71+
if [ -n "${AZURE_OPENAI_DALL_E_ENDPOINT}" ] && [ -n "${AZURE_OPENAI_DALL_E_MODEL_NAME}" ]; then
72+
cat << EOF >> custom-values.yaml
73+
openAiDalleEndpoint: ${AZURE_OPENAI_DALL_E_ENDPOINT}
74+
openAiDalleModelName: ${AZURE_OPENAI_DALL_E_MODEL_NAME}
75+
EOF
76+
fi
77+
fi
78+
79+
###########################################################
80+
# Add order-service
81+
###########################################################
82+
83+
cat << EOF >> custom-values.yaml
84+
orderService:
85+
image:
86+
repository: ${SOURCE_REGISTRY}/aks-store-demo/order-service
87+
EOF
88+
89+
# Add Azure Service Bus to order-service if provided
90+
if [ -n "${AZURE_SERVICE_BUS_HOST}" ]; then
91+
cat << EOF >> custom-values.yaml
92+
queueHost: ${AZURE_SERVICE_BUS_HOST}
93+
EOF
94+
fi
95+
96+
###########################################################
97+
# Add makeline-service
98+
###########################################################
99+
100+
cat << EOF >> custom-values.yaml
101+
makelineService:
102+
image:
103+
repository: ${SOURCE_REGISTRY}/aks-store-demo/makeline-service
104+
EOF
105+
106+
# Add Azure Service Bus to makeline-service if provided
107+
if [ -n "${AZURE_SERVICE_BUS_HOST}" ]; then
108+
cat << EOF >> custom-values.yaml
109+
orderQueueHost: ${AZURE_SERVICE_BUS_HOST}
110+
EOF
111+
fi
112+
113+
# Add Azure Cosmos DB to makeline-service if provided
114+
if [ -n "${AZURE_COSMOS_DATABASE_URI}" ]; then
115+
cat << EOF >> custom-values.yaml
116+
orderDBApi: ${AZURE_DATABASE_API}
117+
orderDBUri: ${AZURE_COSMOS_DATABASE_URI}
118+
EOF
119+
fi
120+
121+
###########################################################
122+
# Do not deploy RabbitMQ when using Azure Service Bus
123+
###########################################################
124+
if [ -n "${AZURE_SERVICE_BUS_HOST}" ]; then
125+
cat << EOF >> custom-values.yaml
126+
useRabbitMQ: false
127+
EOF
128+
fi
129+
130+
###########################################################
131+
# Do not deploy MongoDB when using Azure Cosmos DB
132+
###########################################################
133+
if [ -n "${AZURE_COSMOS_DATABASE_URI}" ]; then
134+
cat << EOF >> custom-values.yaml
135+
useMongoDB: false
136+
EOF
137+
fi

0 commit comments

Comments
 (0)