Skip to content

fix: Template deployment #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Apr 5, 2025
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,6 @@ __pycache__/
venv
myenv

scriptsenv/
scriptsenv/

scriptenv
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ To change the azd parameters from the default values, follow the steps [here](./
* This deployment will take *7-10 minutes* to provision the resources in your account and set up the solution with sample data.
* If you get an error or timeout with deployment, changing the location can help, as there may be availability constraints for the resources.

5. Once the deployment has completed successfully, open the [Azure Portal](https://portal.azure.com/), go to the deployed resource group, find the App Service and get the app URL from `Default domain`.
5. Once the deployment has completed successfully and you would like to use the sample data, run the bash command printed in the terminal. The bash command will look like the following:
```shell
./infra/scripts/process_sample_data.sh <Storage-Account-name> <Storgae-Account-container-name> <Key-Vault-name>
```

6. Open the [Azure Portal](https://portal.azure.com/), go to the deployed resource group, find the App Service and get the app URL from `Default domain`.

6. You can now delete the resources by running `azd down`, if you are done trying out the application.
<!-- 6. You can now proceed to run the [development server](#development-server) to test the app locally, or if you are done trying out the app, you can delete the resources by running `azd down`. -->
Expand Down
5 changes: 5 additions & 0 deletions azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,18 @@ hooks:
run: |
Write-Host "Web app URL: "
Write-Host "$env:WEB_APP_URL" -ForegroundColor Cyan
Write-Host "`nIf you want to use the Sample Data, run the following command in the Bash terminal to process it:"
Write-Host "bash ./infra/scripts/process_sample_data.sh $env:STORAGE_ACCOUNT_NAME $env:STORAGE_CONTAINER_NAME $env:KEY_VAULT_NAME" -ForegroundColor Cyan
shell: pwsh
continueOnError: false
interactive: true
posix:
run: |
echo "Web app URL: "
echo $WEB_APP_URL
echo ""
echo "If you want to use the Sample Data, run the following command in the terminal to process it:"
echo "bash ./infra/scripts/process_sample_data.sh $STORAGE_ACCOUNT_NAME $STORAGE_CONTAINER_NAME $KEY_VAULT_NAME"
shell: sh
continueOnError: false
interactive: true
36 changes: 21 additions & 15 deletions infra/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,12 @@ module cosmosDBModule 'deploy_cosmos_db.bicep' = {
}
scope: resourceGroup(resourceGroup().name)
}
// output copykbfiles string = './infra/scripts/copy_kb_files.sh ${storageAccount.outputs.storageName} ${storageAccount.outputs.storageContainer} ${managedIdentityModule.outputs.managedIdentityOutput.clientId}'
// output createindex string = './infra/scripts/run_create_index_scripts.sh ${kvault.outputs.keyvaultName} ${managedIdentityModule.outputs.managedIdentityOutput.clientId}'

output STORAGE_ACCOUNT_NAME string = storageAccount.outputs.storageName
output STORAGE_CONTAINER_NAME string = storageAccount.outputs.storageContainer
output KEY_VAULT_NAME string = kvault.outputs.keyvaultName


// //========== Deployment script to upload sample data ========== //
Expand Down Expand Up @@ -452,21 +458,21 @@ module cosmosDBModule 'deploy_cosmos_db.bicep' = {
// dependsOn:[keyVault,uploadFiles]
// }

//========== Deployment script to upload sample data ========== //
module uploadFiles 'deploy_post_deployment_scripts.bicep' = {
name : 'deploy_post_deployment_scripts'
params:{
solutionName: solutionPrefix
solutionLocation: secondaryLocation
baseUrl: baseUrl
storageAccountName: storageAccount.outputs.storageName
containerName: storageAccount.outputs.storageContainer
managedIdentityObjectId:managedIdentityModule.outputs.managedIdentityOutput.id
managedIdentityClientId:managedIdentityModule.outputs.managedIdentityOutput.clientId
keyVaultName:aifoundry.outputs.keyvaultName
logAnalyticsWorkspaceResourceName: aifoundry.outputs.logAnalyticsWorkspaceResourceName
}
}
// //========== Deployment script to upload sample data ========== //
// module uploadFiles 'deploy_post_deployment_scripts.bicep' = {
// name : 'deploy_post_deployment_scripts'
// params:{
// solutionName: solutionPrefix
// solutionLocation: secondaryLocation
// baseUrl: baseUrl
// storageAccountName: storageAccount.outputs.storageName
// containerName: storageAccount.outputs.storageContainer
// managedIdentityObjectId:managedIdentityModule.outputs.managedIdentityOutput.id
// managedIdentityClientId:managedIdentityModule.outputs.managedIdentityOutput.clientId
// keyVaultName:aifoundry.outputs.keyvaultName
// logAnalyticsWorkspaceResourceName: aifoundry.outputs.logAnalyticsWorkspaceResourceName
// }
// }


// resource CosmosDB 'Microsoft.DocumentDB/databaseAccounts@2023-04-15' = {
Expand Down
222 changes: 22 additions & 200 deletions infra/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.34.44.8038",
"templateHash": "745056846550767942"
"version": "0.33.93.31351",
"templateHash": "2424049160506179064"
}
},
"parameters": {
Expand Down Expand Up @@ -150,8 +150,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.34.44.8038",
"templateHash": "16854919160820907978"
"version": "0.33.93.31351",
"templateHash": "5719315788994459005"
}
},
"parameters": {
Expand Down Expand Up @@ -243,8 +243,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.34.44.8038",
"templateHash": "998804936838864872"
"version": "0.33.93.31351",
"templateHash": "16444845925569233096"
}
},
"parameters": {
Expand Down Expand Up @@ -383,8 +383,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.34.44.8038",
"templateHash": "15569997416548251984"
"version": "0.33.93.31351",
"templateHash": "627756007451802146"
}
},
"parameters": {
Expand Down Expand Up @@ -981,8 +981,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.34.44.8038",
"templateHash": "4051638923493896337"
"version": "0.33.93.31351",
"templateHash": "12863612675732383951"
}
},
"parameters": {
Expand Down Expand Up @@ -1210,8 +1210,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.34.44.8038",
"templateHash": "4077975888118623954"
"version": "0.33.93.31351",
"templateHash": "6455788440385967919"
}
},
"parameters": {
Expand Down Expand Up @@ -1696,8 +1696,8 @@
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.34.44.8038",
"templateHash": "6611317231290784098"
"version": "0.33.93.31351",
"templateHash": "16935405490916431865"
}
},
"parameters": {
Expand Down Expand Up @@ -1874,198 +1874,20 @@
"dependsOn": [
"[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_keyvault')]"
]
},
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2022-09-01",
"name": "deploy_post_deployment_scripts",
"properties": {
"expressionEvaluationOptions": {
"scope": "inner"
},
"mode": "Incremental",
"parameters": {
"solutionName": {
"value": "[variables('solutionPrefix')]"
},
"solutionLocation": {
"value": "[parameters('secondaryLocation')]"
},
"baseUrl": {
"value": "[variables('baseUrl')]"
},
"storageAccountName": {
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_storage_account'), '2022-09-01').outputs.storageName.value]"
},
"containerName": {
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_storage_account'), '2022-09-01').outputs.storageContainer.value]"
},
"managedIdentityObjectId": {
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_managed_identity'), '2022-09-01').outputs.managedIdentityOutput.value.id]"
},
"managedIdentityClientId": {
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_managed_identity'), '2022-09-01').outputs.managedIdentityOutput.value.clientId]"
},
"keyVaultName": {
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.keyvaultName.value]"
},
"logAnalyticsWorkspaceResourceName": {
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.logAnalyticsWorkspaceResourceName.value]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.34.44.8038",
"templateHash": "17578272684671627358"
}
},
"parameters": {
"solutionName": {
"type": "string",
"metadata": {
"description": "Solution Name"
}
},
"solutionLocation": {
"type": "string",
"metadata": {
"description": "Specifies the location for resources."
}
},
"baseUrl": {
"type": "string"
},
"managedIdentityObjectId": {
"type": "string"
},
"managedIdentityClientId": {
"type": "string"
},
"storageAccountName": {
"type": "string"
},
"containerName": {
"type": "string"
},
"containerAppName": {
"type": "string",
"defaultValue": "[format('ca-{0}', parameters('solutionName'))]"
},
"environmentName": {
"type": "string",
"defaultValue": "[format('cae-{0}', parameters('solutionName'))]"
},
"imageName": {
"type": "string",
"defaultValue": "python:3.11-alpine"
},
"setupCopyKbFiles": {
"type": "string",
"defaultValue": "[format('{0}infra/scripts/copy_kb_files.sh', parameters('baseUrl'))]"
},
"setupCreateIndexScriptsUrl": {
"type": "string",
"defaultValue": "[format('{0}infra/scripts/run_create_index_scripts.sh', parameters('baseUrl'))]"
},
"keyVaultName": {
"type": "string"
},
"logAnalyticsWorkspaceResourceName": {
"type": "string"
}
},
"resources": [
{
"type": "Microsoft.App/managedEnvironments",
"apiVersion": "2022-03-01",
"name": "[parameters('environmentName')]",
"location": "[parameters('solutionLocation')]",
"properties": {
"zoneRedundant": false,
"appLogsConfiguration": {
"destination": "log-analytics",
"logAnalyticsConfiguration": {
"customerId": "[reference(resourceId('Microsoft.OperationalInsights/workspaces', parameters('logAnalyticsWorkspaceResourceName')), '2020-10-01').customerId]",
"sharedKey": "[listKeys(resourceId('Microsoft.OperationalInsights/workspaces', parameters('logAnalyticsWorkspaceResourceName')), '2020-10-01').primarySharedKey]"
}
}
}
},
{
"type": "Microsoft.App/containerApps",
"apiVersion": "2022-03-01",
"name": "[parameters('containerAppName')]",
"location": "[parameters('solutionLocation')]",
"identity": {
"type": "UserAssigned",
"userAssignedIdentities": {
"[format('{0}', parameters('managedIdentityObjectId'))]": {}
}
},
"properties": {
"managedEnvironmentId": "[resourceId('Microsoft.App/managedEnvironments', parameters('environmentName'))]",
"configuration": {
"ingress": null,
"activeRevisionsMode": "Single"
},
"template": {
"scale": {
"minReplicas": 1,
"maxReplicas": 1
},
"containers": [
{
"name": "[parameters('containerAppName')]",
"image": "[parameters('imageName')]",
"resources": {
"cpu": 2,
"memory": "4.0Gi"
},
"command": [
"/bin/sh",
"-c",
"[format('mkdir -p /scripts && apk add --no-cache curl bash jq py3-pip gcc musl-dev libffi-dev openssl-dev python3-dev && pip install --upgrade azure-cli && apk add --no-cache --virtual .build-deps build-base unixodbc-dev && curl -s -o msodbcsql18_18.4.1.1-1_amd64.apk https://download.microsoft.com/download/7/6/d/76de322a-d860-4894-9945-f0cc5d6a45f8/msodbcsql18_18.4.1.1-1_amd64.apk && curl -s -o mssql-tools18_18.4.1.1-1_amd64.apk https://download.microsoft.com/download/7/6/d/76de322a-d860-4894-9945-f0cc5d6a45f8/mssql-tools18_18.4.1.1-1_amd64.apk && apk add --allow-untrusted msodbcsql18_18.4.1.1-1_amd64.apk && apk add --allow-untrusted mssql-tools18_18.4.1.1-1_amd64.apk && curl -s -o /scripts/copy_kb_files.sh {0} && chmod +x /scripts/copy_kb_files.sh && sh -x /scripts/copy_kb_files.sh {1} {2} {3} {4} && curl -s -o /scripts/run_create_index_scripts.sh {5} && chmod +x /scripts/run_create_index_scripts.sh && sh -x /scripts/run_create_index_scripts.sh {6} {7} {8} && apk add --no-cache ca-certificates less ncurses-terminfo-base krb5-libs libgcc libintl libssl3 libstdc++ tzdata userspace-rcu zlib icu-libs curl && apk -X https://dl-cdn.alpinelinux.org/alpine/edge/main add --no-cache lttng-ust openssh-client && echo \"Container app setup completed successfully.\"', parameters('setupCopyKbFiles'), parameters('storageAccountName'), parameters('containerName'), parameters('baseUrl'), parameters('managedIdentityClientId'), parameters('setupCreateIndexScriptsUrl'), parameters('baseUrl'), parameters('keyVaultName'), parameters('managedIdentityClientId'))]"
],
"env": [
{
"name": "STORAGE_ACCOUNT_NAME",
"value": "[parameters('storageAccountName')]"
},
{
"name": "CONTAINER_NAME",
"value": "[parameters('containerName')]"
},
{
"name": "APPSETTING_WEBSITE_SITE_NAME",
"value": "DUMMY"
}
]
}
]
}
},
"dependsOn": [
"[resourceId('Microsoft.App/managedEnvironments', parameters('environmentName'))]"
]
}
]
}
},
"dependsOn": [
"[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry')]",
"[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_managed_identity')]",
"[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_storage_account')]"
]
}
],
"outputs": {
"WEB_APP_URL": {
"type": "string",
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_app_service'), '2022-09-01').outputs.webAppUrl.value]"
},
"copykbfiles": {
"type": "string",
"value": "[format('./infra/scripts/copy_kb_files.sh {0} {1} {2}', reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_storage_account'), '2022-09-01').outputs.storageName.value, reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_storage_account'), '2022-09-01').outputs.storageContainer.value, reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_managed_identity'), '2022-09-01').outputs.managedIdentityOutput.value.clientId)]"
},
"createindex": {
"type": "string",
"value": "[format('./infra/scripts/run_create_index_scripts.sh {0} {1}', reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_keyvault'), '2022-09-01').outputs.keyvaultName.value, reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_managed_identity'), '2022-09-01').outputs.managedIdentityOutput.value.clientId)]"
}
}
}
Loading
Loading