Skip to content

Commit

Permalink
Update deployment templates and scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
kbeaugrand committed Aug 14, 2023
1 parent 4db382f commit eae6062
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 3 deletions.
13 changes: 11 additions & 2 deletions scripts/deploy/deploy-azure.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,15 @@ param(
# SKU for the Azure App Service plan
$WebAppServiceSku = "B1",

[ValidateSet("Volatile", "AzureCognitiveSearch", "Qdrant")]
[ValidateSet("Volatile", "AzureCognitiveSearch", "Qdrant", "Postgres")]
[string]
# What method to use to persist embeddings
$MemoryStore = "AzureCognitiveSearch",

[SecureString]
# Password for the Postgres database
$SqlAdminPassword = '',

[switch]
# Don't deploy Cosmos DB for chat storage - Use volatile memory instead
$NoCosmosDb,
Expand Down Expand Up @@ -87,6 +91,10 @@ if ($AIService -eq "OpenAI" -and !$AIApiKey) {
exit 1
}

if ($MemoryStore -eq "Postgres" -and !$SqlAdminPassword) {
exit 1
}

$jsonConfig = "
{
`\`"webAppServiceSku`\`": { `\`"value`\`": `\`"$WebAppServiceSku`\`" },
Expand All @@ -97,7 +105,8 @@ $jsonConfig = "
`\`"deployNewAzureOpenAI`\`": { `\`"value`\`": $(If ($DeployAzureOpenAI) {"true"} Else {"false"}) },
`\`"memoryStore`\`": { `\`"value`\`": `\`"$MemoryStore`\`" },
`\`"deployCosmosDB`\`": { `\`"value`\`": $(If (!($NoCosmosDb)) {"true"} Else {"false"}) },
`\`"deploySpeechServices`\`": { `\`"value`\`": $(If (!($NoSpeechServices)) {"true"} Else {"false"}) }
`\`"deploySpeechServices`\`": { `\`"value`\`": $(If (!($NoSpeechServices)) {"true"} Else {"false"}) },
`\`"sqlAdminPassword`\`": { `\`"value`\`": `\`"$(ConvertFrom-SecureString $SqlAdminPassword -AsPlainText)`\`" }
}
"

Expand Down
16 changes: 15 additions & 1 deletion scripts/deploy/deploy-azure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ usage() {
echo " -wr, --web-app-region WEB_APP_REGION Region to deploy to the static web app into. This must be a region that supports static web apps. (default: \"West US 2\")"
echo " -a, --app-service-sku WEB_APP_SVC_SKU SKU for the Azure App Service plan (default: \"B1\")"
echo " -ms, --memory-store Method to use to persist embeddings. Valid values are"
echo " \"AzureCognitiveSearch\" (default), \"Qdrant\" and \"Volatile\""
echo " \"AzureCognitiveSearch\" (default), \"Qdrant\", \"Postgres\" and \"Volatile\""
echo " -sap, --sql-admin-password Password for the PostgreSQL Server admin user"
echo " -nc, --no-cosmos-db Don't deploy Cosmos DB for chat storage - Use volatile memory instead"
echo " -ns, --no-speech-services Don't deploy Speech Services to enable speech as chat input"
echo " -dd, --debug-deployment Switches on verbose template deployment output"
Expand Down Expand Up @@ -84,6 +85,11 @@ while [[ $# -gt 0 ]]; do
MEMORY_STORE=="$2"
shift
;;
-sap|--sql-admin-password)
SQL_ADMIN_PASSWORD="$2"
shift
shift
;;
-nc|--no-cosmos-db)
NO_COSMOS_DB=true
shift
Expand Down Expand Up @@ -152,6 +158,13 @@ if [[ "${AI_SERVICE_TYPE,,}" = "openai" ]] && [[ -z "$AI_SERVICE_KEY" ]]; then
exit 1
fi

# If MEMORY_STORE is Postges, then SQL_ADMIN_PASSWORD is mandatory
if [[ "${MEMORY_STORE,,}" = "postgres" ]] && [[ -z "$SQL_ADMIN_PASSWORD" ]]; then
echo "When --memory-store is 'Postgres', --sql-admin-password must be set."
usage
exit 1
fi

# If resource group is not set, then set it to rg-DEPLOYMENT_NAME
if [ -z "$RESOURCE_GROUP" ]; then
RESOURCE_GROUP="rg-${DEPLOYMENT_NAME}"
Expand Down Expand Up @@ -187,6 +200,7 @@ JSON_CONFIG=$(cat << EOF
"aiEndpoint": { "value": "$([ ! -z "$AI_ENDPOINT" ] && echo "$AI_ENDPOINT")" },
"deployNewAzureOpenAI": { "value": $([ "$NO_NEW_AZURE_OPENAI" = true ] && echo "false" || echo "true") },
"memoryStore": { "value": "$MEMORY_STORE" },
"sqlAdminPassword": { "value": "$SQL_ADMIN_PASSWORD" },
"deployCosmosDB": { "value": $([ "$NO_COSMOS_DB" = true ] && echo "false" || echo "true") },
"deploySpeechServices": { "value": $([ "$NO_SPEECH_SERVICES" = true ] && echo "false" || echo "true") }
}
Expand Down
89 changes: 89 additions & 0 deletions scripts/deploy/main.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ param deployCosmosDB bool = true
'Volatile'
'AzureCognitiveSearch'
'Qdrant'
'Postgres'
])
param memoryStore string = 'Volatile'

Expand All @@ -78,6 +79,10 @@ var uniqueName = '${name}-${rgIdHash}'
@description('Name of the Azure Storage file share to create')
var storageFileShareName = 'aciqdrantshare'

@description('PostgreSQL admin password')
@secure()
param sqlAdminPassword string = newGuid()

resource openAI 'Microsoft.CognitiveServices/accounts@2022-12-01' = if (deployNewAzureOpenAI) {
name: 'ai-${uniqueName}'
location: location
Expand Down Expand Up @@ -250,6 +255,10 @@ resource appServiceWebConfig 'Microsoft.Web/sites/config@2022-09-01' = {
name: 'MemoryStore:AzureCognitiveSearch:Key'
value: memoryStore == 'AzureCognitiveSearch' ? azureCognitiveSearch.listAdminKeys().primaryKey : ''
}
{
name: 'MemoryStore:Postgres:ConnectionString'
value: memoryStore == 'Postgres' ? 'Host=${postgreServerGroup.properties.serverNames[0].fullyQualifiedDomainName}:5432;Username=citus;Password=${sqlAdminPassword};Database=citus' : ''
}
{
name: 'AzureSpeech:Region'
value: location
Expand Down Expand Up @@ -501,6 +510,16 @@ resource virtualNetwork 'Microsoft.Network/virtualNetworks@2021-05-01' = {
privateLinkServiceNetworkPolicies: 'Enabled'
}
}
{
name: 'postgresSubnet'
properties: {
addressPrefix: '10.0.3.0/24'
serviceEndpoints: []
delegations: []
privateEndpointNetworkPolicies: 'Disabled'
privateLinkServiceNetworkPolicies: 'Enabled'
}
}
]
}
}
Expand Down Expand Up @@ -703,6 +722,76 @@ resource memorySourcesContainer 'Microsoft.DocumentDB/databaseAccounts/sqlDataba
}
}

resource postgreServerGroup 'Microsoft.DBforPostgreSQL/serverGroupsv2@2022-11-08' = if (memoryStore == 'Postgres') {
name: 'pg-${uniqueName}'
location: location
properties: {
postgresqlVersion: '15'
administratorLoginPassword: sqlAdminPassword
enableHa: false
coordinatorVCores: 1
coordinatorServerEdition: 'BurstableMemoryOptimized'
coordinatorStorageQuotaInMb: 32768
nodeVCores: 4
nodeCount: 0
nodeStorageQuotaInMb: 524288
nodeEnablePublicIpAccess: false
}
}

resource postgresDNSZone 'Microsoft.Network/privateDnsZones@2020-06-01' = if (memoryStore == 'Postgres') {
name: 'privatelink.postgres.cosmos.azure.com'
location: 'global'
}

resource postgresPrivateEndpoint 'Microsoft.Network/privateEndpoints@2023-04-01' = if (memoryStore == 'Postgres') {
name: 'pg-${uniqueName}-pe'
location: location
properties: {
subnet: {
id: virtualNetwork.properties.subnets[2].id
}
privateLinkServiceConnections: [
{
name: 'postgres'
properties: {
privateLinkServiceId: postgreServerGroup.id
groupIds: [
'coordinator'
]
}
}
]
}
}

resource postgresVirtualNetworkLink 'Microsoft.Network/privateDnsZones/virtualNetworkLinks@2020-06-01' = if (memoryStore == 'Postgres') {
parent: postgresDNSZone
name: 'pg-${uniqueName}-vnl'
location: 'global'
properties: {
virtualNetwork: {
id: virtualNetwork.id
}
registrationEnabled: true
}
}

resource postgresPrivateDnsZoneGroup 'Microsoft.Network/privateEndpoints/privateDnsZoneGroups@2023-04-01' = if (memoryStore == 'Postgres') {
#disable-next-line use-parent-property
name: '${postgresPrivateEndpoint.name}/default'
properties: {
privateDnsZoneConfigs: [
{
name: 'postgres'
properties: {
privateDnsZoneId: postgresDNSZone.id
}
}
]
}
}

resource speechAccount 'Microsoft.CognitiveServices/accounts@2022-12-01' = if (deploySpeechServices) {
name: 'cog-${uniqueName}'
location: location
Expand Down

0 comments on commit eae6062

Please sign in to comment.