-
Notifications
You must be signed in to change notification settings - Fork 6
/
main.bicep
124 lines (109 loc) · 3.01 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
targetScope = 'resourceGroup'
param location string = resourceGroup().location
@minLength(1)
@maxLength(64)
@description('Name of containerapp')
param appName string
@minLength(1)
@maxLength(64)
@description('Container environment name')
param containerAppsEnvironmentName string
@description('Container registry username')
param registryUsername string
@secure()
@description('Container registry password')
param registryPassword string
var registryPasswordRef = 'container-registry-password'
@allowed([
'blue'
'green'
])
@description('Name of the label that gets 100% of the traffic')
param productionLabel string
@description('BuildId')
param buildID string
@minLength(1)
@maxLength(64)
@description('CommitId for blue revision')
param blueCommitID string
@maxLength(64)
@description('CommitId for green revision')
param greenCommitID string = ''
@maxLength(64)
@description('CommitId for the latest deployed revision')
param latestCommitId string
resource containerAppsEnvironment 'Microsoft.App/managedEnvironments@2022-03-01' = {
name: containerAppsEnvironmentName
location: location
properties: {
}
}
resource blueGreenDeploymentApp 'Microsoft.App/containerApps@2023-05-01' = {
name: appName
location: location
tags: {
blueCommitID: blueCommitID
greenCommitID: greenCommitID
latestCommitId: latestCommitId
productionLabel: productionLabel
}
properties: {
configuration: {
activeRevisionsMode: 'multiple'
ingress: {
external: true
targetPort: 3000
traffic: !empty(blueCommitID) && !empty(greenCommitID) ? [
{
revisionName: '${appName}--${greenCommitID}'
label: 'green'
weight: productionLabel == 'green' ? 100 : 0
}
{
revisionName: '${appName}--${blueCommitID}'
label: 'blue'
weight: productionLabel == 'blue' ? 100 : 0
}
] :[
{
revisionName: '${appName}--${blueCommitID}'
label: 'blue'
weight: 100
}
]
}
maxInactiveRevisions: 10 // remove old inactive revisions, depends on company policy and how many revisions you want to keep
registries: [
{
passwordSecretRef: registryPasswordRef
server: 'registry.hub.docker.com'
username: registryUsername
}
]
secrets: [
{
name: registryPasswordRef
value: registryPassword
}
]
}
environmentId: containerAppsEnvironment.id
template: {
containers: [
{
env: [
{
name: 'string'
value: 'string'
}
]
image: 'registry.hub.docker.com/nkiboi/aca-example:${buildID}'
name: appName
}
]
revisionSuffix: latestCommitId
}
}
}
output containerAppFQDN string = blueGreenDeploymentApp.properties.configuration.ingress.fqdn
output latestRevisionName string = blueGreenDeploymentApp.properties.latestRevisionName