-
Notifications
You must be signed in to change notification settings - Fork 0
/
azure-pipelines.yml
248 lines (239 loc) · 8.61 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
# Docker
# Build and push an image to Azure Container Registry
# https://docs.microsoft.com/azure/devops/pipelines/languages/docker
trigger:
branches:
include:
- master
paths:
include:
- web/*
- backend/*
- integration-tests/*
- azure-pipelines.yml
variables:
dockerHubServiceConnection: Specmore Docker Hub
tag: '$(Build.BuildId)'
GitVersion.ShortSha: ''
GitVersion.SemVer: ''
GitVersion.FullSemVer: ''
# Agent VM image name
vmImageName: 'ubuntu-latest'
stages:
- stage: Build
displayName: Build, Test and Push Test Candidate images
jobs:
- job: SetVersion
displayName: Calc Version Number
pool:
vmImage: $(vmImageName)
steps:
- task: gitversion/setup@0
displayName: Install GitVersion
inputs:
versionSpec: '5.x'
- task: gitversion/execute@0
name: GitVersionTask
displayName: Use GitVersion
- bash: echo ShortSha $(GitVersion.ShortSha);
echo SemVer $(GitVersion.SemVer);
echo FullSemVer $(GitVersion.FullSemVer);
displayName: Display versions
- job: BuildBackend
displayName: Build Backend Service image
dependsOn: SetVersion
variables:
GitVersion.SemVer: $[ dependencies.SetVersion.outputs['GitVersionTask.GitVersion.SemVer'] ]
GitVersion.FullSemVer: $[ dependencies.SetVersion.outputs['GitVersionTask.GitVersion.FullSemVer'] ]
GitVersion.ShortSha: $[ dependencies.SetVersion.outputs['GitVersionTask.GitVersion.ShortSha'] ]
pool:
vmImage: $(vmImageName)
steps:
- bash: docker build -f docker/Dockerfile-backend --target build --build-arg SEMVER=$(GitVersion.FullSemVer) -t backend-build-stage .;
id=$(docker create backend-build-stage);
mkdir out;
docker cp $id:/app/build/test-results ./out/results;
docker rm $id;
displayName: Run Docker build stage
- task: PublishTestResults@2
inputs:
testRunner: JUnit
testResultsFiles: 'out/results/**/TEST-*.xml'
failTaskOnFailedTests: true
testRunTitle: Backend Build Tests
- task: Docker@2
displayName: Build final image
inputs:
command: build
repository: specmore/spectacular-backend-test-candidate
containerRegistry: $(dockerHubServiceConnection)
buildContext: .
dockerfile: 'docker/Dockerfile-backend'
arguments: --build-arg SEMVER=$(GitVersion.FullSemVer)
tags: |
$(tag)
$(GitVersion.SemVer)
- task: Docker@2
displayName: Push image to container registry
inputs:
command: push
repository: specmore/spectacular-backend-test-candidate
buildContext: .
dockerfile: 'docker/Dockerfile-backend'
containerRegistry: $(dockerHubServiceConnection)
tags: |
$(tag)
$(GitVersion.SemVer)
- job: BuildWeb
displayName: Build Web App image
dependsOn: SetVersion
variables:
GitVersion.SemVer: $[ dependencies.SetVersion.outputs['GitVersionTask.GitVersion.SemVer'] ]
GitVersion.FullSemVer: $[ dependencies.SetVersion.outputs['GitVersionTask.GitVersion.FullSemVer'] ]
GitVersion.ShortSha: $[ dependencies.SetVersion.outputs['GitVersionTask.GitVersion.ShortSha'] ]
pool:
vmImage: $(vmImageName)
steps:
- bash: docker build -f docker/Dockerfile-web --target build --build-arg SEMVER=$(GitVersion.FullSemVer) -t web-build-stage .;
id=$(docker create web-build-stage);
mkdir out;
docker cp $id:/usr/src/app/out/results ./out/results;
docker rm $id;
displayName: Run Docker build stage
- task: PublishTestResults@2
inputs:
testRunner: JUnit
testResultsFiles: 'out/results/**/junit.xml'
failTaskOnFailedTests: true
testRunTitle: Web Build Tests
- task: Docker@2
displayName: Build final image
inputs:
command: build
repository: specmore/spectacular-web-test-candidate
containerRegistry: $(dockerHubServiceConnection)
buildContext: .
dockerfile: 'docker/Dockerfile-web'
arguments: --build-arg SEMVER=$(GitVersion.FullSemVer) --build-arg SHORTSHA=$(GitVersion.ShortSha)
tags: |
$(tag)
$(GitVersion.SemVer)
- task: Docker@2
displayName: Push image to container registry
inputs:
command: push
repository: specmore/spectacular-web-test-candidate
buildContext: .
dockerfile: 'docker/Dockerfile-web'
containerRegistry: $(dockerHubServiceConnection)
tags: |
$(tag)
$(GitVersion.SemVer)
- stage: IntegrationTesting
displayName: Integration Testing
jobs:
- job: E2EUITests
displayName: End to End UI Tests
pool:
vmImage: $(vmImageName)
steps:
- bash: scripts/run-int-tests.ci.sh
displayName: Run integration tests
- task: PublishTestResults@2
inputs:
testRunner: JUnit
testResultsFiles: '**/results/tests.xml'
failTaskOnFailedTests: true
testRunTitle: E2E UI Tests
- bash: if [ -d integration-tests/ui-e2e/cypress/screenshots ]; then
echo "##vso[task.setVariable variable=SCREENSHOTSEXIST]true";
fi;
if [ -d integration-tests/ui-e2e/cypress/videos ]; then
echo "##vso[task.setVariable variable=VIDEOSEXIST]true";
fi;
displayName: Check artifacts exist
condition: always()
- task: PublishPipelineArtifact@1
displayName: Publish Screenshots
condition: eq(variables.SCREENSHOTSEXIST, 'true')
inputs:
targetPath: $(Build.SourcesDirectory)/integration-tests/ui-e2e/cypress/screenshots
artifactName: E2E UI Tests Screenshots
- task: PublishPipelineArtifact@1
displayName: Publish Videos
condition: eq(variables.VIDEOSEXIST, 'true')
inputs:
targetPath: $(Build.SourcesDirectory)/integration-tests/ui-e2e/cypress/videos
artifactName: E2E UI Tests Videos
- stage: CreateReleaseCandidate
displayName: Tag images as Release Candidates
jobs:
- job: TagImage
displayName: Tag and Push images
pool:
vmImage: $(vmImageName)
steps:
- task: gitversion/setup@0
displayName: Install GitVersion
inputs:
versionSpec: '5.x'
- task: gitversion/execute@0
name: GitVersion
displayName: Use GitVersion
- bash: echo ShortSha $(GitVersion.ShortSha);
echo SemVer $(GitVersion.SemVer);
echo FullSemVer $(GitVersion.FullSemVer);
displayName: Display versions
- task: Docker@2
displayName: Login to ACR
inputs:
command: login
containerRegistry: $(dockerHubServiceConnection)
- task: Docker@2
displayName: Pull backend Test Candidate image
inputs:
command: pull
arguments: docker.io/specmore/spectacular-backend-test-candidate:$(tag)
- task: Docker@2
displayName: Tag backend Release Candidate image
inputs:
command: tag
arguments: docker.io/specmore/spectacular-backend-test-candidate:$(tag) docker.io/specmore/spectacular-backend-release-candidate:$(tag)
- task: Docker@2
displayName: SemVer Tag backend Release Candidate image
inputs:
command: tag
arguments: docker.io/specmore/spectacular-backend-test-candidate:$(tag) docker.io/specmore/spectacular-backend-release-candidate:$(GitVersion.SemVer)
- task: Docker@2
displayName: Push backend Release Candidate image
inputs:
command: push
containerRegistry: $(dockerHubServiceConnection)
repository: specmore/spectacular-backend-release-candidate
tags: |
$(tag)
$(GitVersion.SemVer)
- task: Docker@2
displayName: Pull web Test Candidate image
inputs:
command: pull
arguments: docker.io/specmore/spectacular-web-test-candidate:$(tag)
- task: Docker@2
displayName: Tag web Release Candidate image
inputs:
command: tag
arguments: docker.io/specmore/spectacular-web-test-candidate:$(tag) docker.io/specmore/spectacular-web-release-candidate:$(tag)
- task: Docker@2
displayName: SemVer Tag web Release Candidate image
inputs:
command: tag
arguments: docker.io/specmore/spectacular-web-test-candidate:$(tag) docker.io/specmore/spectacular-web-release-candidate:$(GitVersion.SemVer)
- task: Docker@2
displayName: Push web Release Candidate image
inputs:
command: push
containerRegistry: $(dockerHubServiceConnection)
repository: specmore/spectacular-web-release-candidate
tags: |
$(tag)
$(GitVersion.SemVer)