Skip to content

Commit aae1e12

Browse files
committed
Updates to get Bicep functioning
1 parent 2289b94 commit aae1e12

File tree

3 files changed

+132
-131
lines changed

3 files changed

+132
-131
lines changed

Labs/deploy/azuredeploy.bicep

Lines changed: 129 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,16 @@ This Azure resource deployment template uses some of the following practices:
2222
param location string = 'eastus'
2323

2424
@description('''
25-
Unique name for the deployed services below. Max length 15 characters, alphanumeric only:
25+
Unique name for the deployed services below. Max length 17 characters, alphanumeric only:
2626
- Azure Cosmos DB for MongoDB vCore
2727
- Azure OpenAI Service
2828
29-
The name defaults to a unique string generated from the resource group identifier.
29+
The name defaults to a unique string generated from the resource group identifier. Prefixed with
30+
**dg** 'developer guide' as the id may start with a number which is an invalid name for
31+
many resources.
3032
''')
31-
@maxLength(15)
32-
param name string = uniqueString(resourceGroup().id)
33+
@maxLength(17)
34+
param name string = 'dg${uniqueString(resourceGroup().id)}'
3335

3436
@description('Specifies the SKU for the Azure App Service plan. Defaults to **B1**')
3537
@allowed([
@@ -54,15 +56,8 @@ param mongoDbUserName string
5456
@secure()
5557
param mongoDbPassword string
5658

57-
58-
59-
/*
60-
@description('Git repository URL for the application source. This defaults to the [`solliancenet/cosmos-db-openai-python-dev-guide-labs`](https://github.com/solliancenet/cosmos-db-openai-python-dev-guide-labs.git) repository.')
61-
param appGitRepository string = 'https://github.com/solliancenet/cosmos-db-openai-python-dev-guide-labs.git'
62-
63-
@description('Git repository branch for the application source. This defaults to the [**main** branch of the `solliancenet/cosmos-db-openai-python-dev-guide-labs`](https://github.com/solliancenet/cosmos-db-openai-python-dev-guide-labs/tree/main) repository.')
64-
param appGetRepositoryBranch string = 'main'
65-
*/
59+
@description('Azure Container Registry SKU. Defaults to **Basic**')
60+
param acrSku string = 'Basic'
6661

6762
/* *************************************************************** */
6863
/* Variables */
@@ -79,23 +74,28 @@ var openAiSettings = {
7974
deployment: {
8075
name: 'completions'
8176
}
77+
sku: {
78+
name: 'Standard'
79+
capacity: 120
80+
}
8281
}
8382
embeddingsModel: {
8483
name: 'text-embedding-ada-002'
8584
version: '2'
8685
deployment: {
8786
name: 'embeddings'
8887
}
88+
sku: {
89+
name: 'Standard'
90+
capacity: 150
91+
}
8992
}
9093
}
9194

9295
var mongovCoreSettings = {
9396
mongoClusterName: '${name}-mongo'
9497
mongoClusterLogin: mongoDbUserName
9598
mongoClusterPassword: mongoDbPassword
96-
97-
mongoDatabaseName: 'cosmic_works'
98-
mongoCollectionNames: 'products,customers,sales'
9999
}
100100

101101
var appServiceSettings = {
@@ -109,18 +109,9 @@ var appServiceSettings = {
109109
repo: 'https://github.com/crpietschmann/cosmos-db-dev-guide-frontend-app.git'
110110
branch: 'main'
111111
}
112-
}
113-
api: {
114-
name: '${name}-api'
115-
git: {
116-
repo: 'https://github.com/crpietschmann/cosmos-db-dev-guide-backend-app-python.git'
117-
branch: 'main'
118-
}
119-
}
112+
}
120113
}
121114

122-
123-
124115
/* *************************************************************** */
125116
/* Azure Cosmos DB for MongoDB vCore */
126117
/* *************************************************************** */
@@ -167,11 +158,11 @@ resource mongoFirewallRulesAllowAll 'Microsoft.DocumentDB/mongoClusters/firewall
167158
/* Azure OpenAI */
168159
/* *************************************************************** */
169160

