-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathazuredeploy.bicep
More file actions
388 lines (352 loc) · 10.4 KB
/
azuredeploy.bicep
File metadata and controls
388 lines (352 loc) · 10.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
/* ***************************************************************
Azure Cosmos DB + Azure OpenAI Python developer guide lab
******************************************************************
This Azure resource deployment template uses some of the following practices:
- [Abbrevation examples for Azure resources](https://learn.microsoft.com/en-us/azure/cloud-adoption-framework/ready/azure-best-practices/resource-abbreviations)
*/
/* *************************************************************** */
/* Parameters */
/* *************************************************************** */
@description('Location where all resources will be deployed. This value defaults to the **East US** region.')
@allowed([
'eastus'
'francecentral'
'southcentralus'
'uksouth'
'westeurope'
])
param location string = 'eastus'
@description('''
Unique name for the deployed services below. Max length 17 characters, alphanumeric only:
- Azure Cosmos DB for MongoDB vCore
- Azure OpenAI Service
The name defaults to a unique string generated from the resource group identifier. Prefixed with
**dg** 'developer guide' as the id may start with a number which is an invalid name for
many resources.
''')
@maxLength(17)
param name string = 'dg${uniqueString(resourceGroup().id)}'
@description('Specifies the SKU for the Azure App Service plan. Defaults to **B1**')
@allowed([
'B1'
'S1'
'P0v3'
])
param appServiceSku string = 'B1' //'P0v3' for production workloads
@description('Specifies the SKU for the Azure OpenAI resource. Defaults to **S0**')
@allowed([
'S0'
])
param openAiSku string = 'S0'
@description('MongoDB vCore user Name. No dashes.')
param mongoDbUserName string
@description('MongoDB vCore password. 8-256 characters, 3 of the following: lower case, upper case, numeric, symbol.')
@minLength(8)
@maxLength(256)
@secure()
param mongoDbPassword string
@description('Azure Container Registry SKU. Defaults to **Basic**')
param acrSku string = 'Basic'
/* *************************************************************** */
/* Variables */
/* *************************************************************** */
var openAiSettings = {
name: '${name}-openai'
sku: openAiSku
maxConversationTokens: '100'
maxCompletionTokens: '500'
completionsModel: {
name: 'gpt-35-turbo'
version: '0613'
deployment: {
name: 'completions'
}
sku: {
name: 'Standard'
capacity: 120
}
}
embeddingsModel: {
name: 'text-embedding-ada-002'
version: '2'
deployment: {
name: 'embeddings'
}
sku: {
name: 'Standard'
capacity: 120
}
}
}
var mongovCoreSettings = {
mongoClusterName: '${name}-mongo'
mongoClusterLogin: mongoDbUserName
mongoClusterPassword: mongoDbPassword
}
var appServiceSettings = {
plan: {
name: '${name}-web'
sku: appServiceSku
}
web: {
name: '${name}-web'
git: {
repo: 'https://github.com/AzureCosmosDB/Azure-OpenAI-Developer-Guide-Front-End.git'
branch: 'main'
}
}
}
/* *************************************************************** */
/* Azure Cosmos DB for MongoDB vCore */
/* *************************************************************** */
resource mongoCluster 'Microsoft.DocumentDB/mongoClusters@2023-03-01-preview' = {
name: mongovCoreSettings.mongoClusterName
location: location
properties: {
administratorLogin: mongovCoreSettings.mongoClusterLogin
administratorLoginPassword: mongovCoreSettings.mongoClusterPassword
serverVersion: '5.0'
nodeGroupSpecs: [
{
kind: 'Shard'
sku: 'M30'
diskSizeGB: 128
enableHa: false
nodeCount: 1
}
]
}
}
resource mongoFirewallRulesAllowAzure 'Microsoft.DocumentDB/mongoClusters/firewallRules@2023-03-01-preview' = {
parent: mongoCluster
name: 'allowAzure'
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '0.0.0.0'
}
}
resource mongoFirewallRulesAllowAll 'Microsoft.DocumentDB/mongoClusters/firewallRules@2023-03-01-preview' = {
parent: mongoCluster
name: 'allowAll'
properties: {
startIpAddress: '0.0.0.0'
endIpAddress: '255.255.255.255'
}
}
/* *************************************************************** */
/* Azure OpenAI */
/* *************************************************************** */
resource openAiAccount 'Microsoft.CognitiveServices/accounts@2023-05-01' = {
name: openAiSettings.name
location: location
sku: {
name: openAiSettings.sku
}
kind: 'OpenAI'
properties: {
customSubDomainName: openAiSettings.name
publicNetworkAccess: 'Enabled'
}
}
resource openAiEmbeddingsModelDeployment 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = {
parent: openAiAccount
name: openAiSettings.embeddingsModel.deployment.name
sku: {
name: openAiSettings.embeddingsModel.sku.name
capacity: openAiSettings.embeddingsModel.sku.capacity
}
properties: {
model: {
format: 'OpenAI'
name: openAiSettings.embeddingsModel.name
version: openAiSettings.embeddingsModel.version
}
}
}
resource openAiCompletionsModelDeployment 'Microsoft.CognitiveServices/accounts/deployments@2023-05-01' = {
parent: openAiAccount
name: openAiSettings.completionsModel.deployment.name
dependsOn: [
openAiEmbeddingsModelDeployment
]
sku: {
name: openAiSettings.completionsModel.sku.name
capacity: openAiSettings.completionsModel.sku.capacity
}
properties: {
model: {
format: 'OpenAI'
name: openAiSettings.completionsModel.name
version: openAiSettings.completionsModel.version
}
}
}
/* *************************************************************** */
/* Logging and instrumentation */
/* *************************************************************** */
resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2021-06-01' = {
name: '${name}-loganalytics'
location: location
properties: {
sku: {
name: 'PerGB2018'
}
}
}
resource appServiceWebInsights 'Microsoft.Insights/components@2020-02-02' = {
name: '${appServiceSettings.web.name}-appi'
location: location
kind: 'web'
properties: {
Application_Type: 'web'
WorkspaceResourceId: logAnalytics.id
}
}
/* *************************************************************** */
/* App Plan Hosting - Azure App Service Plan */
/* *************************************************************** */
resource appServicePlan 'Microsoft.Web/serverfarms@2022-03-01' = {
name: '${appServiceSettings.plan.name}-asp'
location: location
sku: {
name: appServiceSettings.plan.sku
}
kind: 'linux'
properties: {
reserved: true
}
}
/* *************************************************************** */
/* Front-end Web App Hosting - Azure App Service */
/* *************************************************************** */
resource appServiceWeb 'Microsoft.Web/sites@2022-03-01' = {
name: appServiceSettings.web.name
location: location
properties: {
serverFarmId: appServicePlan.id
httpsOnly: true
siteConfig: {
linuxFxVersion: 'NODE|20-lts'
appCommandLine: 'pm2 serve /home/site/wwwroot/dist --no-daemon --spa'
alwaysOn: true
}
}
}
resource appServiceWebSettings 'Microsoft.Web/sites/config@2022-03-01' = {
parent: appServiceWeb
name: 'appsettings'
kind: 'string'
properties: {
APPINSIGHTS_INSTRUMENTATIONKEY: appServiceWebInsights.properties.InstrumentationKey
API_ENDPOINT: 'https://${backendApiContainerApp.properties.configuration.ingress.fqdn}'
}
}
resource appServiceWebDeployment 'Microsoft.Web/sites/sourcecontrols@2021-03-01' = {
parent: appServiceWeb
name: 'web'
properties: {
repoUrl: appServiceSettings.web.git.repo
branch: appServiceSettings.web.git.branch
isManualIntegration: true
}
}
/* *************************************************************** */
/* Registry for Back-end API Image - Azure Container Registry */
/* *************************************************************** */
resource containerRegistry 'Microsoft.ContainerRegistry/registries@2023-01-01-preview' = {
name: replace('${name}registry','-', '')
location: location
sku: {
name: acrSku
}
properties: {
adminUserEnabled: true
}
}
/* *************************************************************** */
/* Container environment - Azure Container App Environment */
/* *************************************************************** */
resource containerAppEnvironment 'Microsoft.App/managedEnvironments@2023-05-01' = {
name: '${name}-containerappenv'
location: location
properties: {
appLogsConfiguration: {
destination: 'log-analytics'
logAnalyticsConfiguration: {
customerId: logAnalytics.properties.customerId
sharedKey: logAnalytics.listKeys().primarySharedKey
}
}
workloadProfiles: [
{
name: 'Warm'
minimumCount: 1
maximumCount: 10
workloadProfileType: 'E4'
}
]
infrastructureResourceGroup: 'ME_${resourceGroup().name}'
}
}
/* *************************************************************** */
/* Back-end API App Application - Azure Container App */
/* deploys default hello world */
/* *************************************************************** */
resource backendApiContainerApp 'Microsoft.App/containerApps@2023-05-01' = {
name: '${name}-api'
location: location
properties: {
environmentId: containerAppEnvironment.id
configuration: {
ingress: {
external: true
targetPort: 80
allowInsecure: false
traffic: [
{
latestRevision: true
weight: 100
}
]
corsPolicy: {
allowCredentials: false
allowedHeaders: [
'*'
]
allowedOrigins: [
'*'
]
}
}
registries: [
{
server: containerRegistry.name
username: containerRegistry.properties.loginServer
passwordSecretRef: 'container-registry-password'
}
]
secrets: [
{
name: 'container-registry-password'
value: containerRegistry.listCredentials().passwords[0].value
}
]
}
template: {
containers: [
{
name: 'hello-world'
image: 'mcr.microsoft.com/azuredocs/containerapps-helloworld:latest'
resources: {
cpu: 1
memory: '2Gi'
}
}
]
scale: {
minReplicas: 1
maxReplicas: 1
}
}
}
}