-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.bicep
89 lines (86 loc) · 2.9 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
@description('Name for the container group')
param name string
@description('Location for all resources.')
param location string = resourceGroup().location
@description('Container image server url')
param imageServer string
@description('Container image server Username')
param imageServerUsername string
@secure()
@description('Container image server Password.')
param imageServerPassword string
@description('Container image to deploy.')
param image string
@description('(Optional. VNet Subnet Resource Id to deploy the container instance to.')
param subnetResourceId string = ''
@description('The number of CPU cores to allocate to the container.')
param cpuCores int = 1
@description('The amount of memory to allocate to the container in gigabytes.')
param memoryInGb int = 2
@description('OS type')
@allowed(['Linux', 'Windows'])
param osType string = 'Linux'
@description('The behavior of Azure runtime if container has stopped.')
@allowed([
'Always'
'Never'
'OnFailure'
])
param restartPolicy string = 'Always'
@description('Number of linux container instances deploy. Note: Multi-container groups currently support only Linux containers. For Windows containers, Azure Container Instances only supports deployment of a single container instance.')
param instances int = 1
@description('Container environment variables. Array of name, value|secureValue')
param environmentVariables array
@description('Resource tags')
param tags object = { Application: 'self-hosted' }
@description('Custom DNS servers to use for private DNS. Array of strings holding IP address of DNS servers.')
param dnsServers array
var osAbbreviation = osType == 'Linux' ? 'lnx' : 'win'
var containerPrefix = 'selfhosted-${osAbbreviation}-'
var envVariables = [for e in environmentVariables: {
name: e.name
value: contains(e, 'value') ? e.value : null
secureValue: contains(e, 'secureValue') ? e.secureValue : null
}]
resource containerGroupResource 'Microsoft.ContainerInstance/containerGroups@2021-09-01' = {
name: name
location: location
tags: tags
properties: {
containers: [for index in range(0, instances): {
name: '${containerPrefix}${padLeft(index + 1, 3, '0')}'
properties: {
image: '${imageServer}/${image}'
environmentVariables: concat(envVariables, [
{
name: 'NAME'
value: '${containerPrefix}${padLeft(index + 1, 2, '0')}'
}
])
resources: {
requests: {
cpu: cpuCores
memoryInGB: memoryInGb
}
}
}
}]
dnsConfig: empty(dnsServers) ? null : {
nameServers: dnsServers
}
imageRegistryCredentials: [
{
server: imageServer
username: imageServerUsername
password: imageServerPassword
}
]
osType: osType
restartPolicy: restartPolicy
subnetIds: empty(subnetResourceId) ? [] : [
{
id: subnetResourceId
}
]
}
}