-
Notifications
You must be signed in to change notification settings - Fork 8
/
azure-pipelines.yml
428 lines (394 loc) · 16.1 KB
/
azure-pipelines.yml
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
426
427
428
# This pipeline has four main stages (with two extra ones for optimization reasons):
# 1) Building docker images:
# - anonlink-nginx
# - anonling-app
# - anonlink-benchmark (done in a separate stage 1bis) to be able to depend on it)
# - anonlink-docs-tutorials (done in a separate stage 1ter) to be able to depend on it)
# 2) Running the integration tests using docker-compose
# 3) Running the benchmark using docker-compose
# 4) Running the tests for the tutorials using docker-compose
# 5) Deploying on Kubernetes and running the corresponding tests.
# The dependencies are the following:
# 1 -> 2 -> 5
# 1, 1bis -> 3
# 1, 1ter -> 4
#
# The dockerhub login is a secret in Azure Pipeline.
# The kubeconfig file is a secret file in Azure Pipeline.
#
# The resources used by this pipeline are available in the folder `.azurePipeline`,
# where there are some kubectl templates, azure pipeline step templates and bash scripts.
variables:
backendImageName: data61/anonlink-app
testE2EImageName: data61/anonlink-test
frontendImageName: data61/anonlink-nginx
tutorialImageName: data61/anonlink-docs-tutorials
benchmarkingImageName: data61/anonlink-benchmark
# The Kubernetes Service Connection to use - must be configured in Azure DevOps.
CLUSTER: 'k8s'
# This pipeline should be triggered by every push to any branches, but should not be used
# for external PRs.
pr: none
trigger:
branches:
include:
- '*'
stages:
- stage: stage_base_docker_image_build
displayName: Base Docker build
dependsOn: []
jobs:
- job: HashBaseDependencies
displayName: Hash Dependencies
pool:
vmImage: 'ubuntu-latest'
steps:
- template: .azurePipeline/templateSetVariableDockerBaseTag.yml
- script: |
# Determine if we need to build the base by checking if docker hub already
# has the image?
echo "Trying to pull $(SetDockerBaseTag.DOCKER_BASE_TAG)"
if docker pull data61/anonlink-base:$(SetDockerBaseTag.DOCKER_BASE_TAG) ; then
echo "Base image pulled. Skipping building the base image."
echo "##vso[task.setvariable variable=BUILD_BASE;isOutput=true]false"
else
echo "Base image with correct tag wasn't present."
echo "##vso[task.setvariable variable=BUILD_BASE;isOutput=true]true"
fi
name: BaseRequired
- template: .azurePipeline/templateDockerBuildPush.yml
parameters:
folder: './base'
dependsOn: HashBaseDependencies
imageName: data61/anonlink-base
jobName: 'anonlink_base'
imageTag: $[dependencies.HashBaseDependencies.outputs['SetDockerBaseTag.DOCKER_BASE_TAG']]
skip: $[eq(dependencies.HashBaseDependencies.outputs['BaseRequired.BUILD_BASE'], 'false')]
- stage: stage_docker_image_build
displayName: Anonlink Docker build
dependsOn: [stage_base_docker_image_build]
jobs:
# Why do we recompute the base hash? Because we can't pass variables between stages.
# https://github.com/microsoft/azure-pipelines-tasks/issues/4743
- job: HashBaseDependencies
displayName: Hash Dependencies
pool:
vmImage: 'ubuntu-latest'
steps:
- template: .azurePipeline/templateSetVariableDockerBaseTag.yml
- template: .azurePipeline/templateDockerBuildPush.yml
parameters:
folder: './backend'
jobName: 'anonlink_app'
dependsOn: HashBaseDependencies
imageName: data61/anonlink-app
dockerBuildVersion: "$[dependencies.HashBaseDependencies.outputs['SetDockerBaseTag.DOCKER_BASE_TAG']]"
- stage: stage_docker_e2e_test_image_build
displayName: Build E2E Test Docker image
dependsOn: [stage_base_docker_image_build]
jobs:
# Why do we recompute the base hash? Because we can't pass variables between stages.
# https://github.com/microsoft/azure-pipelines-tasks/issues/4743
- job: HashBaseDependencies
displayName: Hash Dependencies
pool:
vmImage: 'ubuntu-latest'
steps:
- template: .azurePipeline/templateSetVariableDockerBaseTag.yml
- template: .azurePipeline/templateDockerBuildPush.yml
parameters:
folder: './e2etests'
jobName: 'anonlink_e2e_test'
dependsOn: HashBaseDependencies
imageName: data61/anonlink-test
dockerBuildVersion: "$[dependencies.HashBaseDependencies.outputs['SetDockerBaseTag.DOCKER_BASE_TAG']]"
- stage: stage_docker_nginx_image_build
displayName: Nginx Docker build
dependsOn: []
jobs:
- template: .azurePipeline/templateDockerBuildPush.yml
parameters:
folder: '.'
dockerFilePath: './frontend/Dockerfile'
imageName: data61/anonlink-nginx
jobName: 'anonlink_nginx'
- stage: stage_benchmark_image_build
displayName: Build benchmark image
dependsOn: []
jobs:
- template: .azurePipeline/templateDockerBuildPush.yml
parameters:
folder: './benchmarking'
imageName: data61/anonlink-benchmark
jobName: 'anonlink_benchmark'
- stage: stage_docs_tutorial_image_build
displayName: Build docs tutorials image
dependsOn: []
jobs:
- template: .azurePipeline/templateDockerBuildPush.yml
parameters:
folder: './docs/tutorial'
imageName: data61/anonlink-docs-tutorials
jobName: 'anonlink_docs_tutorials'
- stage: stage_integration_tests
displayName: Integration Tests
dependsOn:
- stage_docker_image_build
jobs:
- job: Integration
timeoutInMinutes: 15
variables:
resultFile: testResults.xml
displayName: Integration Tests
pool:
vmImage: 'ubuntu-latest'
steps:
- template: .azurePipeline/templateSetVariableDockerTag.yml
- script: |
./.azurePipeline/runDockerComposeTests.sh --no-ansi -p es$(DOCKER_TAG)$(Build.SourceVersion) -t $(DOCKER_TAG) -o $(resultFile) --type integrationtests
displayName: 'Start docker compose'
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '$(resultFile)'
testRunTitle: 'Publish integration test results'
failTaskOnFailedTests: true
- stage: stage_benchmark
displayName: Benchmark
dependsOn:
- stage_docker_image_build
- stage_benchmark_image_build
jobs:
- job: Benchmark
timeoutInMinutes: 15
variables:
resultFile: results.json
displayName: Benchmark
pool:
vmImage: 'ubuntu-latest'
steps:
- template: .azurePipeline/templateSetVariableDockerTag.yml
- script: |
./.azurePipeline/runDockerComposeTests.sh --no-ansi -p es$(DOCKER_TAG)$(Build.SourceVersion) -t $(DOCKER_TAG) -o $(resultFile) --type benchmark
displayName: 'Start docker compose benchmark'
# Publish Pipeline Artifact
# Publish a local directory or file as a named artifact for the current pipeline.
- task: PublishPipelineArtifact@0
inputs:
artifactName: 'benchmark'
targetPath: $(resultFile)
- stage: stage_tutorials_tests
displayName: Tutorials tests
dependsOn:
- stage_docker_image_build
- stage_docs_tutorial_image_build
jobs:
- job: TutorialsTests
timeoutInMinutes: 10
variables:
resultFile: tutorialTestResults.xml
displayName: Tutorials Tests
pool:
vmImage: 'ubuntu-latest'
steps:
- template: .azurePipeline/templateSetVariableDockerTag.yml
- script: |
./.azurePipeline/runDockerComposeTests.sh --no-ansi -p es$(DOCKER_TAG)$(Build.SourceVersion) -t $(DOCKER_TAG) -o $(resultFile) --type tutorials
displayName: 'Test notebook tutorials'
- task: PublishTestResults@2
condition: succeededOrFailed()
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: '$(resultFile)'
testRunTitle: 'Publish tutorials tests results'
failTaskOnFailedTests: true
- stage: stage_k8s_deployment
displayName: Kubernetes deployment
dependsOn: [stage_docker_image_build]
jobs:
- job: job_k8s_deployment
displayName: Kubernetes deployment and test
timeoutInMinutes: 40
variables:
# All the deployments for tests are done in the namespace `test-azure`, simplifying
# debugging or cleaning if something wrong happens.
NAMESPACE: test-azure
pool:
vmImage: 'ubuntu-latest'
steps:
# Prepare the variables required during the scripts.
- template: .azurePipeline/templateSetVariableDockerTag.yml
- template: .azurePipeline/templateSetVariableReleaseName.yml
- script: |
echo "##vso[task.setvariable variable=PVC]$(DEPLOYMENT)-test-results"
echo "##vso[task.setvariable variable=SERVICE]$(DEPLOYMENT)-entity-service-api"
echo $(backendImageName):$(DOCKER_TAG) | xargs -I@ echo "##vso[task.setvariable variable=IMAGE_NAME_WITH_TAG]@"
echo $(testE2EImageName):$(DOCKER_TAG) | xargs -I@ echo "##vso[task.setvariable variable=TEST_E2E_IMAGE_NAME_WITH_TAG]@"
echo $(DEPLOYMENT)-tmppod | xargs -I@ echo "##vso[task.setvariable variable=POD_NAME]@"
displayName: 'Set variables for service, test result volume and pod'
- task: Kubernetes@1
displayName: 'Create a new namespace'
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: $(CLUSTER)
command: apply
useConfigurationFile: true
inline: '{ "kind": "Namespace", "apiVersion": "v1", "metadata": { "name": "$(NAMESPACE)" }}'
# The file `.azurePipeline/k8s_test_pvc.yaml.tmpl` is a template for the creation of persistent volume via kubectl
- script: |
cat .azurePipeline/k8s_test_pvc.yaml.tmpl | \
sed 's|\$PVC'"|$(PVC)|g" | \
sed 's|\$DEPLOYMENT_NAME'"|$(DEPLOYMENT)|g" > $(Build.ArtifactStagingDirectory)/k8s_test_pvc.yaml
displayName: 'Create test result volume claim from template'
- task: KubernetesManifest@0
displayName: 'Create test result volume claim'
inputs:
action: 'deploy'
kubernetesServiceConnection: '$(CLUSTER)'
manifests: '$(Build.ArtifactStagingDirectory)/k8s_test_pvc.yaml'
namespace: $(NAMESPACE)
# Install Helm on an agent machine
- task: HelmInstaller@1
inputs:
helmVersionToInstall: 'latest'
- task: HelmDeploy@0
displayName: Helm package
inputs:
command: package
save: false
chartPath: 'deployment/entity-service'
destination: $(Build.ArtifactStagingDirectory)
updatedependency: true
- task: KubernetesManifest@0
name: bake
displayName: Bake K8s manifests from Helm chart
inputs:
action: 'bake'
helmChart: 'deployment/entity-service'
namespace: $(NAMESPACE)
releaseName: $(DEPLOYMENT)
overrides: |
global.postgresql.postgresqlPassword:notaproductionpassword
api.ingress.enabled:false
workers.replicaCount:4
api.www.image.repository:$(frontendImageName)
api.www.image.pullPolicy:Always
api.app.image.repository:$(backendImageName)
api.app.image.pullPolicy:Always
api.dbinit.image.repository:$(backendImageName)
workers.image.repository:$(backendImageName)
workers.image.pullPolicy:Always
anonlink.objectstore.uploadEnabled:true
anonlink.objectstore.uploadSecure:false
anonlink.objectstore.uploadAccessKey:testUploadAccessKey
anonlink.objectstore.uploadSecretKey:testUploadSecretKey
anonlink.objectstore.downloadSecure:false
anonlink.objectstore.downloadAccessKey:testDownloadAccessKey
anonlink.objectstore.downloadSecretKey:testDownloadSecretKey
minio.accessKey:testMinioAccessKey
minio.secretKey:testMinioSecretKey
- task: KubernetesManifest@0
displayName: Deploy K8s manifest
inputs:
action: 'deploy'
failOnStderr: false
kubernetesServiceConnection: '$(CLUSTER)'
manifests: '$(bake.manifestsBundle)'
namespace: $(NAMESPACE)
containers: |
data61/anonlink-nginx:$(DOCKER_TAG)
data61/anonlink-app:$(DOCKER_TAG)
#data61/anonlink-worker:$(DOCKER_TAG)
# The file `.azurePipeline/k8s_test_job.yaml.tmpl` is a template for the creation of the test job.
# The test job stops when all the tests have been run, creating a test result file in the PVC.
- script: |
cat .azurePipeline/k8s_test_job.yaml.tmpl | \
sed 's|\$PVC'"|$(PVC)|g" | \
sed 's|\$DEPLOYMENT_NAME'"|$(DEPLOYMENT)|g" | \
sed 's|\$TEST_E2E_IMAGE_NAME_WITH_TAG'"|$(TEST_E2E_IMAGE_NAME_WITH_TAG)|g" | \
sed 's|\$SERVICE'"|$(SERVICE)|g" > $(Build.ArtifactStagingDirectory)/k8s_test_job.yaml
displayName: 'Prepare integration test job from template'
- task: KubernetesManifest@0
displayName: 'Deploy Integration Test Job'
inputs:
action: 'deploy'
kubernetesServiceConnection: '$(CLUSTER)'
manifests: '$(Build.ArtifactStagingDirectory)/k8s_test_job.yaml'
namespace: $(NAMESPACE)
- task: Kubernetes@1
displayName: 'Wait for integration test pod'
name: waitpods
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: $(CLUSTER)
command: 'wait'
arguments: '--namespace $(NAMESPACE) -ldeployment=$(DEPLOYMENT) --timeout=60s --for=condition=Ready pods'
- task: Kubernetes@1
displayName: 'Integration test logs'
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: $(CLUSTER)
command: 'logs'
arguments: '--namespace $(NAMESPACE) -ljobgroup=anonlink-integration-test -ldeployment=$(DEPLOYMENT) -f'
- script: |
echo "Get the test results"
cat .azurePipeline/k8s_get_results.yaml.tmpl | \
sed 's|\$PVC'"|$(PVC)|g" | \
sed 's|\$DEPLOYMENT_NAME'"|$(DEPLOYMENT)|g" | \
sed 's|\$POD_NAME'"|$(POD_NAME)|g" > $(Build.ArtifactStagingDirectory)/k8s_get_results.yaml
displayName: 'Prepare get results pod from template'
- task: KubernetesManifest@0
displayName: 'Deploy Result fetching Pod'
inputs:
action: 'deploy'
kubernetesServiceConnection: '$(CLUSTER)'
manifests: '$(Build.ArtifactStagingDirectory)/k8s_get_results.yaml'
namespace: $(NAMESPACE)
- task: Kubernetes@1
displayName: 'Copy integration test results'
inputs:
connectionType: 'Kubernetes Service Connection'
kubernetesServiceEndpoint: $(CLUSTER)
command: 'cp'
arguments: '$(NAMESPACE)/$(POD_NAME):/mnt/results.xml k8s-results.xml'
- script: |
if [ -f "k8s-results.xml" ]; then
echo "Result file 'k8s-results.xml' exists"
else
echo "Result file 'k8s-results.xml' does not exist"
exit 1
fi
displayName: 'Check test result file existence'
# Publish the test results.
- task: PublishTestResults@2
condition: succeeded()
inputs:
testResultsFormat: 'JUnit'
testResultsFiles: 'k8s-results.xml'
testRunTitle: 'Kubernetes Integration test results'
failTaskOnFailedTests: true
# Publish all the pods logs if some tests failed.
- template: .azurePipeline/templatePublishLogsFromPods.yml
parameters:
logsFolderPath: $(Build.ArtifactStagingDirectory)
releaseName: $(DEPLOYMENT)
namespace: $(NAMESPACE)
kubernetesServiceEndpoint: $(CLUSTER)
JobAttempt: $(System.JobAttempt)
# Cleanup
- task: KubernetesManifest@0
condition: always()
inputs:
action: 'delete'
kubernetesServiceConnection: $(CLUSTER)
arguments: '-f $(bake.manifestsBundle)'
namespace: $(NAMESPACE)
# Note that all the test resources (i.e. the pvc, the job and the pod have a label `deployment` set to $(DEPLOYMENT)
- task: KubernetesManifest@0
condition: always()
inputs:
action: 'delete'
kubernetesServiceConnection: $(CLUSTER)
arguments: 'pods,jobs,pvc,pv,statefulsets,deployment -l deployment=$(DEPLOYMENT)'
namespace: $(NAMESPACE)