-
Notifications
You must be signed in to change notification settings - Fork 94
/
.gitlab-ci.yml
340 lines (312 loc) · 8.93 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
include:
- template: Security/Dependency-Scanning.gitlab-ci.yml
- template: Security/Container-Scanning.gitlab-ci.yml
stages:
- baseimage
- build
- test
- prepare
- review
- integration_testing
- deploy:staging
- qa
- deploy:canary
- deploy:production
- scan
variables:
default_php_image: registry.gitlab.com/minds/engine/php:8.2
baseimage:prepare:
stage: baseimage
image:
name: gcr.io/kaniko-project/executor:v1.14.0-debug
entrypoint: [""]
script:
- /kaniko/executor
--context "${CI_PROJECT_DIR}/containers/php"
--dockerfile "${CI_PROJECT_DIR}/containers/php/Dockerfile"
--destination "${CI_REGISTRY_IMAGE}/php:${CI_PIPELINE_ID}"
rules:
- if: '$CI_COMMIT_REF_NAME == "master"'
when: never
- if: '$CI_COMMIT_REF_NAME != "master"'
changes:
- containers/php/*
when: manual
allow_failure: true
baseimage:deploy:
stage: baseimage
image:
name: gcr.io/kaniko-project/executor:v1.14.0-debug
entrypoint: [""]
script:
- /kaniko/executor
--context "${CI_PROJECT_DIR}/containers/php"
--dockerfile "${CI_PROJECT_DIR}/containers/php/Dockerfile"
--destination "${CI_REGISTRY_IMAGE}/php:8.2"
rules:
- if: '$CI_COMMIT_REF_NAME == "master"'
changes:
- containers/php/*
- if: '$CI_COMMIT_REF_NAME != "master"'
when: never
- when: manual
allow_failure: true
build:
stage: build
image: "$default_php_image"
script:
- apk add --no-cache git
- sh tools/setup.sh production
artifacts:
name: "$CI_COMMIT_REF_SLUG"
paths:
- vendor
- bin
test:
stage: test
image: "$default_php_image"
script:
- php -n -c Spec/php-test.ini bin/phpspec run
lint:
stage: test
image: "$default_php_image"
script:
- bin/php-cs-fixer fix --allow-risky=yes --verbose --dry-run
static-analysis:
stage: test
image: "$default_php_image"
script:
- mv settings.example.php settings.php
- bin/phpstan analyse --memory-limit=1G
allow_failure: true
prepare:fpm:
stage: prepare
image:
name: gcr.io/kaniko-project/executor:v1.14.0-debug
entrypoint: [""]
script:
- /kaniko/executor
--context "${CI_PROJECT_DIR}"
--dockerfile "${CI_PROJECT_DIR}/containers/php-fpm/Dockerfile"
--destination "${CI_REGISTRY_IMAGE}/fpm:${CI_PIPELINE_ID}"
--build-arg MINDS_VERSION=$CI_PIPELINE_ID
--build-arg SENTRY_DSN=$SENTRY_DSN
prepare:rr:
stage: prepare
image:
name: gcr.io/kaniko-project/executor:v1.14.0-debug
entrypoint: [""]
script:
- /kaniko/executor
--context "${CI_PROJECT_DIR}"
--dockerfile "${CI_PROJECT_DIR}/containers/php-rr/Dockerfile"
--destination "${CI_REGISTRY_IMAGE}/rr:${CI_PIPELINE_ID}"
--build-arg MINDS_VERSION=$CI_PIPELINE_ID
--build-arg SENTRY_DSN=$SENTRY_DSN
prepare:runners:
stage: prepare
image:
name: gcr.io/kaniko-project/executor:v1.14.0-debug
entrypoint: [""]
script:
- /kaniko/executor
--context "${CI_PROJECT_DIR}"
--dockerfile "${CI_PROJECT_DIR}/containers/php-runners/Dockerfile"
--destination "${CI_REGISTRY_IMAGE}/runners:${CI_PIPELINE_ID}"
--build-arg MINDS_VERSION=$CI_PIPELINE_ID
--build-arg SENTRY_DSN=$RUNNERS_SENTRY_DSN
prepare:all:sentry:
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 finalize $CI_PIPELINE_ID
- echo "Finalized release for $CI_PIPELINE_ID"
container_scanning:
stage: scan
variables:
CS_IMAGE: $CI_REGISTRY_IMAGE/fpm:$CI_PIPELINE_ID
container_scanning_runners:
extends: container_scanning
stage: scan
variables:
CS_IMAGE: $CI_REGISTRY_IMAGE/runners:$CI_PIPELINE_ID
dependency_scanning:
stage: scan
.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
review:start:
stage: review
image: minds/ci:latest
script:
- *oci_prepare
# Download repo, use same branch name if exists
- HELM_GIT_REPO=https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.com/minds/helm-charts.git
- git clone --branch=master $HELM_GIT_REPO
- BRANCH_EXISTS=$(git ls-remote --heads $HELM_GIT_REPO $CI_COMMIT_REF_NAME | wc -l)
- cd ./helm-charts
- if [ $BRANCH_EXISTS == "1" ] ; then
- echo "Matching branch exists, checking out $CI_COMMIT_REF_NAME..."
- git checkout $CI_COMMIT_REF_NAME 2>/dev/null
- fi;
#
- echo "Upgrading helm for pipeline ${CI_PIPELINE_ID}"
- echo "Setting to image ${CI_REGISTRY_IMAGE}"
- "helm upgrade \
--install \
--namespace default \
--values ./minds/values-sandbox-oke.yaml \
--reuse-values \
--set engine.image.repository=$CI_REGISTRY_IMAGE/fpm \
--set engine.image.rrRepository=$CI_REGISTRY_IMAGE/rr \
--set-string engine.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
--set-string sockets.serverUri=$CI_COMMIT_REF_SLUG-sockets.$KUBE_INGRESS_BASE_DOMAIN
--wait \
$CI_COMMIT_REF_SLUG \
./minds"
- 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
review:stop:
stage: 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
when: manual
except:
refs:
- master
- feat/ci-k8s
integration_testing:
stage: qa
image: "$default_php_image"
script:
- apk add --no-cache git
- >
if [ "$CI_COMMIT_REF_NAME" == "master" ]; then
export MINDS_DOMAIN=https://www.minds.com
else
export MINDS_DOMAIN=https://$CI_COMMIT_REF_SLUG.$KUBE_INGRESS_BASE_DOMAIN
fi
- export BYPASS_SIGNING_KEY=$BYPASS_SIGNING_KEY
- sh integration_tests/setup_and_run.sh
artifacts:
when: always
paths:
- integration_tests/tests/_output
allow_failure: true
# qa:manual:
# stage: qa
# script:
# - echo "Manually approved"
# when: manual
# only:
# refs:
# - master
# - production
# - test/gitlab-ci
# allow_failure: true
################
# Deploy Stage #
################
.deploy: &deploy
stage: deploy:staging
image: minds/ci:latest
script:
# FPM
- crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- crane tag $CI_REGISTRY_IMAGE/fpm:$CI_PIPELINE_ID $IMAGE_LABEL
# RoadRunner (rr)
- crane tag $CI_REGISTRY_IMAGE/rr:$CI_PIPELINE_ID $IMAGE_LABEL
# OKE: Rolling restart
- *oci_prepare
- kubectl -n default rollout restart deployment minds-engine-$IMAGE_LABEL
# Update sentry
- sentry-cli releases deploys $CI_PIPELINE_ID new -e $IMAGE_LABEL
staging:fpm:
<<: *deploy
after_script:
- crane tag $CI_REGISTRY_IMAGE/fpm:$CI_PIPELINE_ID latest
- crane tag $CI_REGISTRY_IMAGE/rr:$CI_PIPELINE_ID latest
stage: deploy:staging
variables:
IMAGE_LABEL: "staging"
environment:
name: staging
url: https://www.minds.com/?staging=1
only:
refs:
- master
- test/gitlab-ci
allow_failure: true
canary:fpm:
<<: *deploy
stage: deploy:canary
variables:
IMAGE_LABEL: "canary"
only:
refs:
- master
environment:
name: canary
url: https://www.minds.com/?canary=1 # requires canary cookie
when: manual
allow_failure: true
production:fpm:
<<: *deploy
stage: deploy:production
variables:
IMAGE_LABEL: "production"
only:
refs:
- master
environment:
name: production
url: https://www.minds.com/
when: manual
production:runners:
stage: deploy:production
image: minds/ci:latest
script:
- IMAGE_LABEL="production"
- crane auth login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- crane tag $CI_REGISTRY_IMAGE/runners:$CI_PIPELINE_ID $IMAGE_LABEL
- crane tag $CI_REGISTRY_IMAGE/runners:$CI_PIPELINE_ID latest
# OKE: Rolling restart
- *oci_prepare
- kubectl -n default get deployments | grep minds-runners- | awk '{print $1}' | xargs kubectl -n default rollout restart deployment
only:
refs:
- master
- test/gitlab-ci
environment:
name: runners
url: https://www.minds.com/