Skip to content

Commit

Permalink
Merge pull request Azure-Samples#137 from pauldotyu/main
Browse files Browse the repository at this point in the history
refactor: updating azd to deploy app via helm
  • Loading branch information
pauldotyu authored Apr 16, 2024
2 parents fcad517 + e6745b3 commit c917c64
Show file tree
Hide file tree
Showing 22 changed files with 447 additions and 124 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,6 @@ test-results/
playwright-report/
playwright/.cache/
.env.playwright.local

# custom helm values
custom-values.yaml
6 changes: 6 additions & 0 deletions azd-hooks/postdeploy.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/usr/bin/env pwsh

############################################
# Delete custom-values.yaml
############################################
Remove-Item -Path custom-values.yaml -ErrorAction SilentlyContinue
6 changes: 6 additions & 0 deletions azd-hooks/postdeploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

############################################
# Delete custom-values.yaml
############################################
rm custom-values.yaml
155 changes: 121 additions & 34 deletions azd-hooks/predeploy.ps1
Original file line number Diff line number Diff line change
@@ -1,39 +1,126 @@
#!/usr/bin/env pwsh

echo "Retrieving cluster credentials"
az aks get-credentials --resource-group $env:AZURE_RESOURCEGROUP_NAME --name $env:AZURE_AKS_CLUSTER_NAME --overwrite-existing
az aks get-credentials --resource-group ${AZURE_RESOURCEGROUP_NAME} --name ${AZURE_AKS_CLUSTER_NAME} --overwrite-existing