170-
resource openAiAccount 'Microsoft.CognitiveServices/accounts@2022-12-01' = {
161+
resource openAiAccount 'Microsoft.CognitiveServices/accounts@2023-05-01' = {
171162
name: openAiSettings.name
172163
location: location
173164
sku: {
174-
name: openAiSettings.sku
165+
name: openAiSettings.sku
175166
}
176167
kind: 'OpenAI'
177168
properties: {
@@ -180,45 +171,64 @@ resource openAiAccount 'Microsoft.CognitiveServices/accounts@2022-12-01' = {
180171
}
181172
}
182173

183-
resource openAiEmbeddingsModelDeployment 'Microsoft.CognitiveServices/accounts/deployments@2022-12-01' = {
174+
resource openAiEmbeddingsModelDeployment 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = {
184175
parent: openAiAccount
185-
name: openAiSettings.embeddingsModel.deployment.name
176+
name: openAiSettings.embeddingsModel.deployment.name
177+
sku: {
178+
name: openAiSettings.embeddingsModel.sku.name
179+
capacity: openAiSettings.embeddingsModel.sku.capacity
180+
}
186181
properties: {
187182
model: {
188183
format: 'OpenAI'
189184
name: openAiSettings.embeddingsModel.name
190185
version: openAiSettings.embeddingsModel.version
191186
}
192-
scaleSettings: {
193-
scaleType: 'Standard'
194-
}
195187
}
196188
}
197189

198-
resource openAiCompletionsModelDeployment 'Microsoft.CognitiveServices/accounts/deployments@2022-12-01' = {
190+
resource openAiCompletionsModelDeployment 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = {
199191
parent: openAiAccount
200192
name: openAiSettings.completionsModel.deployment.name
193+
sku: {
194+
name: openAiSettings.completionsModel.sku.name
195+
capacity: openAiSettings.completionsModel.sku.capacity
196+
}
201197
properties: {
202198
model: {
203199
format: 'OpenAI'
204200
name: openAiSettings.completionsModel.name
205201
version: openAiSettings.completionsModel.version
206-
}
207-
scaleSettings: {
208-
scaleType: 'Standard'
209-
}
202+
}
210203
}
211-
dependsOn: [
212-
openAiEmbeddingsModelDeployment
213-
]
214204
}
215205

206+
/* *************************************************************** */
207+
/* Logging and instrumentation */
208+
/* *************************************************************** */
216209

210+
resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2021-06-01' = {
211+
name: '${name}-loganalytics'
212+
location: location
213+
properties: {
214+
sku: {
215+
name: 'PerGB2018'
216+
}
217+
}
218+
}
219+
resource appServiceWebInsights 'Microsoft.Insights/components@2020-02-02' = {
220+
name: '${appServiceSettings.web.name}-appi'
221+
location: location
222+
kind: 'web'
223+
properties: {
224+
Application_Type: 'web'
225+
WorkspaceResourceId: logAnalytics.id
226+
}
227+
}
217228

218229
/* *************************************************************** */
219230
/* App Plan Hosting - Azure App Service Plan */
220231
/* *************************************************************** */
221-
222232
resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
223233
name: '${appServiceSettings.plan.name}-asp'
224234
location: location
@@ -250,16 +260,6 @@ resource appServiceWeb 'Microsoft.Web/sites@2022-03-01' = {
250260
}
251261
}
252262

253-
resource appServiceWebSettings 'Microsoft.Web/sites/config@2022-03-01' = {
254-
parent: appServiceWeb
255-
name: 'appsettings'
256-
kind: 'string'
257-
properties: {
258-
APPINSIGHTS_INSTRUMENTATIONKEY: appServiceWebInsights.properties.InstrumentationKey
259-
API_ENDPOINT: 'https://${appServiceApi.properties.defaultHostName}'
260-
}
261-
}
262-
263263
resource appServiceWebConnectionStrings 'Microsoft.Web/sites/config@2022-03-01' = {
264264
parent: appServiceWeb
265265
name: 'connectionstrings'
@@ -272,15 +272,6 @@ resource appServiceWebConnectionStrings 'Microsoft.Web/sites/config@2022-03-01'
272272
}
273273
}
274274

275-
resource appServiceWebInsights 'Microsoft.Insights/components@2020-02-02' = {
276-
name: '${appServiceSettings.web.name}-appi'
277-
location: location
278-
kind: 'web'
279-
properties: {
280-
Application_Type: 'web'
281-
}
282-
}
283-
284275
resource appServiceWebDeployment 'Microsoft.Web/sites/sourcecontrols@2021-03-01' = {
285276
parent: appServiceWeb
286277
name: 'web'
@@ -289,89 +280,99 @@ resource appServiceWebDeployment 'Microsoft.Web/sites/sourcecontrols@2021-03-01'
289280
branch: appServiceSettings.web.git.branch
290281
isManualIntegration: true
291282
}
292-
dependsOn: [
293-
appServiceWebSettings
294-
]
295283
}
296284

297285

