-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathazure-pipeline.yml
More file actions
425 lines (403 loc) · 19.1 KB
/
azure-pipeline.yml
File metadata and controls
425 lines (403 loc) · 19.1 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
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
# File: azure-pipeline.yml
name: load_test_pipeline
trigger: none
pool:
vmImage: 'ubuntu-latest'
parameters:
- name: appServicePlanSku
displayName: Sku for App Service Plan
type: string
default: S3
values:
- S1
- S2
- S3
- name: userAmount
displayName: Amount of virtual users
type: number
default: 100
values:
- 50
- 100
- 150
- 200
- 250
- 300
- name: prefix
displayName: Prefix for all resources created in terraform
type: string
default: umbraco-azure-load-test-pipeline
variables:
serviceConnection: 'terraform-umbraco-load-testing-az-serviceconnection'
# Azure Resource Variables
azurergname: '${{ parameters.prefix }}-rg'
loadTestResourceName: '${{ parameters.prefix }}-loadtest'
# Terraform settings
terraformWorkingDirectory: '$(System.DefaultWorkingDirectory)/Terraform'
# LoadTestLocation
loadTestFileLocation: '$(System.DefaultWorkingDirectory)/LoadTestVersions.yaml'
stages:
- stage: terraformDeploy
displayName: Terraform Setup and Apply
jobs:
- job: checkResourceGroup
displayName: Checks if resource group with defined name already exists
steps:
- task: AzureCLI@2
name: checkGroup
displayName: Checks if the resource group exists before running all the steps
inputs:
azureSubscription: '$(serviceConnection)'
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: 'Write-Host "##vso[task.setvariable variable=resourceGroupExists;isOutput=true]$(az group exists -n $(azurergname))"'
- job: getFormattedVersions
displayName: Formats versions
steps:
# If a version is empty it is changed to null, otherwise our powershell script would not be able to read the input
- script: echo "##vso[task.setvariable variable=firstDotNetVersion]null"
displayName: update value if firstDotNetVersion is empty
condition: eq(variables['firstDotNetVersion'],'')
- script: echo "##vso[task.setvariable variable=firstUmbracoVersion]null"
displayName: update value if firstUmbracoVersion is empty
condition: eq(variables['firstUmbracoVersion'],'')
- script: echo "##vso[task.setvariable variable=secondDotNetVersion]null"
displayName: update value if secondDotNetVersion is empty
condition: eq(variables['secondDotNetVersion'],'')
- script: echo "##vso[task.setvariable variable=secondUmbracoVersion]null"
displayName: update value if secondUmbracoVersion is empty
condition: eq(variables['secondUmbracoVersion'],'')
- script: echo "##vso[task.setvariable variable=thirdDotNetVersion]null"
displayName: update value if thirdDotNetVersion is empty
condition: eq(variables['thirdDotNetVersion'],'')
- script: echo "##vso[task.setvariable variable=thirdUmbracoVersion]null"
displayName: update value if thirdUmbracoVersion is empty
condition: eq(variables['thirdUmbracoVersion'],'')
- script: echo "##vso[task.setvariable variable=fourthDotNetVersion]null"
displayName: update value if fourthDotNetVersion is empty
condition: eq(variables['fourthDotNetVersion'],'')
- script: echo "##vso[task.setvariable variable=fourthUmbracoVersion]null"
displayName: update value if fourthUmbracoVersion is empty
condition: eq(variables['fourthUmbracoVersion'],'')
- task: PowerShell@2
name: versionsOutput
inputs:
filePath: '$(terraformWorkingDirectory)/script/versionsToJson.ps1'
arguments: |
-firstDotNetVersion $(firstDotNetVersion) -firstUmbracoVersion $(firstUmbracoVersion) -secondDotNetVersion $(secondDotNetVersion) -secondUmbracoVersion $(secondUmbracoVersion) -thirdDotNetVersion $(thirdDotNetVersion) -thirdUmbracoVersion $(thirdUmbracoVersion) -fourthDotNetVersion $(fourthDotNetVersion) -fourthUmbracoVersion $(fourthUmbracoVersion)
echo "##vso[task.setvariable variable=umbracoTFversions;isOutput=true]$env:umbracoTFversions"
- job: setup
dependsOn:
- checkResourceGroup
- getFormattedVersions
condition: eq(dependencies.checkResourceGroup.outputs['checkGroup.resourceGroupExists'], false)
displayName: Terraform Setup
variables:
umbracoTFversions: $[dependencies.getFormattedVersions.outputs['versionsOutput.umbracoTFversions']]
steps:
- task: TerraformInstaller@0
displayName: Install Terraform
inputs:
terraformVersion: 'latest'
- task: PowerShell@2
displayName: Terraform Init
inputs:
targetType: 'inline'
script: 'terraform init -backend=false'
workingDirectory: '$(terraformWorkingDirectory)'
- task: TerraformTaskV4@4
displayName: Validate
inputs:
provider: 'azurerm'
command: 'validate'
workingDirectory: '$(terraformWorkingDirectory)'
- script: echo '$(umbracoTFversions)'
- task: TerraformTaskV4@4
displayName: Terraform Plan
inputs:
provider: 'azurerm'
command: 'plan'
workingDirectory: '$(terraformWorkingDirectory)'
environmentServiceNameAzureRM: '$(serviceConnection)'
commandOptions: '-parallelism=1 -var resource_name_prefix=${{ parameters.prefix }} -var resource_group_name=$(azurergname) -var="umbraco_cms_versions=$(umbracoTFversions)"'
- job: apply
displayName: Terraform Apply
dependsOn:
- getFormattedVersions
- setup
variables:
umbracoTFversions: $[dependencies.getFormattedVersions.outputs['versionsOutput.umbracoTFversions']]
steps:
# TODO: DO we really need to install terraform again?
- task: TerraformInstaller@0
displayName: Install Terraform
inputs:
terraformVersion: 'latest'
# We need to initialize again, otherwise the pipeline will fail.
- task: PowerShell@2
displayName: Terraform Init
inputs:
targetType: 'inline'
script: 'terraform init -backend=false'
workingDirectory: '$(terraformWorkingDirectory)'
- task: AzureCLI@2
name: AzLoginInfo
displayName: Gets Azure Login Credentials
inputs:
azureSubscription: '$(serviceConnection)'
scriptType: bash
scriptLocation: inlineScript
inlineScript: |
echo "##vso[task.setvariable variable=ARM_CLIENT_ID]$servicePrincipalId"
echo "##vso[task.setvariable variable=ARM_CLIENT_SECRET]$servicePrincipalKey"
echo "##vso[task.setvariable variable=ARM_TENANT_ID]$tenantId"
addSpnToEnvironment: true
- task: TerraformTaskV4@4
displayName: Terraform Apply
inputs:
provider: 'azurerm'
command: 'apply'
workingDirectory: '$(terraformWorkingDirectory)'
environmentServiceNameAzureRM: '$(serviceConnection)'
commandOptions: '-parallelism=1 -var resource_name_prefix=${{ parameters.prefix }} -var resource_group_name=$(azurergname) -var client_id=$(ARM_CLIENT_ID) -var client_secret=$(ARM_CLIENT_SECRET) -var tenant_id=$(ARM_TENANT_ID) -var app_service_plan_sku=${{ parameters.appServicePlanSku }} -var="umbraco_cms_versions=$(umbracoTFversions)"'
- task: TerraformTaskV4@4
displayName: Terraform Output
inputs:
provider: 'azurerm'
command: 'output'
workingDirectory: '$(terraformWorkingDirectory)'
environmentServiceNameAzureRM: '$(serviceConnection)'
- task: PowerShell@2
name: outputVars
displayName: Sets the output as variables
inputs:
targetType: 'inline'
script: |
Write-Host "##vso[task.setvariable variable=firstHostName;isOutput=true]$(terraform output -json hostnames | jq -r '.[0]')"
Write-Host "##vso[task.setvariable variable=secondHostName;isOutput=true]$(terraform output -json hostnames | jq -r '.[1]')"
Write-Host "##vso[task.setvariable variable=thirdHostName;isOutput=true]$(terraform output -json hostnames | jq -r '.[2]')"
Write-Host "##vso[task.setvariable variable=fourthHostName;isOutput=true]$(terraform output -json hostnames | jq -r '.[3]')"
Write-Host "##vso[task.setvariable variable=firstUmbracoVersion;isOutput=true]$(terraform output -json cms_versions | jq -r '.[0]')"
Write-Host "##vso[task.setvariable variable=secondUmbracoVersion;isOutput=true]$(terraform output -json cms_versions | jq -r '.[1]')"
Write-Host "##vso[task.setvariable variable=thirdUmbracoVersion;isOutput=true]$(terraform output -json cms_versions | jq -r '.[2]')"
Write-Host "##vso[task.setvariable variable=fourthUmbracoVersion;isOutput=true]$(terraform output -json cms_versions | jq -r '.[3]')"
Write-Host "##vso[task.setvariable variable=firstAppServiceName;isOutput=true]$(terraform output -json app_service_name | jq -r '.[0]')"
Write-Host "##vso[task.setvariable variable=secondAppServiceName;isOutput=true]$(terraform output -json app_service_name | jq -r '.[1]')"
Write-Host "##vso[task.setvariable variable=thirdAppServiceName;isOutput=true]$(terraform output -json app_service_name | jq -r '.[2]')"
Write-Host "##vso[task.setvariable variable=fourthAppServiceName;isOutput=true]$(terraform output -json app_service_name | jq -r '.[3]')"
workingDirectory: '$(terraformWorkingDirectory)'
- job: runLoadTest
displayName: Runs the load test
dependsOn: apply
variables:
firstHostName: $[dependencies.apply.outputs['outputVars.firstHostName']]
secondHostName: $[dependencies.apply.outputs['outputVars.secondHostName']]
thirdHostName: $[dependencies.apply.outputs['outputVars.thirdHostName']]
fourthHostName: $[dependencies.apply.outputs['outputVars.fourthHostName']]
firstUmbracoVersion: $[dependencies.apply.outputs['outputVars.firstUmbracoVersion']]
secondUmbracoVersion: $[dependencies.apply.outputs['outputVars.secondUmbracoVersion']]
thirdUmbracoVersion: $[dependencies.apply.outputs['outputVars.thirdUmbracoVersion']]
fourthUmbracoVersion: $[dependencies.apply.outputs['outputVars.fourthUmbracoVersion']]
firstAppServiceName: $[dependencies.apply.outputs['outputVars.firstAppServiceName']]
secondAppServiceName: $[dependencies.apply.outputs['outputVars.secondAppServiceName']]
thirdAppServiceName: $[dependencies.apply.outputs['outputVars.thirdAppServiceName']]
fourthAppServiceName: $[dependencies.apply.outputs['outputVars.fourthAppServiceName']]
steps:
# The load test are set up so we will be able to load test up to 4 different hostnames. A load test is only gonna run if the hostName variable is not null
- task: AzureCLI@2
name: startAppServiceOne
condition: or(ne(variables['firstHostName'], 'null'), ne(variables['firstUmbracoVersion'], 'null'))
displayName: Starts the first hostname
inputs:
azureSubscription: '$(serviceConnection)'
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: az webapp start -n $(firstAppServiceName) -g $(azurergname)
- task: PowerShell@2
condition: or(ne(variables['firstHostName'], 'null'), ne(variables['firstUmbracoVersion'], 'null'))
displayName: Sleeps for 3 minutes
inputs:
targetType: 'inline'
script: Start-Sleep -Seconds 180
- task: AzureLoadTest@1
condition: or(ne(variables['firstHostName'], 'null'), ne(variables['firstUmbracoVersion'], 'null'))
displayName: LoadTest 1
inputs:
azureSubscription: '$(serviceConnection)'
loadTestConfigFile: '$(loadTestFileLocation)'
resourceGroup: '$(azurergname)'
loadTestResource: $(loadTestResourceName)
loadTestRunName: '$(firstUmbracoVersion)'
loadTestRunDescription: 'We are load testing different versions of Umbraco'
env: |
[
{
"name": "hostName",
"value": "$(firstHostName)"
},
{
"name": "users",
"value": "${{ parameters.userAmount }}"
}
]
- task: AzureCLI@2
name: startAppServiceTwo
condition: or(ne(variables['secondHostName'], 'null'), ne(variables['secondUmbracoVersion'], 'null'))
displayName: Starts the second hostname
inputs:
azureSubscription: '$(serviceConnection)'
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
az webapp stop -n $(firstAppServiceName) -g $(azurergname)
az webapp start -n $(secondAppServiceName) -g $(azurergname)
- task: PowerShell@2
condition: or(ne(variables['secondHostName'], 'null'), ne(variables['secondUmbracoVersion'], 'null'))
displayName: Sleeps for 3 minutes
inputs:
targetType: 'inline'
script: Start-Sleep -Seconds 180
- task: AzureLoadTest@1
condition: or(ne(variables['secondHostName'], 'null'), ne(variables['secondUmbracoVersion'], 'null'))
displayName: LoadTest 2
inputs:
azureSubscription: '$(serviceConnection)'
loadTestConfigFile: '$(loadTestFileLocation)'
resourceGroup: '$(azurergname)'
loadTestResource: $(loadTestResourceName)
loadTestRunName: '$(secondUmbracoVersion)'
loadTestRunDescription: 'We are load testing different versions of Umbraco'
env: |
[
{
"name": "hostName",
"value": "$(secondHostName)"
},
{
"name": "users",
"value": "${{ parameters.userAmount }}"
}
]
- task: AzureCLI@2
name: startAppServiceThree
condition: or(ne(variables['thirdHostName'], 'null'), ne(variables['thirdUmbracoVersion'], 'null'))
displayName: Starts the third hostname
inputs:
azureSubscription: '$(serviceConnection)'
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
az webapp stop -n $(secondAppServiceName) -g $(azurergname)
az webapp start -n $(thirdAppServiceName) -g $(azurergname)
- task: PowerShell@2
condition: or(ne(variables['thirdHostName'], 'null'), ne(variables['thirdUmbracoVersion'], 'null'))
displayName: Sleeps for 3 minutes
inputs:
targetType: 'inline'
script: Start-Sleep -Seconds 180
- task: AzureLoadTest@1
condition: or(ne(variables['thirdHostName'], 'null'), ne(variables['thirdUmbracoVersion'], 'null'))
displayName: LoadTest 3
inputs:
azureSubscription: '$(serviceConnection)'
loadTestConfigFile: '$(loadTestFileLocation)'
resourceGroup: '$(azurergname)'
loadTestResource: $(loadTestResourceName)
loadTestRunName: '$(thirdUmbracoVersion)'
loadTestRunDescription: 'We are load testing different versions of Umbraco'
env: |
[
{
"name": "hostName",
"value": "$(thirdHostName)"
},
{
"name": "users",
"value": "${{ parameters.userAmount }}"
}
]
- task: AzureCLI@2
name: startAppServiceFour
condition: or(ne(variables['fourthHostName'], 'null'), ne(variables['fourthUmbracoVersion'], 'null'))
displayName: Starts the fourth hostname
inputs:
azureSubscription: '$(serviceConnection)'
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: |
az webapp stop -n $(thirdAppServiceName) -g $(azurergname)
az webapp start -n $(fourthAppServiceName) -g $(azurergname)
- task: PowerShell@2
condition: or(ne(variables['fourthHostName'], 'null'), ne(variables['fourthUmbracoVersion'], 'null'))
displayName: Sleeps for 3 minutes
inputs:
targetType: 'inline'
script: Start-Sleep -Seconds 180
- task: AzureLoadTest@1
condition: or(ne(variables['fourthHostName'], 'null'), ne(variables['fourthUmbracoVersion'], 'null'))
displayName: LoadTest 4
inputs:
azureSubscription: '$(serviceConnection)'
loadTestConfigFile: '$(loadTestFileLocation)'
resourceGroup: '$(azurergname)'
loadTestResource: $(loadTestResourceName)
loadTestRunName: '$(fourthUmbracoVersion)'
loadTestRunDescription: 'We are load testing different versions of Umbraco'
env: |
[
{
"name": "hostName",
"value": "$(fourthHostName)"
},
{
"name": "users",
"value": "${{ parameters.userAmount }}"
}
]
- job: doesResourceGroupExists
dependsOn: runLoadTest
condition: succeededOrFailed()
displayName: Checks if the resource group exists
steps:
- task: AzureCLI@2
name: checkResourceGroup
displayName: Checks if the resource group exists
inputs:
azureSubscription: '$(serviceConnection)'
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: 'Write-Host "##vso[task.setvariable variable=doesExist;isOutput=true]$(az group exists -n $(azurergname))"'
- job: manualValidationResourceGroup
dependsOn: doesResourceGroupExists
condition: eq(dependencies.doesResourceGroupExists.outputs['checkResourceGroup.doesExist'], true)
displayName: Manual validation for deleting the resource group
pool: server
timeoutInMinutes: 1440
steps:
- task: ManualValidation@0
displayName: Wait for external validation
timeoutInMinutes: 1440
inputs:
# notifyUsers: aze@umbraco.dk
instructions: 'Please press "Resume" if you want to keep the resource group $(azurergname). If you press "Reject" or do not pick an option after 24 hours, The resource group $(azurergname), and all the content inside of the resource group will be deleted'
- job: deleteResourceGroup
displayName: Deletes the resource group
dependsOn: manualValidationResourceGroup
condition: eq(dependencies.manualValidationResourceGroup.result, 'failed')
steps:
- task: AzureCLI@2
name: checkResourceGroupAgain
displayName: Checks if the resource group exists before deleting it
inputs:
azureSubscription: '$(serviceConnection)'
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: 'Write-Host "##vso[task.setvariable variable=doesResourceGroupExist;isOutput=true]$(az group exists -n $(azurergname))"'
- task: AzureCLI@2
displayName: Deletes the resource group
retryCountOnTaskFailure: 5
inputs:
azureSubscription: '$(serviceConnection)'
scriptType: 'pscore'
scriptLocation: 'inlineScript'
inlineScript: 'az group delete -n $(azurergname) --yes'