$makelineUseSqlApi = "false"
if ($env:AZURE_DATABASE_API -eq "cosmosdbsql") {
$makelineUseSqlApi = "true"
###########################################################
# Create the custom-values.yaml file with base images
###########################################################

@"
namespace: ${env:AZURE_AKS_NAMESPACE}
productService:
image:
repository: ${env:AZURE_REGISTRY_URI}/aks-store-demo/product-service
storeAdmin:
image:
repository: ${env:AZURE_REGISTRY_URI}/aks-store-demo/store-admin
storeFront:
image:
repository: ${env:AZURE_REGISTRY_URI}/aks-store-demo/store-front
virtualCustomer:
image:
repository: ${env:AZURE_REGISTRY_URI}/aks-store-demo/virtual-customer
virtualWorker:
image:
repository: ${env:AZURE_REGISTRY_URI}/aks-store-demo/virtual-worker
"@ | Out-File -FilePath custom-values.yaml -Encoding utf8

###########################################################
# Add ai-service if Azure OpenAI endpoint is provided
###########################################################

if ($env:AZURE_OPENAI_ENDPOINT) {
@"
aiService:
image:
repository: ${env:AZURE_REGISTRY_URI}/aks-store-demo/ai-service
create: true
modelDeploymentName: ${env:AZURE_OPENAI_MODEL_NAME}
openAiEndpoint: ${env:AZURE_OPENAI_ENDPOINT}
useAzureOpenAi: if ($env:AZURE_OPENAI_ENDPOINT) { 'true' }
"@ | Out-File -Path custom-values.yaml -Append -Encoding utf8

# If Azure identity exists, use it, otherwise use the Azure OpenAI API key
if ($env:AZURE_IDENTITY_CLIENT_ID) {
@"
managedIdentityClientId: ${env:AZURE_IDENTITY_CLIENT_ID}
useAzureAd: true
"@ | Out-File -Path custom-values.yaml -Append -Encoding utf8
} else {
$openAiKey = az keyvault secret show --name $env:AZURE_OPENAI_KEY --vault-name $env:AZURE_KEY_VAULT_NAME --query value -o tsv
@"
openAiKey: $openAiKey
"@ | Out-File -Path custom-values.yaml -Append -Encoding utf8
}
}

###########################################################
# Add order-service
###########################################################
@"
orderService:
image:
repository: ${env:AZURE_REGISTRY_URI}/aks-store-demo/order-service
"@ | Out-File -Path custom-values.yaml -Append -Encoding utf8

# Add Azure Service Bus to order-service if provided
if ($env:AZURE_SERVICE_BUS_HOST) {
$queuePassword = az keyvault secret show --name $env:AZURE_SERVICE_BUS_SENDER_KEY --vault-name $env:AZURE_KEY_VAULT_NAME --query value -o tsv
@"
queueHost: ${env:AZURE_SERVICE_BUS_HOST}
queuePort: "5671"
queueTransport: "tls"
queueUsername: ${env:AZURE_SERVICE_BUS_SENDER_NAME}
queuePassword: $queuePassword
"@ | Out-File -Path custom-values.yaml -Append -Encoding utf8
}

###########################################################
# Add makeline-service
###########################################################
@"
makelineService:
image:
repository: ${env:AZURE_REGISTRY_URI}/aks-store-demo/makeline-service
"@ | Out-File -Path custom-values.yaml -Append -Encoding utf8

# Add Azure Service Bus to makeline-service if provided
if ($env:AZURE_SERVICE_BUS_URI) {
$orderQueuePassword = az keyvault secret show --name $env:AZURE_SERVICE_BUS_LISTENER_KEY --vault-name $env:AZURE_KEY_VAULT_NAME --query value -o tsv
@"
orderQueueUri: ${env:AZURE_SERVICE_BUS_URI}
orderQueueUsername: ${env:AZURE_SERVICE_BUS_LISTENER_NAME}
orderQueuePassword: $orderQueuePassword
"@ | Out-File -Path custom-values.yaml -Append -Encoding utf8
}

# Add Azure Cosmos DB to makeline-service if provided
if ($env:AZURE_COSMOS_DATABASE_URI) {
$orderDBPassword = az keyvault secret show --name $env:AZURE_COSMOS_DATABASE_KEY --vault-name $env:AZURE_KEY_VAULT_NAME --query value -o tsv
@"
orderDBApi: ${env:AZURE_DATABASE_API}
orderDBUri: ${env:AZURE_COSMOS_DATABASE_URI}
orderDBUsername: ${env:AZURE_COSMOS_DATABASE_NAME}
orderDBPassword: $orderDBPassword
"@ | Out-File -Path custom-values.yaml -Append -Encoding utf8
}



###########################################################
# Do not deploy RabbitMQ when using Azure Service Bus
###########################################################
if ($env:AZURE_SERVICE_BUS_HOST) {
@"
useRabbitMQ: false
"@ | Out-File -Path custom-values.yaml -Append -Encoding utf8
}

echo "Deploy Helm chart"
helm upgrade aks-store-demo ./charts/aks-store-demo `
--install `
--set aiService.create=true `
--set aiService.modelDeploymentName=$env:AZURE_OPENAI_MODEL_NAME `
--set aiService.openAiEndpoint=$env:AZURE_OPENAI_ENDPOINT `
--set aiService.managedIdentityClientId=$env:AZURE_IDENTITY_CLIENT_ID `
--set aiService.image.repository=$env:AZURE_REGISTRY_URI/aks-store-demo/ai-service `
--set orderService.useAzureServiceBus=true `
--set orderService.queueHost=$env:AZURE_SERVICE_BUS_HOST `
--set orderService.queuePort=5671 `
--set orderService.queueUsername=$env:AZURE_SERVICE_BUS_SENDER_NAME `
--set orderService.queuePassword=$(az keyvault secret show --name $env:AZURE_SERVICE_BUS_SENDER_KEY --vault-name $env:AZURE_KEY_VAULT_NAME --query value -o tsv) `
--set orderService.queueTransport=tls `
--set orderService.image.repository=$env:AZURE_REGISTRY_URI/aks-store-demo/order-service `
--set makelineService.useAzureCosmosDB=true `
--set makelineService.orderQueueUri=$env:AZURE_SERVICE_BUS_URI `
--set makelineService.orderQueueUsername=$env:AZURE_SERVICE_BUS_LISTENER_NAME `
--set makelineService.orderQueuePassword=$(az keyvault secret show --name $env:AZURE_SERVICE_BUS_LISTENER_KEY --vault-name $env:AZURE_KEY_VAULT_NAME --query value -o tsv) `
--set makelineService.orderDBUri=$env:AZURE_COSMOS_DATABASE_URI `
--set makelineService.orderDBUsername=$env:AZURE_COSMOS_DATABASE_NAME `
--set makelineService.orderDBPassword=$(az keyvault secret show --name $env:AZURE_COSMOS_DATABASE_KEY --vault-name $env:AZURE_KEY_VAULT_NAME --query value -o tsv) `
--set makelineService.image.repository=$env:AZURE_REGISTRY_URI/aks-store-demo/makeline-service `
--set productService.image.repository=$env:AZURE_REGISTRY_URI/aks-store-demo/product-service `
--set storeAdmin.image.repository=$env:AZURE_REGISTRY_URI/aks-store-demo/store-admin `
--set storeFront.image.repository=$env:AZURE_REGISTRY_URI/aks-store-demo/store-front `
--set virtualCustomer.image.repository=$env:AZURE_REGISTRY_URI/aks-store-demo/virtual-customer `
--set virtualWorker.image.repository=$env:AZURE_REGISTRY_URI/aks-store-demo/virtual-worker `
--set makelineService.useSqlApi=$makelineUseSqlApi
###########################################################
# Do not deploy MongoDB when using Azure Cosmos DB
###########################################################
if ($env:AZURE_COSMOS_DATABASE_URI) {
@"
useMongoDB: false
"@ | Out-File -Path custom-values.yaml -Append -Encoding utf8
}
142 changes: 103 additions & 39 deletions azd-hooks/predeploy.sh
Original file line number Diff line number Diff line change
@@ -1,58 +1,122 @@
#!/bin/bash

echo "Retrieving cluster credentials"
az aks get-credentials --resource-group ${AZURE_RESOURCEGROUP_NAME} --name ${AZURE_AKS_CLUSTER_NAME} --overwrite-existing

echo "Deploy Helm chart"
cmd="helm upgrade aks-store-demo ./charts/aks-store-demo \
--install \
--namespace ${AZURE_AKS_NAMESPACE} \
--create-namespace \
--set aiService.image.repository=${AZURE_REGISTRY_URI}/aks-store-demo/ai-service \
--set orderService.image.repository=${AZURE_REGISTRY_URI}/aks-store-demo/order-service \
--set makelineService.image.repository=${AZURE_REGISTRY_URI}/aks-store-demo/makeline-service \
--set productService.image.repository=${AZURE_REGISTRY_URI}/aks-store-demo/product-service \
--set storeAdmin.image.repository=${AZURE_REGISTRY_URI}/aks-store-demo/store-admin \
--set storeFront.image.repository=${AZURE_REGISTRY_URI}/aks-store-demo/store-front \
--set virtualCustomer.image.repository=${AZURE_REGISTRY_URI}/aks-store-demo/virtual-customer \
--set virtualWorker.image.repository=${AZURE_REGISTRY_URI}/aks-store-demo/virtual-worker"
##########################################################
# Create the custom-values.yaml file with base images
##########################################################

cat << EOF > custom-values.yaml
namespace: ${AZURE_AKS_NAMESPACE}
productService:
image:
repository: ${AZURE_REGISTRY_URI}/aks-store-demo/product-service
storeAdmin:
image:
repository: ${AZURE_REGISTRY_URI}/aks-store-demo/store-admin
storeFront:
image:
repository: ${AZURE_REGISTRY_URI}/aks-store-demo/store-front
virtualCustomer:
image:
repository: ${AZURE_REGISTRY_URI}/aks-store-demo/virtual-customer
virtualWorker:
image:
repository: ${AZURE_REGISTRY_URI}/aks-store-demo/virtual-worker
EOF

###########################################################
# Add ai-servie if Azure OpenAI endpoint is provided
###########################################################

if [ -n "${AZURE_OPENAI_ENDPOINT}" ]; then
cmd+=" --set aiService.create=true \
--set aiService.openAiEndpoint=${AZURE_OPENAI_ENDPOINT} \
--set aiService.modelDeploymentName=${AZURE_OPENAI_MODEL_NAME} \
--set aiService.useAzureOpenAi=true"
cat << EOF >> custom-values.yaml
aiService:
image:
repository: ${AZURE_REGISTRY_URI}/aks-store-demo/ai-service
create: true
modelDeploymentName: ${AZURE_OPENAI_MODEL_NAME}
openAiEndpoint: ${AZURE_OPENAI_ENDPOINT}
useAzureOpenAi: true
EOF

# If Azure identity exists, use it, otherwise use the Azure OpenAI API key
if [ -n "${AZURE_IDENTITY_CLIENT_ID}" ]; then
cmd+=" --set aiService.managedIdentityClientId=${AZURE_IDENTITY_CLIENT_ID} \
--set aiService.useAzureAd=true"
cat << EOF >> custom-values.yaml
useAzureAd: true
managedIdentityClientId: ${AZURE_IDENTITY_CLIENT_ID}
EOF
else
cmd+=" --set aiService.openAiKey=$(az keyvault secret show --name ${AZURE_OPENAI_KEY} --vault-name ${AZURE_KEY_VAULT_NAME} --query value -o tsv) \
--set aiService.useAzureAd=false"
cat << EOF >> custom-values.yaml
openAiKey: $(az keyvault secret show --name ${AZURE_OPENAI_KEY} --vault-name ${AZURE_KEY_VAULT_NAME} --query value -o tsv)
EOF
fi
fi

###########################################################
# Add order-service
###########################################################

cat << EOF >> custom-values.yaml
orderService:
image:
repository: ${AZURE_REGISTRY_URI}/aks-store-demo/order-service
EOF

# Add Azure Service Bus to order-service if provided
if [ -n "${AZURE_SERVICE_BUS_HOST}" ]; then
cmd+=" --set orderService.useAzureServiceBus=true \
--set orderService.queueHost=${AZURE_SERVICE_BUS_HOST} \
--set orderService.queuePort=5671 \
--set orderService.queueUsername=${AZURE_SERVICE_BUS_SENDER_NAME} \
--set orderService.queuePassword=$(az keyvault secret show --name ${AZURE_SERVICE_BUS_SENDER_KEY} --vault-name ${AZURE_KEY_VAULT_NAME} --query value -o tsv) \
--set orderService.queueTransport=tls \
--set makelineService.orderQueueUri=${AZURE_SERVICE_BUS_URI} \
--set makelineService.orderQueueUsername=${AZURE_SERVICE_BUS_LISTENER_NAME} \
--set makelineService.orderQueuePassword=$(az keyvault secret show --name ${AZURE_SERVICE_BUS_LISTENER_KEY} --vault-name ${AZURE_KEY_VAULT_NAME} --query value -o tsv)"
cat << EOF >> custom-values.yaml
queueHost: ${AZURE_SERVICE_BUS_HOST}
queuePort: "5671"
queueTransport: "tls"
queueUsername: ${AZURE_SERVICE_BUS_SENDER_NAME}
queuePassword: $(az keyvault secret show --name ${AZURE_SERVICE_BUS_SENDER_KEY} --vault-name ${AZURE_KEY_VAULT_NAME} --query value -o tsv)
EOF
fi

###########################################################
# Add makeline-service
###########################################################

cat << EOF >> custom-values.yaml
makelineService:
image:
repository: ${AZURE_REGISTRY_URI}/aks-store-demo/makeline-service
EOF

# Add Azure Service Bus to makeline-service if provided
if [ -n "${AZURE_SERVICE_BUS_URI}" ]; then
cat << EOF >> custom-values.yaml
orderQueueUri: ${AZURE_SERVICE_BUS_URI}
orderQueueUsername: ${AZURE_SERVICE_BUS_LISTENER_NAME}
orderQueuePassword: $(az keyvault secret show --name ${AZURE_SERVICE_BUS_LISTENER_KEY} --vault-name ${AZURE_KEY_VAULT_NAME} --query value -o tsv)
EOF
fi

# Add Azure Cosmos DB to makeline-service if provided
if [ -n "${AZURE_COSMOS_DATABASE_URI}" ]; then
cmd+=" --set makelineService.useAzureCosmosDB=true \
--set makelineService.orderDBUri=${AZURE_COSMOS_DATABASE_URI} \
--set makelineService.orderDBUsername=${AZURE_COSMOS_DATABASE_NAME} \
--set makelineService.orderDBPassword=$(az keyvault secret show --name ${AZURE_COSMOS_DATABASE_KEY} --vault-name ${AZURE_KEY_VAULT_NAME} --query value -o tsv)"
cat << EOF >> custom-values.yaml
orderDBApi: ${AZURE_DATABASE_API}
orderDBUri: ${AZURE_COSMOS_DATABASE_URI}
orderDBUsername: ${AZURE_COSMOS_DATABASE_NAME}
orderDBPassword: $(az keyvault secret show --name ${AZURE_COSMOS_DATABASE_KEY} --vault-name ${AZURE_KEY_VAULT_NAME} --query value -o tsv)
EOF
fi

if [ "${AZURE_DATABASE_API}" == "cosmosdbsql" ]; then
cmd+=" --set makelineService.useSqlApi=true"
fi
###########################################################
# Do not deploy RabbitMQ when using Azure Service Bus
###########################################################
if [ -n "${AZURE_SERVICE_BUS_HOST}" ]; then
cat << EOF >> custom-values.yaml
useRabbitMQ: false
EOF
fi

eval $cmd
###########################################################
# Do not deploy MongoDB when using Azure Cosmos DB
###########################################################
if [ -n "${AZURE_COSMOS_DATABASE_URI}" ]; then
cat << EOF >> custom-values.yaml
useMongoDB: false
EOF
fi
Loading

0 comments on commit c917c64

Please sign in to comment.