298286
/* *************************************************************** */
299-
/* Back-end API Hosting - Azure App Service */
287+
/* Registry for Back-end API Image - Azure Container Registry */
300288
/* *************************************************************** */
301-
302-
resource appServiceApi 'Microsoft.Web/sites@2022-03-01' = {
303-
name: appServiceSettings.api.name
289+
resource containerRegistry 'Microsoft.ContainerRegistry/registries@2023-01-01-preview' = {
290+
name: replace('${name}registry','-', '')
304291
location: location
305-
properties: {
306-
serverFarmId: appServicePlan.id
307-
httpsOnly: true
308-
siteConfig: {
309-
linuxFxVersion: 'PYTHON|3.12'
310-
alwaysOn: true
311-
httpLoggingEnabled: true
312-
appCommandLine: 'startup.txt'
313-
cors: {
314-
allowedOrigins: [
315-
'*'
316-
]
317-
supportCredentials: false
318-
}
319-
}
292+
sku: {
293+
name: acrSku
320294
}
321-
}
322-
323-
resource appServiceApiSettings 'Microsoft.Web/sites/config@2022-03-01' = {
324-
parent: appServiceApi
325-
name: 'appsettings'
326-
kind: 'string'
327295
properties: {
328-
WEBSITES_PORT: '8000'
329-
ENABLE_ORYX_BUILD: 'true'
330-
SCM_DO_BUILD_DURING_DEPLOYMENT: 'true'
331-
WEBSITE_ENABLE_DEFAULT_CODE_PROFILER: 'true'
332-
APPINSIGHTS_INSTRUMENTATIONKEY: appServiceWebInsights.properties.InstrumentationKey
333-
APPINSIGHTS_PROFILERFEATURE_VERSION: '1.0.0'
334-
DiagnosticServices_EXTENSION_VERSION: '~3'
335-
WEBSITE_HTTPLOGGING_RETENTION_DAYS: '7'
336-
OPENAI__ENDPOINT: openAiAccount.properties.endpoint
337-
OPENAI__KEY: openAiAccount.listKeys().key1
338-
OPENAI__EMBEDDINGSDEPLOYMENT: openAiEmbeddingsModelDeployment.name
339-
OPENAI__MAXTOKENS: '8191'
340-
MONGODB__DATABASENAME: mongovCoreSettings.mongoDatabaseName
341-
MONGODB__COLLECTIONNAMES: mongovCoreSettings.mongoCollectionNames
296+
adminUserEnabled: true
342297
}
343298
}
344299

345-
resource appServiceApiConnectionStrings 'Microsoft.Web/sites/config@2022-03-01' = {
346-
parent: appServiceApi
347-
name: 'connectionstrings'
348-
kind: 'string'
300+
/* *************************************************************** */
301+
/* Container environment - Azure Container App Environment */
302+
/* *************************************************************** */
303+
resource containerAppEnvironment 'Microsoft.App/managedEnvironments@2023-05-01' = {
304+
name: '${name}-containerappenv'
305+
location: location
349306
properties: {
350-
MONGODB__CONNECTION: {
351-
value: 'mongodb+srv://${mongovCoreSettings.mongoClusterLogin}:${mongovCoreSettings.mongoClusterPassword}@${mongovCoreSettings.mongoClusterName}.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retrywrites=false&maxIdleTimeMS=120000'
352-
type: 'Custom'
307+
appLogsConfiguration: {
308+
destination: 'log-analytics'
309+
logAnalyticsConfiguration: {
310+
customerId: logAnalytics.properties.customerId
311+
sharedKey: logAnalytics.listKeys().primarySharedKey
312+
}
353313
}
314+
workloadProfiles: [
315+
{
316+
name: 'Warm'
317+
minimumCount: 1
318+
maximumCount: 10
319+
workloadProfileType: 'E4'
320+
}
321+
]
322+
infrastructureResourceGroup: 'ME_${resourceGroup().name}'
354323
}
355324
}
356325

357-
resource appServiceApiDeployment 'Microsoft.Web/sites/sourcecontrols@2021-03-01' = {
358-
parent: appServiceApi
359-
name: 'web'
326+
/* *************************************************************** */
327+
/* Back-end API App Application - Azure Container App */
328+
/* deploys default hello world */
329+
/* *************************************************************** */
330+
resource backendApiContainerApp 'Microsoft.App/containerApps@2023-05-01' = {
331+
name: '${name}-api'
332+
location: location
360333
properties: {
361-
repoUrl: appServiceSettings.api.git.repo
362-
branch: appServiceSettings.api.git.branch
363-
isManualIntegration: true
334+
environmentId: containerAppEnvironment.id
335+
configuration: {
336+
ingress: {
337+
external: true
338+
targetPort: 80
339+
allowInsecure: false
340+
traffic: [
341+
{
342+
latestRevision: true
343+
weight: 100
344+
}
345+
]
346+
}
347+
registries: [
348+
{
349+
server: containerRegistry.name
350+
username: containerRegistry.properties.loginServer
351+
passwordSecretRef: 'container-registry-password'
352+
}
353+
]
354+
secrets: [
355+
{
356+
name: 'container-registry-password'
357+
value: containerRegistry.listCredentials().passwords[0].value
358+
}
359+
]
360+
}
361+
template: {
362+
containers: [
363+
{
364+
name: 'hello-world'
365+
image: 'mcr.microsoft.com/azuredocs/containerapps-helloworld:latest'
366+
resources: {
367+
cpu: 1
368+
memory: '2Gi'
369+
}
370+
}
371+
]
372+
scale: {
373+
minReplicas: 1
374+
maxReplicas: 1
375+
}
376+
}
364377
}
365-
dependsOn: [
366-
appServiceApiSettings
367-
]
368378
}
369-
370-
371-
/* *************************************************************** */
372-
/* Outputs */
373-
/* *************************************************************** */
374-
375-
output deployedWebUrl string = appServiceWeb.properties.defaultHostName
376-
377-
output deployedApiUrl string = appServiceApi.properties.defaultHostName

Labs/deploy/azuredeploy.parameters.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"value": "eastus"
77
},
88
"name": {
9-
"value": "mongodb-aoai"
9+
"value": "mongo-devguide"
1010
},
1111
"openAiSku": {
1212
"value": "S0"

0 commit comments

Comments
 (0)