generated from mochan-tk/Handson-LINE-Bot-Azure-GitHub-v4
-
Notifications
You must be signed in to change notification settings - Fork 37
/
main.bicep
244 lines (227 loc) · 6.62 KB
/
main.bicep
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
// playground:https://bicepdemo.z22.web.core.windows.net/
param location string = resourceGroup().location
param random string
param secret string
param access string
param containerRegistryName string
param containerVer string
param containerAppsName string = 'capp-${toLower(random)}'
var appInsightsName = 'AppInsights'
var storageAccountName = 'fnstor${toLower(substring(replace(random, '-', ''), 0, 18))}'
var containerName = 'files'
param accountName string = 'cosmos-${toLower(random)}'
var databaseName = 'SimpleDB'
var cosmosContainerName = 'Accounts'
@description('That name is the name of our application. It has to be unique.Type a name followed by your resource group name. (<name>-<resourceGroupName>)')
resource storageAccount 'Microsoft.Storage/storageAccounts@2022-09-01' = {
name: storageAccountName
location: location
sku: {
name: 'Standard_LRS'
}
kind: 'StorageV2'
properties: {
supportsHttpsTrafficOnly: true
encryption: {
services: {
file: {
keyType: 'Account'
enabled: true
}
blob: {
keyType: 'Account'
enabled: true
}
}
keySource: 'Microsoft.Storage'
}
accessTier: 'Hot'
}
}
resource container 'Microsoft.Storage/storageAccounts/blobServices/containers@2022-09-01' = {
name: '${storageAccount.name}/default/${containerName}'
properties: {
publicAccess:'Container'
}
}
// https://docs.microsoft.com/en-us/azure/cosmos-db/sql/manage-with-bicep
resource cosmosAccount 'Microsoft.DocumentDB/databaseAccounts@2022-08-15' = {
name: toLower(accountName)
location: location
kind: 'GlobalDocumentDB'
properties: {
//enableFreeTier: true
databaseAccountOfferType: 'Standard'
consistencyPolicy: {
defaultConsistencyLevel: 'Session'
}
locations: [
{
locationName: location
failoverPriority: 0
isZoneRedundant: false
}
]
capabilities: [
{
name: 'EnableServerless'
}
]
}
}
resource cosmosDB 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases@2022-08-15' = {
parent: cosmosAccount
name: databaseName
properties: {
resource: {
id: databaseName
}
}
}
resource cosmosContainer 'Microsoft.DocumentDB/databaseAccounts/sqlDatabases/containers@2022-08-15' = {
parent: cosmosDB
name: cosmosContainerName
properties: {
resource: {
id: cosmosContainerName
partitionKey: {
paths: [
'/partitionKey'
]
kind: 'Hash'
}
}
options:{}
}
}
resource containerRegistry 'Microsoft.ContainerRegistry/registries@2022-12-01' existing = {
name: containerRegistryName
}
var containerImageName = 'linebot/aca'
var containerImageTag = containerVer
// https://github.com/Azure/azure-quickstart-templates/blob/master/quickstarts/microsoft.app/container-app-scale-http/main.bicep
@description('Specifies the name of the log analytics workspace.')
param containerAppLogAnalyticsName string = 'log-${uniqueString(resourceGroup().id)}'
resource logAnalytics 'Microsoft.OperationalInsights/workspaces@2022-10-01' = {
name: containerAppLogAnalyticsName
location: location
properties: any({
retentionInDays: 30
features: {
searchVersion: 1
}
sku: {
name: 'PerGB2018'
}
})
}
resource appInsights 'Microsoft.Insights/components@2020-02-02' = {
name: appInsightsName
location: location
kind: 'web'
properties: {
Application_Type: 'web'
WorkspaceResourceId:logAnalytics.id
}
}
/*
resource managedEnvironments 'Microsoft.App/managedEnvironments@2022-10-01' = {
name: 'managedEnv'
location: location
properties: {
daprAIInstrumentationKey:appInsights.properties.InstrumentationKey
appLogsConfiguration: {
destination: 'log-analytics'
logAnalyticsConfiguration: {
customerId: logAnalytics.properties.customerId
sharedKey: logAnalytics.listKeys().primarySharedKey
}
}
}
sku: {
name: 'Consumption'
}
}
*/
// https://learn.microsoft.com/ja-jp/dotnet/orleans/deployment/deploy-to-azure-container-apps
// https://github.com/microsoft/azure-container-apps/blob/main/docs/templates/bicep/main.bicep
resource containerApps 'Microsoft.App/containerApps@2022-10-01' = {
name: containerAppsName
location: location
properties: {
managedEnvironmentId: '/subscriptions/62f5527b-7ac9-4999-bb23-6a253ad279ea/resourceGroups/20220615LineBot1/providers/Microsoft.App/managedEnvironments/managedEnv'
configuration: {
registries: [
{
server: containerRegistry.properties.loginServer
username: containerRegistry.listCredentials().username
passwordSecretRef: 'reg-pswd-d6696fb9-a98d'
}
]
secrets: [
{
name: 'reg-pswd-d6696fb9-a98d'
value: containerRegistry.listCredentials().passwords[0].value
}
]
activeRevisionsMode: 'Single'
ingress: {
external: true
transport: 'auto'
targetPort: 3000
}
}
template: {
containers: [
{
name: 'line-bot-container-apps'
image: '${containerRegistry.name}.azurecr.io/${containerImageName}:${containerImageTag}'
command: []
resources: {
cpu: json('0.5')
memory: '1Gi'
}
env: [
{
name: 'CHANNEL_SECRET'
value: secret
}
{
name: 'CHANNEL_ACCESS_TOKEN'
value: access
}
{
name: 'STORAGE_CONNECTION_STRING'
value: 'DefaultEndpointsProtocol=https;AccountName=${storageAccount.name};EndpointSuffix=${environment().suffixes.storage};AccountKey=${listKeys(storageAccount.id, storageAccount.apiVersion).keys[0].value}'
}
{
name: 'COSMOSDB_ACCOUNT'
value: cosmosAccount.properties.documentEndpoint
}
{
name: 'COSMOSDB_KEY'
value: cosmosAccount.listKeys().primaryMasterKey
}
{
name: 'COSMOSDB_DATABASENAME'
value: databaseName
}
{
name: 'COSMOSDB_CONTAINERNAME'
value: cosmosContainerName
}
{
name: 'COSMOSDB_CONNECTION_STRING'
value: 'AccountEndpoint=${cosmosAccount.properties.documentEndpoint};AccountKey=${cosmosAccount.listKeys().primaryMasterKey};'
}
]
}
]
scale: {
maxReplicas: 1
minReplicas: 1
}
}
}
}
output acaUrl string = 'https://${containerApps.properties.configuration.ingress.fqdn}'