-
Notifications
You must be signed in to change notification settings - Fork 93
/
.gitlab-ci.yml
492 lines (456 loc) · 11.8 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
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
include:
- template: Security/Dependency-Scanning.gitlab-ci.yml
- template: Security/Container-Scanning.gitlab-ci.yml
stages:
- test and build
- prepare
- scan
- review
- deploy:staging
- qa
- deploy:canary
- deploy:production
- cleanup
variables:
CYPRESS_INSTALL_BINARY: "0" # Speeds up the install process
npm_config_cache: '$CI_PROJECT_DIR/.npm'
CYPRESS_CACHE_FOLDER: '$CI_PROJECT_DIR/cache/Cypress'
FF_USE_FASTZIP: "1"
cache:
key:
files:
- package.json
prefix: ${CI_JOB_NAME}
paths:
- node_modules/
test:
image: cypress/browsers:latest
stage: test and build
script:
- npm install -g npm@7
- npm i
- NODE_OPTIONS=--max_old_space_size=4096
- npm run test -- --no-watch --no-progress --browsers=ChromeHeadlessCI
except:
variables:
- $CI_NIGHTLY_TESTS == "true"
lint:
stage: test and build
image: minds/ci-front:18
script:
- npm i -g prettier@"~3.2.5"
- prettier --check "src/**/*.ts"
- prettier --check "src/**/*.scss"
- prettier --check "src/**/*.html"
except:
variables:
- $CI_NIGHTLY_TESTS == "true"
############
# QA Stage #
############
.cypress_tests: &cypress_tests
image: cypress/browsers:node18.12.0-chrome107
stage: qa
variables:
CYPRESS_INSTALL_BINARY: "7.4.0"
script:
- >
if [ "$CI_BUILD_REF_NAME" == "master" ]; then
export E2E_DOMAIN=https://www.minds.com
export PRODUCTION=true
else
export E2E_DOMAIN=https://$CI_COMMIT_REF_SLUG.$KUBE_INGRESS_BASE_DOMAIN
export PRODUCTION=false
fi
- export CYPRESS_baseUrl=$E2E_DOMAIN
- echo "Preparing E2E tests for $CI_BUILD_REF_NAME running against $E2E_DOMAIN with user $CYPRESS_username"
- git clone --branch=master https://$CI_REGISTRY_USER:${CI_REGISTRY_PASSWORD}@gitlab.com/minds/cypress-tests.git
- echo "Checking if branch exists..."
- BRANCH_EXISTS=$(git ls-remote --heads https://www.gitlab.com/minds/cypress-tests $CI_BUILD_REF_NAME | wc -l)
- cd ./cypress-tests
- if [ $BRANCH_EXISTS == "1" ] ; then
- echo "Matching branch exists, checking out $CI_BUILD_REF_NAME..."
- git checkout $CI_BUILD_REF_NAME 2>/dev/null
- fi;
- npm i
- echo "Running Cypress"
- >
./node_modules/.bin/cypress run --browser chrome
--parallel
--record
--ci-build-id $CI_PIPELINE_ID
--group "minds-e2e"
--key $CYPRESS_RECORD_ID
--config baseUrl=$E2E_DOMAIN
--env shared_key=$CYPRESS_bypass_key,production=$PRODUCTION
artifacts:
when: always
paths:
- cypress/screenshots
- cypress/videos
cache:
paths:
- .npm
- cache/Cypress
# qa:sandbox:
# parallel: 2
# except:
# refs:
# - /^master$/
# - feat/1732-block-refactor
# variables:
# - $CI_NIGHTLY_TESTS == "true"
# <<: *cypress_tests
.playwright_tests: &playwright_tests
image: mcr.microsoft.com/playwright:v1.27.0-focal
stage: qa
script:
- >
if [ "$CI_COMMIT_REF_NAME" == "master" ]; then
export E2E_DOMAIN=https://www.minds.com
else
export E2E_DOMAIN=https://$CI_COMMIT_REF_SLUG.$KUBE_INGRESS_BASE_DOMAIN
fi
- export BYPASS_SIGNING_KEY=$BYPASS_SIGNING_KEY
- sh ./e2e/test/setup_and_run.sh
artifacts:
when: always
paths:
- e2e/test/error-screenshots
- e2e/test/error-screenshots/videos
cache:
paths:
- .npm
- cache/Cypress
qa:e2e:
except:
refs:
- /^master$/
- feat/1732-block-refactor
variables:
- $CI_NIGHTLY_TESTS == "true"
<<: *playwright_tests
qa:nightly:
allow_failure: true
only:
refs:
- /^master$/
variables:
- $CI_NIGHTLY_TESTS == "true"
<<: *playwright_tests
# qa:production:
# parallel: 1
# allow_failure: true
# only:
# - /^master$/
# <<: *cypress_tests
# qa:manual:
# stage: qa
# script:
# - echo "Manually approved"
# when: manual
# only:
# refs:
# - master
# - production
# - test/gitlab-ci
# except:
# variables:
# - $CI_NIGHTLY_TESTS == "true"
# allow_failure: true
###############
# Build Stage #
###############
build:review:
stage: test and build
image: minds/ci-front:18
before_script:
- sed -ri "s|'VERSION'|'$CI_PIPELINE_ID'|" src/environments/environment.prod.ts
script:
- npm i && npm install -g gulp-cli
- sh build/ng-bundles.sh
- sh build/ng-remove-locale-assets.sh # Remove assets from locales
artifacts:
name: '$CI_COMMIT_REF_SLUG'
paths:
- dist
except:
refs:
- master
# - test/gitlab-ci
variables:
- $CI_NIGHTLY_TESTS == "true"
tags:
- angular
build:production:bundles:
stage: test and build
image: minds/ci-front:18
before_script:
- sed -ri "s|'VERSION'|'$CI_PIPELINE_ID'|" src/environments/environment.prod.ts
script:
- npm i && npm install -g gulp-cli
- sh build/ng-bundles.sh
- sh build/ng-remove-locale-assets.sh # Remove assets from locales
artifacts:
name: '$CI_COMMIT_REF_SLUG'
paths:
- dist/browser
- dist/server
- dist/embed
- dist/storybook
only:
refs:
- master
- test/gitlab-ci
except:
variables:
- $CI_NIGHTLY_TESTS == "true"
tags:
- angular
#################
# Prepare Stage #
#################
.sentry_prepare: &sentry_prepare
stage: prepare
image: getsentry/sentry-cli:2.31.0
script:
- echo "Create a new release $CI_PIPELINE_ID"
- sentry-cli releases new $CI_PIPELINE_ID
- sentry-cli releases set-commits --auto $CI_PIPELINE_ID
- sentry-cli releases files $CI_PIPELINE_ID upload-sourcemaps $CI_PROJECT_DIR/dist/browser -x .js -x .map --validate --url-prefix $SOURCEMAP_PREFIX
- sentry-cli releases finalize $CI_PIPELINE_ID
- echo "Finalized release for $CI_PIPELINE_ID"
prepare:review:
stage: prepare
image:
name: gcr.io/kaniko-project/executor:v1.14.0-debug
entrypoint: [""]
script:
- /kaniko/executor
--context "${CI_PROJECT_DIR}/dist"
--dockerfile "${CI_PROJECT_DIR}/containers/server/Dockerfile"
--destination "${CI_REGISTRY_IMAGE}/server:$CI_PIPELINE_ID"
dependencies:
- build:review
except:
refs:
- master
# - test/gitlab-ci
variables:
- $CI_NIGHTLY_TESTS == "true"
prepare:review:sentry:
<<: *sentry_prepare
variables:
SOURCEMAP_PREFIX: '~/browser'
except:
refs:
- master
# - test/gitlab-ci
variables:
- $CI_NIGHTLY_TESTS == "true"
dependencies:
- build:review
prepare:production:
stage: prepare
image:
name: gcr.io/kaniko-project/executor:v1.14.0-debug
entrypoint: [""]
script:
- /kaniko/executor
--context "${CI_PROJECT_DIR}/dist"
--dockerfile "${CI_PROJECT_DIR}/containers/server/Dockerfile"
--destination "${CI_REGISTRY_IMAGE}/server:$CI_PIPELINE_ID"
only:
refs:
- master
- test/gitlab-ci
except:
variables:
- $CI_NIGHTLY_TESTS == "true"
dependencies:
- build:production:bundles
prepare:production:sentry:
<<: *sentry_prepare
variables:
SOURCEMAP_PREFIX: '~/front/dist/browser'
only:
refs:
- master
- test/gitlab-ci
except:
variables:
- $CI_NIGHTLY_TESTS == "true"
dependencies:
- build:production:bundles
##############
# Scan Stage #
##############
container_scanning:
stage: scan
variables:
CS_IMAGE: $CI_REGISTRY_IMAGE/server:$CI_PIPELINE_ID
dependency_scanning:
stage: scan
################
# Review Stage #
################
.oci_prepare: &oci_prepare
- mkdir ~/.oci
- cp $OCI_CONFIG ~/.oci/config
- cp $OCI_KEY /tmp/oci-key.pem
- export OCI_CLI_SUPPRESS_FILE_PERMISSIONS_WARNING=True
- |
oci ce cluster create-kubeconfig \
--cluster-id $OKE_CLUSTER_ID \
--file $KUBECONFIG \
--region us-ashburn-1 \
--token-version 2.0.0 \
--kube-endpoint PUBLIC_ENDPOINT
.cleanup_review: &cleanup_review
image: minds/ci:latest
script:
- *oci_prepare
- helm -n default del $CI_COMMIT_REF_SLUG
environment:
name: review/$CI_COMMIT_REF_NAME
url: https://$CI_COMMIT_REF_SLUG.$KUBE_INGRESS_BASE_DOMAIN
action: stop
variables:
GIT_STRATEGY: none
except:
refs:
- master
# - test/gitlab-ci
variables:
- $CI_NIGHTLY_TESTS == "true"
review:start:
stage: review
image: minds/ci:latest
script:
- *oci_prepare
# Download repo, use same branch name if exists
- HELM_GIT_REPO=https://$CI_REGISTRY_USER:${CI_REGISTRY_PASSWORD}@gitlab.com/minds/helm-charts.git
- git clone --branch=master $HELM_GIT_REPO
- BRANCH_EXISTS=$(git ls-remote --heads $HELM_GIT_REPO $CI_BUILD_REF_NAME | wc -l)
- cd ./helm-charts
- if [ $BRANCH_EXISTS == "1" ] ; then
- echo "Matching branch exists, checking out $CI_BUILD_REF_NAME..."
- git checkout $CI_BUILD_REF_NAME 2>/dev/null
- fi;
#
- "helm upgrade \
--install \
--namespace default \
--reuse-values \
--values ./minds/values-sandbox-oke.yaml
--set front.image.repository=$CI_REGISTRY_IMAGE/server \
--set-string front.image.tag=$CI_PIPELINE_ID \
--set domain=$CI_COMMIT_REF_SLUG.$KUBE_INGRESS_BASE_DOMAIN
--set cdn_domain=$CI_COMMIT_REF_SLUG.$KUBE_INGRESS_BASE_DOMAIN
--set siteUrl=https://$CI_COMMIT_REF_SLUG.$KUBE_INGRESS_BASE_DOMAIN/
--set-string environments.sandbox.routingCookie=false
--timeout 800s \
--wait \
$CI_COMMIT_REF_SLUG \
./minds"
# Update sentry
- sentry-cli releases deploys $CI_PIPELINE_ID new -e review-$CI_COMMIT_REF_SLUG
environment:
name: review/$CI_COMMIT_REF_NAME
url: https://$CI_COMMIT_REF_SLUG.$KUBE_INGRESS_BASE_DOMAIN
on_stop: review:stop
except:
refs:
- master
# - test/gitlab-ci
variables:
- $CI_NIGHTLY_TESTS == "true"
review:stop:
<<: *cleanup_review
stage: review
when: manual
except:
refs:
- master
variables:
- $CI_NIGHTLY_TESTS == "true"
################
# Deploy Stage #
################
.deploy: &deploy
image: minds/ci:latest
script:
## Sync assets with CDN
- aws s3 sync dist $S3_REPOSITORY_URL/$IMAGE_LABEL --cache-control max-age=31536000 --exact-timestamps
## Update docker server container
- crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- crane tag $CI_REGISTRY_IMAGE/server:$CI_PIPELINE_ID $IMAGE_LABEL
# OKE Deploy
- *oci_prepare
- kubectl -n default rollout restart deployment minds-front-$IMAGE_LABEL
## Update sentry
- sentry-cli releases deploys $CI_PIPELINE_ID new -e $IMAGE_LABEL
dependencies:
- build:production:bundles
staging:fpm:
<<: *deploy
after_script:
- crane tag $CI_REGISTRY_IMAGE/server:$CI_PIPELINE_ID latest
stage: deploy:staging
variables:
IMAGE_LABEL: 'staging'
environment:
name: staging
url: https://www.minds.com # requires staging cookie
only:
refs:
- master
- test/gitlab-ci
except:
variables:
- $CI_NIGHTLY_TESTS == "true"
deploy:canary:
<<: *deploy
stage: deploy:canary
variables:
IMAGE_LABEL: 'canary'
environment:
name: canary
url: https://www.minds.com/?canary=1 # requires canary cookie
when: manual
allow_failure: true
only:
refs:
- master
- test/gitlab-ci
except:
variables:
- $CI_NIGHTLY_TESTS == "true"
deploy:production:
<<: *deploy
stage: deploy:production
variables:
IMAGE_LABEL: 'production'
environment:
name: production
url: https://www.minds.com
when: manual
only:
refs:
- master
- test/gitlab-ci
except:
variables:
- $CI_NIGHTLY_TESTS == "true"
#################
# Cleanup stage #
#################
cleanup:review: # We stop the review site after the e2e tests have run
<<: *cleanup_review
stage: cleanup
when: manual
except:
refs:
- master
variables:
- $CI_NIGHTLY_TESTS == "true"