forked from Couchers-org/couchers
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
422 lines (393 loc) · 12 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
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
stages:
- protos
- build
- test
- preview
- release
variables:
GIT_DEPTH: 10
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_CERTDIR: "/certs"
RELEASE_BRANCH: develop
GRPC_TAG: $CI_REGISTRY/couchers/grpc:latest
PROXY_RELEASE_TAG: $CI_REGISTRY_IMAGE/proxy:latest
NGINX_RELEASE_TAG: $CI_REGISTRY_IMAGE/nginx:latest
BACKEND_RELEASE_TAG: $CI_REGISTRY_IMAGE/backend:latest
MEDIA_RELEASE_TAG: $CI_REGISTRY_IMAGE/media:latest
FRONTEND_RELEASE_TAG: $CI_REGISTRY_IMAGE/frontend:latest
VUE_RELEASE_TAG: $CI_REGISTRY_IMAGE/vue:latest
SLUG: $CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA
PROXY_TAG: $CI_REGISTRY_IMAGE/proxy:$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA
NGINX_TAG: $CI_REGISTRY_IMAGE/nginx:$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA
BACKEND_TAG: $CI_REGISTRY_IMAGE/backend:$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA
MEDIA_TAG: $CI_REGISTRY_IMAGE/media:$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA
FRONTEND_TAG: $CI_REGISTRY_IMAGE/frontend:$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA
VUE_TAG: $CI_REGISTRY_IMAGE/vue:$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHORT_SHA
default:
image: docker
services:
- docker:19.03.12-dind
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
protos:
stage: protos
image: $GRPC_TAG
inherit:
# the grpc container doesn't have docker, no need to login
default: false
script:
- cd app && ./generate_protos.sh
rules:
- changes:
- app/**/*
artifacts:
paths:
- app/
build:proxy:
stage: build
script:
- docker pull $PROXY_RELEASE_TAG || true
- docker build --build-arg version=$SLUG --cache-from $PROXY_RELEASE_TAG -t $PROXY_TAG app/proxy/
- docker push $PROXY_TAG
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
- if: $CI_COMMIT_BRANCH != $RELEASE_BRANCH
changes:
- app/pb/**/*
- app/proxy/**/*
build:nginx:
stage: build
script:
- docker pull $NGINX_RELEASE_TAG || true
- docker build --build-arg version=$SLUG --cache-from $NGINX_RELEASE_TAG -t $NGINX_TAG app/nginx/
- docker push $NGINX_TAG
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
- if: $CI_COMMIT_BRANCH != $RELEASE_BRANCH
changes:
- app/pb/**/*
- app/nginx/**/*
build:backend:
stage: build
script:
- docker pull $BACKEND_RELEASE_TAG || true
- docker build --build-arg version=$SLUG --cache-from $BACKEND_RELEASE_TAG -t $BACKEND_TAG app/backend/
- docker push $BACKEND_TAG
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
- if: $CI_COMMIT_BRANCH != $RELEASE_BRANCH
changes:
- app/pb/**/*
- app/backend/**/*
build:media:
stage: build
script:
- docker pull $MEDIA_RELEASE_TAG || true
- docker build --build-arg version=$SLUG --cache-from $MEDIA_RELEASE_TAG -t $MEDIA_TAG app/media/
- docker push $MEDIA_TAG
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
- if: $CI_COMMIT_BRANCH != $RELEASE_BRANCH
changes:
- app/pb/**/*
- app/media/**/*
build:frontend:
stage: build
script:
- docker pull $FRONTEND_RELEASE_TAG || true
- docker build --build-arg version=$SLUG --cache-from $FRONTEND_RELEASE_TAG -t $FRONTEND_TAG app/frontend/
- docker push $FRONTEND_TAG
# creates a new docker container (docker create returns the container name), and copies the /app folder to the host
- mkdir -p artifacts && docker cp $(docker create $FRONTEND_TAG):/app/build artifacts/frontend
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
- if: $CI_COMMIT_BRANCH != $RELEASE_BRANCH
changes:
- app/pb/**/*
- app/frontend/**/*
artifacts:
paths:
- artifacts/frontend/
build:vue:
stage: build
script:
- docker pull $VUE_RELEASE_TAG || true
- docker build --build-arg version=$SLUG --cache-from $VUE_RELEASE_TAG -t $VUE_TAG app/vue/
- docker push $VUE_TAG
# creates a new docker container (docker create returns the container name), and copies the /app folder to the host
- mkdir -p artifacts && docker cp $(docker create $VUE_TAG):/app/dist artifacts/vue
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
- if: $CI_COMMIT_BRANCH != $RELEASE_BRANCH
changes:
- app/pb/**/*
- app/vue/**/*
artifacts:
paths:
- artifacts/vue/
test:backend:
stage: test
image: $BACKEND_TAG
inherit:
# no docker login
default: false
services:
- name: postgis/postgis:13-3.0
alias: postgres
variables:
POSTGRES_PASSWORD: c765064a49d18a95
DATABASE_CONNECTION_STRING: "postgresql://postgres:c765064a49d18a95@postgres/postgres"
script:
- cd /app && pytest --junitxml=junit.xml --cov=couchers src
after_script:
- cd /app && coverage xml && coverage html
- cp /app/junit.xml $CI_PROJECT_DIR/
- cp /app/coverage.xml $CI_PROJECT_DIR/
- cp -a /app/htmlcov $CI_PROJECT_DIR/artifacts/
coverage: '/^TOTAL.+?(\d+\%)$/'
artifacts:
reports:
cobertura: coverage.xml
junit: junit.xml
paths:
- artifacts/htmlcov
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
- if: $CI_COMMIT_BRANCH != $RELEASE_BRANCH
changes:
- app/pb/**/*
- app/backend/**/*
test:media:
stage: test
image: $MEDIA_TAG
inherit:
# no docker login
default: false
variables:
MEDIA_SERVER_FROM_ENV: 0
script:
- cd /app && pytest src --junitxml=junit.xml
after_script:
- cp /app/junit.xml $CI_PROJECT_DIR/junit.xml
artifacts:
reports:
junit: junit.xml
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
- if: $CI_COMMIT_BRANCH != $RELEASE_BRANCH
changes:
- app/pb/**/*
- app/media/**/*
test:frontend:
stage: test
image: $FRONTEND_TAG
inherit:
# no docker login
default: false
script:
- cd /app && yarn test-ci
after_script:
- cp /app/junit.xml $CI_PROJECT_DIR/
- cp /app/coverage/cobertura-coverage.xml $CI_PROJECT_DIR/
- cp -a /app/coverage/lcov-report $CI_PROJECT_DIR/artifacts/
coverage: '/^All files[^|]*\|[^|]*\s+([\d\.]+)/'
artifacts:
reports:
cobertura: cobertura-coverage.xml
junit: junit.xml
paths:
- artifacts/lcov-report
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
- if: $CI_COMMIT_BRANCH != $RELEASE_BRANCH
changes:
- app/pb/**/*
- app/frontend/**/*
test:storybook:
stage: test
image: $FRONTEND_TAG
inherit:
# no docker login
default: false
script:
- cd /app && yarn build-storybook
- cp -a /app/storybook-static $CI_PROJECT_DIR/artifacts/
artifacts:
paths:
- artifacts/storybook-static
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
- if: $CI_COMMIT_BRANCH != $RELEASE_BRANCH
changes:
- app/pb/**/*
- app/frontend/**/*
preview:backend-coverage:
stage: preview
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest
inherit:
# no docker login
default: false
script:
- aws s3 cp artifacts/htmlcov s3://$AWS_PREVIEW_BUCKET/bcov/$CI_COMMIT_SHORT_SHA/ --recursive
- aws s3 cp artifacts/htmlcov s3://$AWS_PREVIEW_BUCKET/bcov/$CI_COMMIT_REF_SLUG/ --recursive
- echo "Done, coverage report available at https://$CI_COMMIT_SHORT_SHA--bcov.preview.coucher.org/ and https://$CI_COMMIT_REF_SLUG--bcov.preview.coucher.org/"
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
- if: $CI_COMMIT_BRANCH != $RELEASE_BRANCH
changes:
- app/pb/**/*
- app/backend/**/*
preview:frontend:
stage: preview
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest
inherit:
# no docker login
default: false
script:
- aws s3 cp artifacts/frontend s3://$AWS_PREVIEW_BUCKET/frontend/$CI_COMMIT_SHORT_SHA/ --recursive
- aws s3 cp artifacts/frontend s3://$AWS_PREVIEW_BUCKET/frontend/$CI_COMMIT_REF_SLUG/ --recursive
- echo "Done, preview available at https://$CI_COMMIT_SHORT_SHA--frontend.preview.coucher.org/ and https://$CI_COMMIT_REF_SLUG--frontend.preview.coucher.org/"
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
- if: $CI_COMMIT_BRANCH != $RELEASE_BRANCH
changes:
- app/pb/**/*
- app/frontend/**/*
preview:frontend-coverage:
stage: preview
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest
inherit:
# no docker login
default: false
script:
- aws s3 cp artifacts/lcov-report s3://$AWS_PREVIEW_BUCKET/fcov/$CI_COMMIT_SHORT_SHA/ --recursive
- aws s3 cp artifacts/lcov-report s3://$AWS_PREVIEW_BUCKET/fcov/$CI_COMMIT_REF_SLUG/ --recursive
- echo "Done, coverage report available at https://$CI_COMMIT_SHORT_SHA--fcov.preview.coucher.org/ and https://$CI_COMMIT_REF_SLUG--fcov.preview.coucher.org/"
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
- if: $CI_COMMIT_BRANCH != $RELEASE_BRANCH
changes:
- app/pb/**/*
- app/frontend/**/*
preview:storybook:
stage: preview
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest
inherit:
# no docker login
default: false
script:
- aws s3 cp artifacts/storybook-static s3://$AWS_PREVIEW_BUCKET/storybook/$CI_COMMIT_SHORT_SHA/ --recursive
- aws s3 cp artifacts/storybook-static s3://$AWS_PREVIEW_BUCKET/storybook/$CI_COMMIT_REF_SLUG/ --recursive
- echo "Done, storybook available at https://$CI_COMMIT_SHORT_SHA--storybook.preview.coucher.org/ and https://$CI_COMMIT_REF_SLUG--storybook.preview.coucher.org/"
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
- if: $CI_COMMIT_BRANCH != $RELEASE_BRANCH
changes:
- app/pb/**/*
- app/frontend/**/*
preview:vue:
stage: preview
image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest
inherit:
# no docker login
default: false
script:
- aws s3 cp artifacts/vue s3://$AWS_PREVIEW_BUCKET/vue/$CI_COMMIT_SHORT_SHA/ --recursive
- aws s3 cp artifacts/vue s3://$AWS_PREVIEW_BUCKET/vue/$CI_COMMIT_REF_SLUG/ --recursive
- echo "Done, preview available at https://$CI_COMMIT_SHORT_SHA--vue.preview.coucher.org/ and https://$CI_COMMIT_REF_SLUG--vue.preview.coucher.org/"
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
- if: $CI_COMMIT_BRANCH != $RELEASE_BRANCH
changes:
- app/pb/**/*
- app/vue/**/*
release:proxy:
stage: release
script:
- docker pull $PROXY_TAG
- docker tag $PROXY_TAG $PROXY_RELEASE_TAG
- docker push $PROXY_RELEASE_TAG
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
release:nginx:
stage: release
script:
- docker pull $NGINX_TAG
- docker tag $NGINX_TAG $NGINX_RELEASE_TAG
- docker push $NGINX_RELEASE_TAG
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
release:backend:
stage: release
script:
- docker pull $BACKEND_TAG
- docker tag $BACKEND_TAG $BACKEND_RELEASE_TAG
- docker push $BACKEND_RELEASE_TAG
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
release:media:
stage: release
script:
- docker pull $MEDIA_TAG
- docker tag $MEDIA_TAG $MEDIA_RELEASE_TAG
- docker push $MEDIA_RELEASE_TAG
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
release:frontend:
stage: release
script:
- docker pull $FRONTEND_TAG
- docker tag $FRONTEND_TAG $FRONTEND_RELEASE_TAG
- docker push $FRONTEND_RELEASE_TAG
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*
release:vue:
stage: release
script:
- docker pull $VUE_TAG
- docker tag $VUE_TAG $VUE_RELEASE_TAG
- docker push $VUE_RELEASE_TAG
rules:
- if: $CI_COMMIT_BRANCH == $RELEASE_BRANCH
changes:
- app/**/*