forked from mistio/mist-ce
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
370 lines (316 loc) · 9.67 KB
/
.gitlab-ci.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
stages:
- discover-submodules
- build
- deploy
- test
- undeploy
- release
#################### DISCOVER-SUBMODULES STAGE ####################
discover-submodules:
stage: discover-submodules
variables:
GIT_SUBMODULE_STRATEGY: recursive
script:
# Will fetch to get all new branches for find-submodules.sh
- git fetch -p --recurse-submodules
- ./ci/find-submodules.sh -n
- cp ci/update-pipelines.sh update-pipelines
artifacts:
paths:
- all-submodules.csv
- related-submodules.csv
- update-pipelines
expire_in: 3 days
tags:
- shell-docker-light
dependencies: []
#################### BUILD STAGE ####################
# Wait for images we depend on to become available.
.docker_wait_submodule_img_template: &docker_wait_submodule_img_template
stage: build
variables:
GIT_STRATEGY: none
NUM: "60"
SLEEP: "10"
script:
- SUBMODULE_SHA=$(grep ^$REPO, all-submodules.csv | cut -d, -f2)
- echo SUBMODULE_SHA is $SUBMODULE_SHA
- GCR_IMG="gcr.io/mist-ops/$IMG"
- DOCKERHUB_IMG="mist/$IMG"
- IMGTAG="$GCR_IMG:$SUBMODULE_SHA"
- echo IMTAG is $IMGTAG
- echo "Will pull docker image $IMGTAG"
- for i in $(seq 1 $NUM); do docker pull $IMGTAG && OK=1 && break || sleep $SLEEP; done
- if [ -z "$OK" ]; then echo "ERROR Couldn't pull $IMGTAG!" && exit 1; fi
- |
for img_name in $GCR_IMG $DOCKERHUB_IMG; do
for ref in $CI_COMMIT_SHA $CI_COMMIT_REF_SLUG; do
IMGTAG2=$img_name:io-$ref
echo "Will tag and push $IMGTAG2"
docker tag $IMGTAG $IMGTAG2
docker push $IMGTAG2
done
done
tags:
- shell-docker-light
dependencies:
- discover-submodules
wait-ui-image:
<<: *docker_wait_submodule_img_template
before_script:
- REPO=mistio/mist.ui
- IMG=ui
wait-landing-image:
<<: *docker_wait_submodule_img_template
before_script:
- REPO=mistio/mist.landing
- IMG=landing
wait-tests-image:
<<: *docker_wait_submodule_img_template
before_script:
- REPO=mistio/mist.tests
- IMG=tests_base
# Rebuild api image.
rebuild-api-image:
stage: build
variables:
NUM: "60"
SLEEP: "10"
REPO: mistio/mist.api
IMG: mist
script:
- SUBMODULE_SHA=$(grep ^$REPO, all-submodules.csv | cut -d, -f2)
- echo SUBMODULE_SHA is $SUBMODULE_SHA
- GCR_IMG="gcr.io/mist-ops/$IMG"
- DOCKERHUB_IMG="mist/$IMG"
- IMGTAG="$GCR_IMG:$SUBMODULE_SHA"
- echo IMTAG is $IMGTAG
- echo "Will pull docker image $IMGTAG"
- for i in $(seq 1 $NUM); do docker pull $IMGTAG && OK=1 && break || sleep $SLEEP; done
- if [ -z "$OK" ]; then echo "ERROR Couldn't pull $IMGTAG!" && exit 1; fi
- echo "Will rebuild api image"
- sed -i "s~^FROM.*~FROM $IMGTAG~" docker/mist/Dockerfile
- docker build -t $IMG/io-$CI_COMMIT_SHA --build-arg IO_VERSION_SHA=$CI_COMMIT_SHA --build-arg IO_VERSION_NAME=$CI_COMMIT_REF_NAME docker/mist
- |
for img_name in $GCR_IMG $DOCKERHUB_IMG; do
for ref in $CI_COMMIT_SHA $CI_COMMIT_REF_SLUG; do
IMGTAG2=$img_name:io-$ref
echo "Will tag and push $IMGTAG2"
docker tag $IMG/io-$CI_COMMIT_SHA $IMGTAG2
docker push $IMGTAG2
done
done
tags:
- shell-docker-light
dependencies:
- discover-submodules
# Build secondary images needed for deploying. Tag with SHA and branch name.
.docker_build_img_template: &docker_build_img_template
stage: build
script:
- GCR_IMG="gcr.io/mist-ops/$IMG"
- DOCKERHUB_IMG="mist/$IMG"
- IMGTAG="$GCR_IMG:$CI_COMMIT_SHA"
- echo "Will build $IMGTAG"
- cd docker/$IMG
- docker build --pull -t $IMGTAG .
- |
for img_name in $GCR_IMG $DOCKERHUB_IMG; do
for ref in $CI_COMMIT_SHA $CI_COMMIT_REF_SLUG; do
for prefix in "io-" ""; do
IMGTAG2=$img_name:$prefix$ref
echo "Will tag and push $IMGTAG2"
docker tag $IMGTAG $IMGTAG2
docker push $IMGTAG2
done
done
done
tags:
- builder
dependencies: []
build-nginx:
<<: *docker_build_img_template
variables:
IMG: nginx
build-logstash:
<<: *docker_build_img_template
variables:
IMG: logstash
build-elasticsearch-manage:
<<: *docker_build_img_template
variables:
IMG: elasticsearch-manage
# Manually build images, tag is SHA/branch independant
.docker_manual_build_img_template: &docker_manual_build_img_template
stage: build
when: manual
script:
- export TAG="${TAG:-latest}"
- echo "Will build img $IMG with tag $TAG."
- cd docker/$IMG
- docker build --pull -t gcr.io/mist-ops/$IMG:$TAG .
- docker tag gcr.io/mist-ops/$IMG:$TAG mist/$IMG:$TAG
- docker push gcr.io/mist-ops/$IMG:$TAG
- docker push mist/$IMG:$TAG
tags:
- builder
dependencies: []
build-alpine-manual:
<<: *docker_manual_build_img_template
variables:
IMG: alpine
TAG: "3.4"
build-socat-manual:
<<: *docker_manual_build_img_template
variables:
IMG: docker-socat
build-mailmock-manual:
<<: *docker_manual_build_img_template
variables:
IMG: mailmock
build-debugger-manual:
<<: *docker_manual_build_img_template
variables:
IMG: debugger
#################### DEPLOY STAGE ####################
.deploy_template: &deploy_template
stage: deploy
image: gcr.io/mist-ops/deployer
dependencies: []
script:
- ./ci/deploy.sh
tags:
- kube-default
deploy_review_env:
<<: *deploy_template
when: manual
environment:
name: review/$CI_COMMIT_REF_SLUG
url: http://$CI_COMMIT_REF_SLUG.io.review.ops.mist.io
on_stop: undeploy_review_env
variables:
NAMESPACE: io-review-$CI_COMMIT_REF_SLUG
DNS_PREFIX: $CI_COMMIT_REF_SLUG.io.review.ops
deploy_test_env:
<<: *deploy_template
environment:
name: test/$CI_COMMIT_REF_SLUG
url: http://$CI_COMMIT_REF_SLUG.io.test.ops.mist.io
on_stop: undeploy_test_env
variables:
NAMESPACE: io-test-$CI_COMMIT_REF_SLUG
DNS_PREFIX: $CI_COMMIT_REF_SLUG.io.test.ops
EXPIRE_HOURS: "12"
#################### TEST STAGE ####################
.test_template: &test_template
stage: test
image: gcr.io/mist-ops/tests_base:io-$CI_COMMIT_SHA
variables:
GIT_STRATEGY: none
MIST_URL: http://$CI_COMMIT_REF_SLUG.io.test.ops.mist.io
DISPLAY: ":1.0"
REGISTER_USER_BEFORE_FEATURE: "True"
EMAIL: fatboy.tester.mist.io+${CI_JOB_ID}@gmail.com
dependencies:
- discover-submodules
before_script:
- 'export TEST=$(echo "$CI_JOB_NAME" | cut -d/ -f1 | cut -d: -f2,3 | tr : /)'
- echo "Test argument is $TEST"
- ./update-pipelines -n io:$CI_JOB_NAME running
- echo $TEST_SETTINGS | base64 -d > test_settings.py
.api_test_template: &api_test_template
<<: *test_template
script:
- /mist.tests/prepare_env.py --api -s /mist.tests/misttests/api/$TEST.py || export FAILED=1
- ./update-pipelines -n io:$CI_JOB_NAME result
tags:
- kube-default
.ui_test_template: &ui_test_template
<<: *test_template
script:
- /mist.tests/prepare_env.py -k --stop --tags=$TEST /mist.tests/misttests/gui/core/pr/features || export FAILED=1
- ./update-pipelines -n io:$CI_JOB_NAME result
artifacts:
paths:
- js_console.log
- error*
- test.mp4
expire_in: 3 days
when: on_failure
tags:
- cpu
API:io:api_token: *api_test_template
API:io:clouds: *api_test_template
API:io:dns: *api_test_template
API:io:keys: *api_test_template
API:io:images: *api_test_template
API:io:libcloud_1/2: *api_test_template
API:io:libcloud_2/2: *api_test_template
API:io:machines: *api_test_template
API:io:networks: *api_test_template
API:io:schedules: *api_test_template
API:io:scripts: *api_test_template
UI:clouds-add-1/2: *ui_test_template
UI:clouds-add-2/2: *ui_test_template
UI:clouds-actions: *ui_test_template
UI:keys: *ui_test_template
UI:machines: *ui_test_template
UI:schedulers-1/2: *ui_test_template
UI:schedulers-2/2: *ui_test_template
UI:scripts: *ui_test_template
UI:scripts-actions: *ui_test_template
UI:images-networks: *ui_test_template
UI:user-actions: *ui_test_template
UI:rbac-teams: *ui_test_template
#################### UNDEPLOY STAGE ####################
.undeploy_template: &undeploy_template
stage: undeploy
image: gcr.io/mist-ops/deployer
dependencies: []
script:
- kubectl delete namespace $NAMESPACE
- cli53 rrdelete mist.io $DNS_PREFIX A || echo "Already deleted"
tags:
- kube-default
undeploy_review_env:
<<: *undeploy_template
when: manual
environment:
name: review/$CI_COMMIT_REF_SLUG
action: stop
variables:
NAMESPACE: io-review-$CI_COMMIT_REF_SLUG
DNS_PREFIX: $CI_COMMIT_REF_SLUG.io.review.ops
undeploy_test_env:
<<: *undeploy_template
environment:
name: test/$CI_COMMIT_REF_SLUG
action: stop
variables:
NAMESPACE: io-test-$CI_COMMIT_REF_SLUG
DNS_PREFIX: $CI_COMMIT_REF_SLUG.io.test.ops
#################### RELEASE STAGE ####################
release: &release_template
stage: release
image: python:2.7-alpine
before_script:
- apk add --update libmagic
- pip install requests python-magic
script:
- mkdir release
- sed "s/\$MIST_TAG/$CI_BUILD_REF_SLUG/g" docker-compose.yml > release/docker-compose.yml
- sed "s/TAG/$CI_BUILD_REF_NAME/g" ci/release.md > release.md
- ./ci/release.py $RELEASE_ARGS --draft -f release/* -m @release.md mistio mist.io $CI_BUILD_REF_NAME
only:
# only for references that match a version string (v1.2.3)
- /^v\d+\.\d+\.\d+$/
except:
# Except branches, meaning it'll only apply to git tags
- branches
prerelease:
<<: *release_template
variables:
RELEASE_ARGS: "--prerelease"
only:
# only for references that match a prelease version string (v1.2.3-beta)
- /^v\d+\.\d+\.\d+-.+$/