Skip to content

Commit c57d877

Browse files
committed
update post deployment scripts
1 parent f759ce1 commit c57d877

5 files changed

Lines changed: 79 additions & 238 deletions

File tree

azure.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,21 @@ hooks:
3131
run: |
3232
Write-Host "Web app URL: "
3333
Write-Host "$env:WEB_APP_URL" -ForegroundColor Cyan
34+
Write-Host "Run the following command in the terminal to copy data files to storage account: "
35+
Write-Host "$env:copykbfiles" -ForegroundColor Cyan
36+
Write-Host "Run the following command in the terminal to run the scripts: "
37+
Write-Host "$env:createindex" -ForegroundColor Cyan
3438
shell: pwsh
3539
continueOnError: false
3640
interactive: true
3741
posix:
3842
run: |
3943
echo "Web app URL: "
4044
echo $WEB_APP_URL
45+
echo "Run the following command in the terminal to copy data files to storage account: "
46+
echo $copykbfiles
47+
echo "Run the following command in the terminal to run the scripts: "
48+
echo $createindex
4149
shell: sh
4250
continueOnError: false
4351
interactive: true

infra/main.bicep

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,8 @@ module cosmosDBModule 'deploy_cosmos_db.bicep' = {
424424
}
425425
scope: resourceGroup(resourceGroup().name)
426426
}
427+
output copykbfiles string = './infra/scripts/copy_kb_files.sh ${storageAccount.outputs.storageName} ${storageAccount.outputs.storageContainer} ${managedIdentityModule.outputs.managedIdentityOutput.clientId}'
428+
output createindex string = './infra/scripts/run_create_index_scripts.sh ${kvault.outputs.keyvaultName} ${managedIdentityModule.outputs.managedIdentityOutput.clientId}'
427429

428430

