forked from JetBrains/teamcity-azure-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
azuredeploy.json
352 lines (352 loc) · 17.3 KB
/
azuredeploy.json
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
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"teamcityVersion": {
"type": "string",
"defaultValue": "latest",
"minLength": 1,
"metadata": {
"description": "The version of TeamCity linux docker images"
}
},
"VMSize": {
"type": "string",
"defaultValue": "Standard_D2s_v3",
"allowedValues": [
"Standard_A1_v2",
"Standard_A2_v2",
"Standard_A4_v2",
"Standard_A8_v2",
"Standard_D2s_v3",
"Standard_D4s_v3",
"Standard_D8s_v3",
"Standard_D1_v2",
"Standard_D2_v2",
"Standard_D3_v2",
"Standard_D2_v3",
"Standard_D4_v3",
"Standard_DS1_v2",
"Standard_DS2_v2",
"Standard_DS3_v2",
"Standard_E2s_v3",
"Standard_E4s_v3",
"Standard_E8s_v3",
"Standard_F1",
"Standard_F2",
"Standard_F4",
"Standard_F8",
"Standard_F2s_v2",
"Standard_F4s_v2",
"Standard_F8s_v2"
],
"metadata": {
"description": "Instance size for the TeamCity VM"
}
},
"VMDataDiskInGB": {
"type": "int",
"defaultValue": 33,
"metadata": {
"description": "Size of attached data disk in GB"
}
},
"VMAdminUsername": {
"type": "string",
"defaultValue": "core",
"metadata": {
"description": "Username to login to the VMs"
}
},
"SSHKeyData": {
"type": "secureString",
"metadata": {
"description": "Public key for SSH authentication"
}
},
"databaseTier": {
"type": "string",
"allowedValues": [
"Basic",
"Standard"
],
"defaultValue": "Basic",
"metadata": {
"description": "Azure database for MySQL pricing tier"
}
},
"databaseDTU": {
"type": "int",
"allowedValues": [
50,
100,
200,
400
],
"defaultValue": 50,
"metadata": {
"description": "Azure database for MySQL performance: Basic 50/100 DTU or Standard 100/200/400 DTU"
}
},
"databaseSizeMB": {
"type": "int",
"allowedValues": [
51200,
128000,
179200,
256000
],
"defaultValue": 51200,
"metadata": {
"description": "Azure database for MySQL Sku Size: Basic 50/175GB or Standard 125/250 GB"
}
},
"databasePassword": {
"type": "secureString",
"minLength": 8,
"maxLength": 128,
"metadata": {
"description": "Azure database for MySQL administrator password"
}
}
},
"variables": {
"publicIpName": "teamcity-pip",
"publicIpDns": "[concat('teamcity-', uniqueString(resourceGroup().id))]",
"virtualNetworkName": "teamcity-vnet",
"networkName": "teamcity-net",
"networkSubnet": "[concat(resourceId('Microsoft.Network/virtualNetworks', variables('virtualNetworkName')), '/subnets/default')]",
"networkSecurityGroupName": "teamcity-nsg",
"vmName": "teamcity",
"storageType": "[if(contains(toLower(substring(parameters('VMSize'), 9)), 's'), 'Premium_LRS', 'Standard_LRS')]",
"sshKeyPath": "[concat('/home/',parameters('VMAdminUsername'),'/.ssh/authorized_keys')]",
"dbServerName": "[concat('teamcity-', uniqueString(resourceGroup().id))]",
"dbName": "teamcitydb"
},
"resources": [
{
"type": "Microsoft.Network/publicIPAddresses",
"name": "[variables('publicIpName')]",
"location": "[resourceGroup().location]",
"apiVersion": "2017-08-01",
"properties": {
"publicIPAllocationMethod": "Dynamic",
"dnsSettings": {
"domainNameLabel": "[variables('publicIpDns')]"
}
}
},
{
"type": "Microsoft.Network/virtualNetworks",
"name": "[variables('virtualNetworkName')]",
"location": "[resourceGroup().location]",
"apiVersion": "2017-08-01",
"properties": {
"addressSpace": {
"addressPrefixes": [
"10.0.0.0/24"
]
},
"subnets": [
{
"name": "default",
"properties": {
"addressPrefix": "10.0.0.0/24"
}
}
]
}
},
{
"type": "Microsoft.Network/networkSecurityGroups",
"name": "[variables('networkSecurityGroupName')]",
"apiVersion": "2017-06-01",
"location": "[resourceGroup().location]",
"properties": {
"securityRules": [
{
"name": "default-allow-ssh",
"properties": {
"priority": 1000,
"protocol": "TCP",
"access": "Allow",
"direction": "Inbound",
"sourceAddressPrefix": "*",
"sourcePortRange": "*",
"destinationAddressPrefix": "*",
"destinationPortRange": "22"
}
},
{
"name": "default-allow-http",
"properties": {
"priority": 1010,
"protocol": "TCP",
"access": "Allow",
"direction": "Inbound",
"sourceAddressPrefix": "*",
"sourcePortRange": "*",
"destinationAddressPrefix": "*",
"destinationPortRange": "80"
}
}
]
}
},
{
"type": "Microsoft.Network/networkInterfaces",
"name": "[variables('networkName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Network/publicIPAddresses/', variables('publicIpName'))]",
"[concat('Microsoft.Network/virtualNetworks/', variables('virtualNetworkName'))]",
"[concat('Microsoft.Network/networkSecurityGroups/', variables('networkSecurityGroupName'))]"
],
"apiVersion": "2016-09-01",
"properties": {
"ipConfigurations": [
{
"name": "[concat(variables('vmName'), '-config')]",
"properties": {
"privateIPAllocationMethod": "Dynamic",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIpAddresses', variables('publicIpName'))]"
},
"subnet": {
"id": "[variables('networkSubnet')]"
}
}
}
],
"networkSecurityGroup": {
"id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('networkSecurityGroupName'))]"
}
}
},
{
"type": "Microsoft.DBforMySQL/servers",
"name": "[variables('dbServerName')]",
"location": "[resourceGroup().location]",
"apiVersion": "2017-04-30-preview",
"properties": {
"version": "5.7",
"administratorLogin": "teamcity",
"administratorLoginPassword": "[parameters('databasePassword')]",
"storageMB": "[parameters('databaseSizeMB')]",
"sslEnforcement": "Disabled"
},
"sku": {
"name": "[concat('MYSQL', substring(parameters('databaseTier'), 0, 1), parameters('databaseDTU'))]",
"tier": "[parameters('databaseTier')]",
"capacity": "[parameters('databaseDTU')]",
"size": "[parameters('databaseSizeMB')]",
"family": "SkuFamily"
},
"resources": [
{
"type": "firewallrules",
"apiVersion": "2017-04-30-preview",
"dependsOn": [
"[concat('Microsoft.DBforMySQL/servers/', variables('dbServerName'))]"
],
"location": "[resourceGroup().location]",
"name": "firewall",
"properties": {
"startIpAddress": "0.0.0.0",
"endIpAddress": "0.0.0.0"
}
},
{
"type": "databases",
"name": "[variables('dbName')]",
"apiVersion": "2017-04-30-preview",
"properties": {
"charset": "utf8",
"collation": "utf8_general_ci"
},
"dependsOn": [
"[concat('Microsoft.DBforMySQL/servers/', variables('dbServerName'))]"
]
}
]
},
{
"type": "Microsoft.Compute/virtualMachines",
"name": "[variables('vmName')]",
"location": "[resourceGroup().location]",
"dependsOn": [
"[concat('Microsoft.Network/networkInterfaces/', variables('networkName'))]"
],
"apiVersion": "2016-04-30-preview",
"properties": {
"hardwareProfile": {
"vmSize": "[parameters('VMSize')]"
},
"osProfile": {
"computerName": "[variables('vmName')]",
"adminUsername": "[parameters('VMAdminUsername')]",
"customData": "[base64(concat('#cloud-config\nwrite_files:\n - path: \"/etc/teamcity/update.sh\"\n permissions: 0755\n content: |\n #!/bin/bash\n while true\n do\n STATUS=$(curl -s -o /etc/teamcity/tags -w ''%{http_code}'' -H Metadata:true \"http://169.254.169.254/metadata/instance/compute/tags?api-version=2017-08-01\u0026format=text\")\n if [ $STATUS -eq 200 ]; then\n VERSION=$(cat /etc/teamcity/tags | sed -n ''s/.*teamcity-version\\:\\([^;]\\+\\).*/\\1/p'')\n if [[ ! -z \"$VERSION\" ]]; then\n TEAMCITY_VERSION=\"TEAMCITY_VERSION=$VERSION\"\n CURRENT_VERSION=$(cat /etc/teamcity/version)\n if [ \"$TEAMCITY_VERSION\" != \"$CURRENT_VERSION\" ]; then\n echo \"TeamCity version has changed to $VERSION\"\n echo \"$TEAMCITY_VERSION\" > /etc/teamcity/version\n /usr/bin/docker pull jetbrains/teamcity-server:${VERSION}\n systemctl restart teamcity-server.service\n /usr/bin/docker pull jetbrains/teamcity-agent:${VERSION}\n systemctl restart teamcity-agent.service\n fi\n fi\n fi\n sleep 60\n done\n - path: \"/etc/coreos/update.conf\"\n content: |\n REBOOT_STRATEGY=\"off\"\ncoreos:\n units:\n - name: \"format-mnt-data.service\"\n enable: true\n content: |\n [Unit]\n Requires=network-online.target\n Before=teamcity-server.service mnt-data.mount\n ConditionPathExists=!/dev/mapper/app-data\n\n [Service]\n Type=oneshot\n ExecStart=/bin/bash -c \\\n ''/usr/sbin/pvcreate /dev/sdc \u0026\u0026 \\\n /usr/sbin/vgcreate app /dev/sdc \u0026\u0026 \\\n /usr/sbin/lvcreate -l 100%FREE -n data app \u0026\u0026 \\\n /usr/sbin/mkfs.ext4 /dev/mapper/app-data''\n\n [Install]\n WantedBy=multi-user.target\n - name: \"mnt-data.mount\"\n enable: true\n content: |\n [Unit]\n Before=teamcity-server.service\n After=format-mnt-data.service\n Requires=format-mnt-data.service\n ConditionVirtualization=!container\n Conflicts=umount.target\n [Mount]\n What=/dev/mapper/app-data\n Where=/mnt/data\n Type=ext4\n Options=\n [Install]\n RequiredBy=teamcity-server.service\n - name: \"get-mysql-connector.service\"\n enable: true\n content: |\n [Unit]\n Before=teamcity-server.service\n After=mnt-data.mount\n Requires=mnt-data.mount\n ConditionPathExists=!/mnt/data/teamcity/lib/jdbc/mysql-connector-java-bin.jar\n\n [Service]\n Type=oneshot\n ExecStart=/usr/bin/mkdir -p /mnt/data/teamcity/lib/jdbc\n ExecStart=/usr/bin/wget -O /mnt/data/teamcity/lib/jdbc/mysql-connector-java-bin.jar \\\n http://central.maven.org/maven2/mysql/mysql-connector-java/5.1.43/mysql-connector-java-5.1.43.jar\n\n [Install]\n WantedBy=multi-user.target\n - name: \"prepare-db-properties.service\"\n enable: true\n content: |\n [Unit]\n Before=teamcity-server.service\n After=mnt-data.mount\n Requires=mnt-data.mount network-online.target\n ConditionPathExists=!/mnt/data/teamcity/config/database.properties\n\n [Service]\n Type=oneshot\n ExecStart=/usr/bin/mkdir -p /mnt/data/teamcity/config\n ExecStart=/bin/bash -c ''echo connectionProperties.user=teamcity@',variables('dbServerName'),' > /mnt/data/teamcity/config/database.properties''\n ExecStart=/bin/bash -c ''echo connectionProperties.password=',parameters('databasePassword'),' >> /mnt/data/teamcity/config/database.properties''\n ExecStart=/bin/bash -c ''echo connectionUrl=jdbc\\\\:mysql\\\\://',variables('dbServerName'),'.mysql.database.azure.com/',variables('dbName'),'?autoReconnect=true >> /mnt/data/teamcity/config/database.properties''\n\n [Install]\n WantedBy=multi-user.target\n - name: \"teamcity-update.service\"\n command: \"start\"\n content: |\n [Unit]\n After=docker.service\n Before=teamcity-server.service teamcity-agent.service\n Requires=docker.service network-online.target\n\n [Service]\n ExecStart=+/bin/sh /etc/teamcity/update.sh\n Restart=always\n\n [Install]\n WantedBy=multi-user.target\n - name: \"teamcity-server.service\"\n command: \"start\"\n content: |\n [Unit]\n Description=TeamCity Server\n After=docker.service mnt-data.mount get-mysql-connector.service prepare-db-properties.service teamcity-update.service\n Requires=docker.service mnt-data.mount get-mysql-connector.service prepare-db-properties.service teamcity-update.service\n\n [Service]\n EnvironmentFile=/etc/teamcity/version\n TimeoutStartSec=1200s\n ExecStartPre=/bin/sh -c \"docker images --filter ''before=jetbrains/teamcity-server:${TEAMCITY_VERSION}'' --format ''{{.ID}} {{.Repository}}'' | grep ''jetbrains/teamcity-server'' | grep -Eo ''^[^ ]+'' | xargs -r docker rmi\"\n ExecStart=/usr/bin/docker run \\\n -v /mnt/data/teamcity:/data/teamcity_server/datadir \\\n -v /mnt/data/logs/teamcity:/opt/teamcity/logs \\\n -v /mnt/data/temp/teamcity:/opt/teamcity/temp \\\n -p 80:8111 \\\n --name teamcity-server \\\n jetbrains/teamcity-server:${TEAMCITY_VERSION}\n ExecStop=-/usr/bin/docker exec teamcity-server /opt/teamcity/bin/teamcity-server.sh stop 60\n ExecStopPost=-/usr/bin/docker stop teamcity-server\n ExecStopPost=-/usr/bin/docker rm teamcity-server\n Restart=always\n\n [Install]\n WantedBy=multi-user.target\n - name: \"teamcity-agent.service\"\n command: \"start\"\n content: |\n [Unit]\n Description=TeamCity Agent\n After=teamcity-server.service coreos-metadata.service teamcity-update.service\n Requires=teamcity-server.service coreos-metadata.service teamcity-update.service\n\n [Service]\n EnvironmentFile=/etc/teamcity/version\n TimeoutStartSec=1200s\n EnvironmentFile=/run/metadata/coreos\n ExecStartPre=/bin/sh -c \"docker images --filter ''before=jetbrains/teamcity-agent:${TEAMCITY_VERSION}'' --format ''{{.ID}} {{.Repository}}'' | grep ''jetbrains/teamcity-agent'' | grep -Eo ''^[^ ]+'' | xargs -r docker rmi\"\n ExecStart=/usr/bin/docker run \\\n -v /mnt/data/temp/teamcity:/opt/teamcity/temp \\\n -e SERVER_URL=${COREOS_AZURE_IPV4_DYNAMIC} \\\n -e AGENT_NAME=Default \\\n --name teamcity-agent \\\n jetbrains/teamcity-agent:${TEAMCITY_VERSION}\n ExecStop=-/usr/bin/docker stop teamcity-agent\n ExecStopPost=-/usr/bin/docker rm teamcity-agent\n Restart=always\n\n [Install]\n WantedBy=multi-user.target'))]",
"linuxConfiguration": {
"disablePasswordAuthentication": true,
"ssh": {
"publicKeys": [
{
"path": "[variables('sshKeyPath')]",
"keyData": "[parameters('SSHKeyData')]"
}
]
}
}
},
"storageProfile": {
"imageReference": {
"publisher": "CoreOS",
"offer": "CoreOS",
"sku": "Stable",
"version": "latest"
},
"osDisk": {
"name": "[concat(variables('vmName'), '-os')]",
"caching": "ReadWrite",
"createOption": "FromImage",
"managedDisk": {
"storageAccountType": "[variables('storageType')]"
}
},
"dataDisks": [
{
"name": "[concat(variables('vmName'), '-data')]",
"caching": "ReadWrite",
"createOption": "Empty",
"diskSizeGB": "[parameters('VMDataDiskInGB')]",
"lun": 0,
"managedDisk": {
"storageAccountType": "[variables('storageType')]"
}
}
]
},
"networkProfile": {
"networkInterfaces": [
{
"id": "[resourceId('Microsoft.Network/networkInterfaces', variables('networkName'))]"
}
]
}
},
"tags": {
"teamcity-version": "[toLower(trim(parameters('teamcityVersion')))]"
}
}
],
"outputs": {
"teamcityURL": {
"type": "string",
"value": "[concat('http://', reference(variables('publicIpName')).dnsSettings.fqdn)]"
},
"SSH": {
"type": "string",
"value": "[concat('ssh ', parameters('VMAdminUsername'), '@', reference(variables('publicIpName')).dnsSettings.fqdn)]"
}
}
}