-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathazure-pipelines.yml
253 lines (240 loc) · 8.14 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
trigger:
branches:
include:
- '*'
tags:
include:
- '*'
name: $(BuildID)-$(Build.SourceBranchName)
pool:
vmImage: 'ubuntu-latest'
variables:
${{ if notIn(variables['Build.SourceBranch'], 'refs/heads/master', 'refs/tags/develop') }}:
buildImage: false
deployService: false
deployEnvironment: 'no'
imageTags: 'no'
apiServiceName: 'no'
executorServiceName: 'no'
controlPanelServiceName: 'no'
${{ if eq(variables['Build.SourceBranch'], 'refs/tags/develop') }}:
buildImage: true
deployService: true
deployEnvironment: development
imageTags: |
$(Build.BuildId)
develop
apiServiceName: olympiad-dev_api
executorServiceName: olympiad-dev_executor
controlPanelServiceName: 'olympiad-dev_control-panel'
${{ if eq(variables['Build.SourceBranch'], 'refs/heads/master') }}:
buildImage: true
deployService: true
deployEnvironment: production
imageTags: |
$(Build.BuildId)
latest
apiServiceName: olympiad_api
executorServiceName: olympiad_executor
controlPanelServiceName: 'olympiad_control-panel'
stages:
- stage: build
displayName: build services
jobs:
- job: build
strategy:
matrix:
api:
cakeTarget: PublishApi
publishPath: deploy/api
artifactName: api-build
executor:
cakeTarget: PublishExecutor
publishPath: deploy/executor
artifactName: executor-build
control-panel:
cakeTarget: PublishControlPanel
publishPath: deploy/control-panel
artifactName: control-panel-build
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '8.0.101'
includePreviewVersions: true
- task: Cake@2
displayName: build service
env:
BUILD_NUMBER: $(Build.BuildId)
SENTRY_AUTH_TOKEN: $(SENTRY_AUTH_TOKEN)
SENTRY_ORG: $(SENTRY_ORG)
SENTRY_PROJECT: $(SENTRY_PROJECT)
SENTRY_URL: $(SENTRY_URL)
inputs:
script: 'build.cake'
target: $(cakeTarget)
verbosity: 'Verbose'
- publish: $(publishPath)
artifact: $(artifactName)
displayName: publish $(artifactName)
- stage: test
jobs:
- job: e2e
steps:
- task: DownloadPipelineArtifact@2
displayName: download api build
inputs:
artifactName: 'api-build'
buildType: 'current'
targetPath: 'deploy/api'
- task: DownloadPipelineArtifact@2
displayName: download executor build
inputs:
artifactName: 'executor-build'
buildType: 'current'
targetPath: 'deploy/executor'
- task: DownloadPipelineArtifact@2
displayName: download control-panel build
inputs:
artifactName: 'control-panel-build'
buildType: 'current'
targetPath: 'deploy/control-panel'
- powershell: ./generateTestStack.ps1
workingDirectory: ./tests/e2e
displayName: generate test env stack file
env:
OLYMPIAD_SERVICE_TAG: $(Build.BuildId)
OLYMPIAD_PRIVATE_REGISTRY_LOGIN: $(registryLogin)
OLYMPIAD_PRIVATE_REGISTRY_PASSWORD: $(registryPassword)
- script: docker-compose -f stack.yml build api control-panel executor
workingDirectory: ./tests/e2e
displayName: build test images
- script: docker-compose -f stack.yml up -d api
workingDirectory: ./tests/e2e
displayName: start api
- script: docker-compose -f stack.yml up tests
workingDirectory: ./tests/e2e
displayName: run tests
- script: docker-compose -f stack.yml logs api
workingDirectory: ./tests/e2e
displayName: show api logs
- script: docker-compose -f stack.yml logs executor
workingDirectory: ./tests/e2e
displayName: show api executor
- publish: ./tests/e2e/out
artifact: olympiad-e2e-test-results
- task: PublishTestResults@2
inputs:
testResultsFormat: JUnit
testResultsFiles: '*.xml'
searchFolder: ./tests/e2e/out
failTaskOnFailedTests: true
- stage: packInDocker
condition: and(succeeded(), ${{variables.buildImage}})
jobs:
- job: pack
strategy:
matrix:
api:
imageName: rtuitlab/olympiad-api
artifactName: api-build
executor:
imageName: rtuitlab/olympiad-executor
artifactName: executor-build
control-panel:
imageName: rtuitlab/olympiad-control-panel
artifactName: control-panel-build
steps:
- download: current
artifact: $(artifactName)
displayName: download $(artifactName)
- task: Docker@2
inputs:
containerRegistry: 'rtuitlab connection by admin'
repository: $(imageName)
command: 'buildAndPush'
Dockerfile: '$(Pipeline.Workspace)/$(artifactName)/Dockerfile'
buildContext: '$(Pipeline.Workspace)/$(artifactName)'
tags: ${{variables.imageTags}}
# deploy deprecated
# - stage: deploy
# condition: and(succeeded(), ${{variables.deployService}})
# jobs:
# - deployment: DeployApi
# displayName: Deploy api
# pool:
# vmImage: 'ubuntu-latest'
# environment: ${{variables.deployEnvironment}}
# strategy:
# runOnce:
# on:
# failure:
# steps:
# - download: none
# - task: SSH@0
# inputs:
# sshEndpoint: 'swarm manager'
# runOptions: 'commands'
# commands: 'docker service rollback ${{variables.apiServiceName}}'
# readyTimeout: '20000'
# deploy:
# steps:
# - download: none
# - task: SSH@0
# inputs:
# sshEndpoint: 'swarm manager'
# runOptions: 'commands'
# commands: 'docker service update --image rtuitlab/olympiad-api:$(Build.BuildId) ${{variables.apiServiceName}}'
# readyTimeout: '20000'
# - deployment: DeployExecutor
# displayName: Deploy executor
# pool:
# vmImage: 'ubuntu-latest'
# environment: ${{variables.deployEnvironment}}
# strategy:
# runOnce:
# on:
# failure:
# steps:
# - download: none
# - task: SSH@0
# inputs:
# sshEndpoint: 'swarm manager'
# runOptions: 'commands'
# commands: 'docker service rollback ${{variables.executorServiceName}}'
# readyTimeout: '20000'
# deploy:
# steps:
# - download: none
# - task: SSH@0
# inputs:
# sshEndpoint: 'swarm manager'
# runOptions: 'commands'
# commands: 'docker service update --image rtuitlab/olympiad-executor:$(Build.BuildId) ${{variables.executorServiceName}}'
# readyTimeout: '20000'
# - deployment: DeployControlPanel
# displayName: Deploy control panel
# pool:
# vmImage: 'ubuntu-latest'
# environment: ${{variables.deployEnvironment}}
# strategy:
# runOnce:
# on:
# failure:
# steps:
# - download: none
# - task: SSH@0
# inputs:
# sshEndpoint: 'swarm manager'
# runOptions: 'commands'
# commands: 'docker service rollback ${{variables.controlPanelServiceName}}'
# readyTimeout: '20000'
# deploy:
# steps:
# - download: none
# - task: SSH@0
# inputs:
# sshEndpoint: 'swarm manager'
# runOptions: 'commands'
# commands: 'docker service update --image rtuitlab/olympiad-control-panel:$(Build.BuildId) ${{variables.controlPanelServiceName}}'
# readyTimeout: '20000'