forked from Minds/front
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
394 lines (365 loc) · 9.83 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
image: minds/ci-front:latest
stages:
- test and build
- prepare
- 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'
test:
image: circleci/node:13-browsers
stage: test and build
script:
- npm ci
- npm run test -- --no-watch --no-progress --browsers=ChromeHeadlessCI
lint:
stage: test and build
script:
- npm i -g prettier@"^1.19.1"
- prettier --check "src/**/*.ts"
- prettier --check "src/**/*.scss"
- prettier --check "src/**/*.html"
############
# QA Stage #
############
.cypress_tests: &cypress_tests
image: cypress/browsers:node12.13.0-chrome80-ff74
stage: qa
variables:
CYPRESS_INSTALL_BINARY: 6.2.0
script:
- npm ci
- >
if [ "$CI_BUILD_REF_NAME" == "master" ]; then
export E2E_DOMAIN=https://www.minds.com
export PRODUCTION=true
else
export E2E_DOMAIN=https://$CI_BUILD_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://gitlab-ci-token:${CI_JOB_TOKEN}@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)
- if [ $BRANCH_EXISTS == "1" ] ; then
- echo "Matching branch exists, checking out $CI_BUILD_REF_NAME..."
- cd ./cypress-tests
- git checkout $CI_BUILD_REF_NAME 2>/dev/null
- cd ..
- fi;
- echo "Running Cypress"
- >
$(npm 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 captcha_bypass_key=$CYPRESS_bypass_key,production=$PRODUCTION,captcha_shared_key=$CYPRESS_shared_key
artifacts:
when: always
paths:
- cypress/screenshots
- cypress/videos
cache:
paths:
- .npm
- cache/Cypress
qa:sandbox:
parallel: 8
allow_failure: false
except:
- /^master$/
- feat/1732-block-refactor
<<: *cypress_tests
qa:production:
parallel: 8
allow_failure: true
only:
- /^master$/
<<: *cypress_tests
# qa:manual:
# stage: qa
# script:
# - echo "Manually approved"
# when: manual
# only:
# refs:
# - master
# - production
# - test/gitlab-ci
# allow_failure: false
###############
# Build Stage #
###############
build:review:
stage: test and build
before_script:
- sed -ri "s|'VERSION'|'$CI_PIPELINE_ID'|" src/environments/environment.prod.ts
script:
- npm ci && npm install -g gulp-cli
- npm run postinstall
- sh build/ng9-bundles.sh
- sh build/ng9-remove-locale-assets.sh # Remove assets from locales
artifacts:
name: '$CI_COMMIT_REF_SLUG'
paths:
- dist
except:
refs:
- master
- production
- test/gitlab-ci
- feat/1732-block-refactor
tags:
- angular
build:production:bundles:
stage: test and build
before_script:
- sed -ri "s|'VERSION'|'$CI_PIPELINE_ID'|" src/environments/environment.prod.ts
script:
- npm ci && npm install -g gulp-cli
- npm run postinstall
- sh build/ng9-bundles.sh
- sh build/ng9-remove-locale-assets.sh # Remove assets from locales
artifacts:
name: '$CI_COMMIT_REF_SLUG'
paths:
- dist/browser
- dist/server
- dist/embed
only:
refs:
- master
- production
- test/gitlab-ci
- feat/1732-block-refactor
tags:
- angular
#################
# Prepare Stage #
#################
.sentry_prepare: &sentry_prepare
stage: prepare
image: getsentry/sentry-cli
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: minds/ci:latest
services:
- docker:dind
script:
- docker login -u gitlab-ci-token -p ${CI_BUILD_TOKEN} ${CI_REGISTRY}
- docker build -t $CI_REGISTRY_IMAGE/server:$CI_PIPELINE_ID -f containers/server/Dockerfile dist/.
- docker push $CI_REGISTRY_IMAGE/server:$CI_PIPELINE_ID
dependencies:
- build:review
except:
refs:
- master
- production
- test/gitlab-ci
- feat/1732-block-refactor
prepare:review:sentry:
<<: *sentry_prepare
variables:
SOURCEMAP_PREFIX: '~/browser'
except:
refs:
- master
- production
- test/gitlab-ci
- feat/1732-block-refactor
dependencies:
- build:review
prepare:production:
stage: prepare
image: minds/ci:latest
services:
- docker:dind
script:
- docker login -u gitlab-ci-token -p ${CI_BUILD_TOKEN} ${CI_REGISTRY}
- docker build -t $CI_REGISTRY_IMAGE/server:$CI_PIPELINE_ID -f containers/server/Dockerfile dist/.
- docker push $CI_REGISTRY_IMAGE/server:$CI_PIPELINE_ID
- docker tag $CI_REGISTRY_IMAGE/server:$CI_PIPELINE_ID $CI_REGISTRY_IMAGE/server:latest
- docker push $CI_REGISTRY_IMAGE/server:latest
only:
refs:
- master
- production
- test/gitlab-ci
- feat/1732-block-refactor
dependencies:
- build:production:bundles
prepare:production:sentry:
<<: *sentry_prepare
variables:
SOURCEMAP_PREFIX: '~/front/dist/browser'
only:
refs:
- master
- production
- test/gitlab-ci
- feat/1732-block-refactor
dependencies:
- build:production:bundles
################
# Review Stage #
################
.cleanup_review: &cleanup_review
image: minds/helm-eks:latest
script:
- aws eks update-kubeconfig --name=sandbox
- helm del --purge $CI_BUILD_REF_SLUG
environment:
name: review/$CI_COMMIT_REF_NAME
url: https://$CI_BUILD_REF_SLUG.$KUBE_INGRESS_BASE_DOMAIN
action: stop
variables:
GIT_STRATEGY: none
except:
refs:
- master
- production
- test/gitlab-ci
- feat/1732-block-refactor
review:start:
stage: review
image: minds/helm-eks:latest
script:
- aws eks update-kubeconfig --name=sandbox
- git clone --branch=master https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/minds/helm-charts.git
- "helm upgrade \
--install \
--reuse-values \
--set front.image.repository=$CI_REGISTRY_IMAGE/server \
--set-string front.image.tag=$CI_PIPELINE_ID \
--set domain=$CI_BUILD_REF_SLUG.$KUBE_INGRESS_BASE_DOMAIN \
--set elasticsearch.clusterName=$CI_BUILD_REF_SLUG--elasticsearch \
--wait \
$CI_BUILD_REF_SLUG \
./helm-charts/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_BUILD_REF_SLUG.$KUBE_INGRESS_BASE_DOMAIN
on_stop: review:stop
except:
refs:
- master
- production
- test/gitlab-ci
- feat/1732-block-refactor
review:stop:
<<: *cleanup_review
stage: review
when: manual
################
# Deploy Stage #
################
.deploy: &deploy
image: minds/ci:latest
services:
- docker:dind
script:
## Sync assets with CDN
- aws s3 sync dist $S3_REPOSITORY_URL --cache-control max-age=31536000
- $(aws ecr get-login --no-include-email --region us-east-1)
## Update docker server container
- docker login -u gitlab-ci-token -p ${CI_BUILD_TOKEN} ${CI_REGISTRY}
- docker pull $CI_REGISTRY_IMAGE/server:$CI_PIPELINE_ID
- docker tag $CI_REGISTRY_IMAGE/server:$CI_PIPELINE_ID $ECR_REPOSITORY_URL:$IMAGE_LABEL
- docker push $ECR_REPOSITORY_URL:$IMAGE_LABEL
## Deploy the new container in rolling restart
- aws ecs update-service --service=$ECS_SERVICE --force-new-deployment --region us-east-1 --cluster=$ECS_CLUSTER
## Update sentry
- sentry-cli releases deploys $CI_PIPELINE_ID new -e $IMAGE_LABEL
dependencies:
- build:production:bundles
staging:fpm:
<<: *deploy
stage: deploy:staging
variables:
IMAGE_LABEL: 'staging'
ECS_SERVICE: $ECS_APP_STAGING_SERVICE
environment:
name: staging
url: https://www.minds.com # requires staging cookie
only:
refs:
- master
- test/gitlab-ci
- feat/1732-block-refactor
review:preprod:
<<: *deploy
stage: review
when: manual
allow_failure: true
variables:
IMAGE_LABEL: 'preprod'
ECS_SERVICE: $ECS_APP_PREPROD_SERVICE
environment:
name: preprod
url: https://www.minds.com # requires preprod cookie
only:
refs:
- epic/angular-9
deploy:canary:
<<: *deploy
stage: deploy:canary
variables:
IMAGE_LABEL: 'canary'
ECS_SERVICE: $ECS_APP_CANARY_SERVICE
environment:
name: canary
url: https://www.minds.com/?canary=1 # requires canary cookie
when: manual
allow_failure: true
only:
refs:
- master
- test/gitlab-ci
- epic/angular-9
- feat/1732-block-refactor
deploy:production:
<<: *deploy
stage: deploy:production
variables:
IMAGE_LABEL: 'production'
ECS_SERVICE: $ECS_APP_PRODUCTION_SERVICE
environment:
name: production
url: https://www.minds.com
when: manual
only:
refs:
- master
- test/gitlab-ci
#################
# Cleanup stage #
#################
cleanup:review: # We stop the review site after the e2e tests have run
<<: *cleanup_review
stage: cleanup
when: manual
except:
refs:
- master
- production
- test/gitlab-ci
- feat/1732-block-refactor