429431
// //========== Deployment script to upload sample data ========== //
@@ -452,21 +454,21 @@ module cosmosDBModule 'deploy_cosmos_db.bicep' = {
452454
// dependsOn:[keyVault,uploadFiles]
453455
// }
454456

455-
//========== Deployment script to upload sample data ========== //
456-
module uploadFiles 'deploy_post_deployment_scripts.bicep' = {
457-
name : 'deploy_post_deployment_scripts'
458-
params:{
459-
solutionName: solutionPrefix
460-
solutionLocation: secondaryLocation
461-
baseUrl: baseUrl
462-
storageAccountName: storageAccount.outputs.storageName
463-
containerName: storageAccount.outputs.storageContainer
464-
managedIdentityObjectId:managedIdentityModule.outputs.managedIdentityOutput.id
465-
managedIdentityClientId:managedIdentityModule.outputs.managedIdentityOutput.clientId
466-
keyVaultName:aifoundry.outputs.keyvaultName
467-
logAnalyticsWorkspaceResourceName: aifoundry.outputs.logAnalyticsWorkspaceResourceName
468-
}
469-
}
457+
// //========== Deployment script to upload sample data ========== //
458+
// module uploadFiles 'deploy_post_deployment_scripts.bicep' = {
459+
// name : 'deploy_post_deployment_scripts'
460+
// params:{
461+
// solutionName: solutionPrefix
462+
// solutionLocation: secondaryLocation
463+
// baseUrl: baseUrl
464+
// storageAccountName: storageAccount.outputs.storageName
465+
// containerName: storageAccount.outputs.storageContainer
466+
// managedIdentityObjectId:managedIdentityModule.outputs.managedIdentityOutput.id
467+
// managedIdentityClientId:managedIdentityModule.outputs.managedIdentityOutput.clientId
468+
// keyVaultName:aifoundry.outputs.keyvaultName
469+
// logAnalyticsWorkspaceResourceName: aifoundry.outputs.logAnalyticsWorkspaceResourceName
470+
// }
471+
// }
470472

471473

472474
// resource CosmosDB 'Microsoft.DocumentDB/databaseAccounts@2023-04-15' = {

infra/main.json

Lines changed: 22 additions & 200 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
"metadata": {
55
"_generator": {
66
"name": "bicep",
7-
"version": "0.34.44.8038",
8-
"templateHash": "745056846550767942"
7+
"version": "0.33.93.31351",
8+
"templateHash": "2424049160506179064"
99
}
1010
},
1111
"parameters": {
@@ -150,8 +150,8 @@
150150
"metadata": {
151151
"_generator": {
152152
"name": "bicep",
153-
"version": "0.34.44.8038",
154-
"templateHash": "16854919160820907978"
153+
"version": "0.33.93.31351",
154+
"templateHash": "5719315788994459005"
155155
}
156156
},
157157
"parameters": {
@@ -243,8 +243,8 @@
243243
"metadata": {
244244
"_generator": {
245245
"name": "bicep",
246-
"version": "0.34.44.8038",
247-
"templateHash": "998804936838864872"
246+
"version": "0.33.93.31351",
247+
"templateHash": "16444845925569233096"
248248
}
249249
},
250250
"parameters": {
@@ -383,8 +383,8 @@
383383
"metadata": {
384384
"_generator": {
385385
"name": "bicep",
386-
"version": "0.34.44.8038",
387-
"templateHash": "15569997416548251984"
386+
"version": "0.33.93.31351",
387+
"templateHash": "627756007451802146"
388388
}
389389
},
390390
"parameters": {
@@ -981,8 +981,8 @@
981981
"metadata": {
982982
"_generator": {
983983
"name": "bicep",
984-
"version": "0.34.44.8038",
985-
"templateHash": "4051638923493896337"
984+
"version": "0.33.93.31351",
985+
"templateHash": "12863612675732383951"
986986
}
987987
},
988988
"parameters": {
@@ -1210,8 +1210,8 @@
12101210
"metadata": {
12111211
"_generator": {
12121212
"name": "bicep",
1213-
"version": "0.34.44.8038",
1214-
"templateHash": "4077975888118623954"
1213+
"version": "0.33.93.31351",
1214+
"templateHash": "6455788440385967919"
12151215
}
12161216
},
12171217
"parameters": {
@@ -1696,8 +1696,8 @@
16961696
"metadata": {
16971697
"_generator": {
16981698
"name": "bicep",
1699-
"version": "0.34.44.8038",
1700-
"templateHash": "6611317231290784098"
1699+
"version": "0.33.93.31351",
1700+
"templateHash": "16935405490916431865"
17011701
}
17021702
},
17031703
"parameters": {
@@ -1874,198 +1874,20 @@
18741874
"dependsOn": [
18751875
"[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_keyvault')]"
18761876
]
1877-
},
1878-
{
1879-
"type": "Microsoft.Resources/deployments",
1880-
"apiVersion": "2022-09-01",
1881-
"name": "deploy_post_deployment_scripts",
1882-
"properties": {
1883-
"expressionEvaluationOptions": {
1884-
"scope": "inner"
1885-
},
1886-
"mode": "Incremental",
1887-
"parameters": {
1888-
"solutionName": {
1889-
"value": "[variables('solutionPrefix')]"
1890-
},
1891-
"solutionLocation": {
1892-
"value": "[parameters('secondaryLocation')]"
1893-
},
1894-
"baseUrl": {
1895-
"value": "[variables('baseUrl')]"
1896-
},
1897-
"storageAccountName": {
1898-
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_storage_account'), '2022-09-01').outputs.storageName.value]"
1899-
},
1900-
"containerName": {
1901-
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_storage_account'), '2022-09-01').outputs.storageContainer.value]"
1902-
},
1903-
"managedIdentityObjectId": {
1904-
"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]"
1905-
},
1906-
"managedIdentityClientId": {
1907-
"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]"
1908-
},
1909-
"keyVaultName": {
1910-
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.keyvaultName.value]"
1911-
},
1912-
"logAnalyticsWorkspaceResourceName": {
1913-
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry'), '2022-09-01').outputs.logAnalyticsWorkspaceResourceName.value]"
1914-
}
1915-
},
1916-
"template": {
1917-
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
1918-
"contentVersion": "1.0.0.0",
1919-
"metadata": {
1920-
"_generator": {
1921-
"name": "bicep",
1922-
"version": "0.34.44.8038",
1923-
"templateHash": "17578272684671627358"
1924-
}
1925-
},
1926-
"parameters": {
1927-
"solutionName": {
1928-
"type": "string",
1929-
"metadata": {
1930-
"description": "Solution Name"
1931-
}
1932-
},
1933-
"solutionLocation": {
1934-
"type": "string",
1935-
"metadata": {
1936-
"description": "Specifies the location for resources."
1937-
}
1938-
},
1939-
"baseUrl": {
1940-
"type": "string"
1941-
},
1942-
"managedIdentityObjectId": {
1943-
"type": "string"
1944-
},
1945-
"managedIdentityClientId": {
1946-
"type": "string"
1947-
},
1948-
"storageAccountName": {
1949-
"type": "string"
1950-
},
1951-
"containerName": {
1952-
"type": "string"
1953-
},
1954-
"containerAppName": {
1955-
"type": "string",
1956-
"defaultValue": "[format('ca-{0}', parameters('solutionName'))]"
1957-
},
1958-
"environmentName": {
1959-
"type": "string",
1960-
"defaultValue": "[format('cae-{0}', parameters('solutionName'))]"
1961-
},
1962-
"imageName": {
1963-
"type": "string",
1964-
"defaultValue": "python:3.11-alpine"
1965-
},
1966-
"setupCopyKbFiles": {
1967-
"type": "string",
1968-
"defaultValue": "[format('{0}infra/scripts/copy_kb_files.sh', parameters('baseUrl'))]"
1969-
},
1970-
"setupCreateIndexScriptsUrl": {
1971-
"type": "string",
1972-
"defaultValue": "[format('{0}infra/scripts/run_create_index_scripts.sh', parameters('baseUrl'))]"
1973-
},
1974-
"keyVaultName": {
1975-
"type": "string"
1976-
},
1977-
"logAnalyticsWorkspaceResourceName": {
1978-
"type": "string"
1979-
}
1980-
},
1981-
"resources": [
1982-
{
1983-
"type": "Microsoft.App/managedEnvironments",
1984-
"apiVersion": "2022-03-01",
1985-
"name": "[parameters('environmentName')]",
1986-
"location": "[parameters('solutionLocation')]",
1987-
"properties": {
1988-
"zoneRedundant": false,
1989-
"appLogsConfiguration": {
1990-
"destination": "log-analytics",
1991-
"logAnalyticsConfiguration": {
1992-
"customerId": "[reference(resourceId('Microsoft.OperationalInsights/workspaces', parameters('logAnalyticsWorkspaceResourceName')), '2020-10-01').customerId]",
1993-
"sharedKey": "[listKeys(resourceId('Microsoft.OperationalInsights/workspaces', parameters('logAnalyticsWorkspaceResourceName')), '2020-10-01').primarySharedKey]"
1994-
}
1995-
}
1996-
}
1997-
},
1998-
{
1999-
"type": "Microsoft.App/containerApps",
2000-
"apiVersion": "2022-03-01",
2001-
"name": "[parameters('containerAppName')]",
2002-
"location": "[parameters('solutionLocation')]",
2003-
"identity": {
2004-
"type": "UserAssigned",
2005-
"userAssignedIdentities": {
2006-
"[format('{0}', parameters('managedIdentityObjectId'))]": {}
2007-
}
2008-
},
2009-
"properties": {
2010-
"managedEnvironmentId": "[resourceId('Microsoft.App/managedEnvironments', parameters('environmentName'))]",
2011-
"configuration": {
2012-
"ingress": null,
2013-
"activeRevisionsMode": "Single"
2014-
},
2015-
"template": {
2016-
"scale": {
2017-
"minReplicas": 1,
2018-
"maxReplicas": 1
2019-
},
2020-
"containers": [
2021-
{
2022-
"name": "[parameters('containerAppName')]",
2023-
"image": "[parameters('imageName')]",
2024-
"resources": {
2025-
"cpu": 2,
2026-
"memory": "4.0Gi"
2027-
},
2028-
"command": [
2029-
"/bin/sh",
2030-
"-c",
2031-
"[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'))]"
2032-
],
2033-
"env": [
2034-
{
2035-
"name": "STORAGE_ACCOUNT_NAME",
2036-
"value": "[parameters('storageAccountName')]"
2037-
},
2038-
{
2039-
"name": "CONTAINER_NAME",
2040-
"value": "[parameters('containerName')]"
2041-
},
2042-
{
2043-
"name": "APPSETTING_WEBSITE_SITE_NAME",
2044-
"value": "DUMMY"
2045-
}
2046-
]
2047-
}
2048-
]
2049-
}
2050-
},
2051-
"dependsOn": [
2052-
"[resourceId('Microsoft.App/managedEnvironments', parameters('environmentName'))]"
2053-
]
2054-
}
2055-
]
2056-
}
2057-
},
2058-
"dependsOn": [
2059-
"[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_ai_foundry')]",
2060-
"[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_managed_identity')]",
2061-
"[extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_storage_account')]"
2062-
]
20631877
}
20641878
],
20651879
"outputs": {
20661880
"WEB_APP_URL": {
20671881
"type": "string",
20681882
"value": "[reference(extensionResourceId(format('/subscriptions/{0}/resourceGroups/{1}', subscription().subscriptionId, resourceGroup().name), 'Microsoft.Resources/deployments', 'deploy_app_service'), '2022-09-01').outputs.webAppUrl.value]"
1883+
},
1884+
"copykbfiles": {
1885+
"type": "string",
1886+
"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)]"
1887+
},
1888+
"createindex": {
1889+
"type": "string",
1890+
"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)]"
20691891
}
20701892
}
20711893
}

infra/scripts/copy_kb_files.sh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
# Variables
44
storageAccount="$1"
55
fileSystem="$2"
6-
baseUrl="$3"
7-
managedIdentityClientId="$4"
6+
# baseUrl="$3"
7+
managedIdentityClientId="$3"
88

99
zipFileName1="pdfdata.zip"
1010
extractedFolder1="pdf"
@@ -15,21 +15,21 @@ zipUrl1=${baseUrl}"infra/data/pdfdata.zip"
1515
# zipUrl2=${baseUrl}"infra/data/audio_data.zip"
1616

1717
# Create folders if they do not exist
18-
mkdir -p "/mnt/azscripts/azscriptinput/$extractedFolder1"
18+
# mkdir -p "/mnt/azscripts/azscriptinput/$extractedFolder1"
1919
# mkdir -p "/mnt/azscripts/azscriptinput/$extractedFolder2"
2020

2121
# Download the zip file
22-
curl --output /mnt/azscripts/azscriptinput/"$zipFileName1" "$zipUrl1"
22+
# curl --output /mnt/azscripts/azscriptinput/"$zipFileName1" "$zipUrl1"
2323
# curl --output /mnt/azscripts/azscriptinput/"$zipFileName2" "$zipUrl2"
2424

2525
# Extract the zip file
26-
unzip /mnt/azscripts/azscriptinput/"$zipFileName1" -d /mnt/azscripts/azscriptinput/"$extractedFolder1"
26+
unzip infra/data/"$zipFileName1" -d infra/data/"$extractedFolder1"
2727
# unzip /mnt/azscripts/azscriptinput/"$zipFileName2" -d /mnt/azscripts/azscriptinput/"$extractedFolder2"
2828

2929
echo "Script Started"
3030

3131
# Authenticate with Azure using managed identity
3232
az login --identity --client-id ${managedIdentityClientId}
3333
# Using az storage blob upload-batch to upload files with managed identity authentication, as the az storage fs directory upload command is not working with managed identity authentication.
34-
az storage blob upload-batch --account-name "$storageAccount" --destination data/"$extractedFolder1" --source /mnt/azscripts/azscriptinput/"$extractedFolder1" --auth-mode login --pattern '*' --overwrite
34+
az storage blob upload-batch --account-name "$storageAccount" --destination data/"$extractedFolder1" --source infra/data/"$extractedFolder1" --auth-mode login --pattern '*' --overwrite
3535
# az storage blob upload-batch --account-name "$storageAccount" --destination data/"$extractedFolder2" --source /mnt/azscripts/azscriptinput/"$extractedFolder2" --auth-mode login --pattern '*' --overwrite

0 commit comments

Comments
 (0)