-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path.gitlab-ci.yml
420 lines (398 loc) · 13.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
stages:
- build
- test
- regenerate
- review
- deploy
- service
.only-default: &only-default
rules:
- if: '$MIRROR_ONLY == "true"'
when: never
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
- if: '$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS'
when: never
- if: '$CI_COMMIT_BRANCH && $CI_PIPELINE_SOURCE != "schedule"'
variables:
TAG: ${CI_REGISTRY_IMAGE}/${CI_COMMIT_REF_SLUG}:${CI_COMMIT_SHA}-${CI_PIPELINE_ID}
STOREFRONT_TAG: ${CI_REGISTRY_IMAGE}/${CI_COMMIT_REF_SLUG}:${CI_COMMIT_SHA}-${CI_PIPELINE_ID}-storefront
HOST: ${CI_COMMIT_REF_SLUG}.${CI_PROJECT_NAME}.${REVIEW_URL}
HOSTS: ${HOST}, cs.${HOST}
COMPOSE_PROJECT_NAME: ${CI_PROJECT_NAME}__${CI_COMMIT_REF_SLUG}
before_script:
- echo ${CI_REGISTRY_PASSWORD} | docker login -u ${CI_REGISTRY_USER} ${CI_REGISTRY} --password-stdin
# Can be removed if mirroring is not needed
include: gitlab/mirror-repository/gitlab-stage.yml
build:
stage: build
<<: *only-default
tags:
- build
script:
- cp -R ./docker/nginx/ ./app/docker/nginx/
- cd ./app/
- docker build -f ./docker/php-fpm/Dockerfile --target production --compress -t ${TAG} .
- docker push ${TAG}
interruptible: true
build-storefront:
stage: build
<<: *only-default
tags:
- build
script:
- cp ./app/schema.graphql ./storefront/schema.graphql
- docker build -f ./storefront/docker/Dockerfile
--target production
--compress
--build-arg SENTRY_RELEASE=${CI_COMMIT_SHORT_SHA}
--build-arg SENTRY_URL=${SENTRY_URL}
--build-arg SENTRY_ORG=shopsys
--build-arg SENTRY_PROJECT=${SENTRY_PROJECT}
--build-arg SENTRY_AUTH_TOKEN=${SENTRY_AUTH_TOKEN}
-t ${STOREFRONT_TAG} ./storefront
- docker push ${STOREFRONT_TAG}
interruptible: true
test:standards-with-graphql-schema-check:
stage: test
<<: *only-default
tags:
- tests
needs:
- build
variables:
GIT_STRATEGY: none
script:
- docker run -i ${TAG} /bin/bash -c "mv PRODUCTION DEVELOPMENT; npm install format-graphql && ./check-schema.sh && php phing composer-dev standards"
interruptible: true
test:storefront-standards-with-codegen:
stage: test
<<: *only-default
image: node:20-alpine3.17
tags:
- tests
needs:
- build-storefront
before_script:
- corepack enable
- corepack prepare --activate [email protected]
- pnpm config set store-dir .pnpm-store
- apk add --no-cache grep
- cp ./app/schema.graphql ./storefront/schema.graphql
- cd ./storefront
script:
- pnpm install --frozen-lockfile
- ./check-next-public-variable.sh
- ./check-code-gen.sh
- pnpm run check
interruptible: true
tests:functional-and-acceptance:
image: tmaier/docker-compose:latest
stage: test
<<: *only-default
tags:
- tests
script:
- cp -f ./gitlab/docker-compose-ci.yml ./docker-compose.yml
- docker compose up -d
- docker compose exec -T php-fpm /bin/bash -c "mv PRODUCTION DEVELOPMENT; php phing composer-dev npm-install-dependencies test-db-create frontend-api-generate-new-keys tests tests-acceptance-build tests-acceptance"
after_script:
- mkdir -p codeception/
- docker cp shopsys-framework-php-fpm:/var/www/html/var/log/codeception/ ./
artifacts:
paths:
- codeception/
when: on_failure
expire_in: 1 day
interruptible: true
test:storefront-acceptance:
image: tmaier/docker-compose:latest
stage: test
<<: *only-default
tags:
- tests
# parallel:
# matrix:
# - GROUP: "authentication"
# - GROUP: "cart"
# - GROUP: "order"
# - GROUP: "transportAndPayment"
# - GROUP: "visits"
# - GROUP: "others"
artifacts:
paths:
- ./storefront/cypress/videos/
- ./storefront/cypress/screenshots/
- ./storefront/cypress/snapshotDiffs/
- php-fpm-log.txt
- webserver-log.txt
- storefront-log.txt
when: on_failure
expire_in: 1 day
script:
- cp -f ./gitlab/docker-compose-ci.yml ./docker-compose.yml
- docker compose up -d
- docker compose exec -T php-fpm php phing -D production.confirm.action=y composer-prod db-create frontend-api-generate-new-keys build-demo-dev-quick error-pages-generate
- cd storefront
- GROUP=$GROUP docker compose run cypress
after_script:
- docker compose logs php-fpm > php-fpm-log.txt
- docker compose logs webserver > webserver-log.txt
- docker compose logs storefront > storefront-log.txt
interruptible: true
regenerate-storefront-screenshots:
image: tmaier/docker-compose:latest
stage: regenerate
<<: *only-default
tags:
- tests
needs:
- build
- build-storefront
# parallel:
# matrix:
# - GROUP: "authentication"
# - GROUP: "cart"
# - GROUP: "order"
# - GROUP: "transportAndPayment"
# - GROUP: "visits"
# - GROUP: "others"
artifacts:
paths:
- ./storefront/cypress/snapshots/
- php-fpm-log.txt
- webserver-log.txt
- storefront-log.txt
when: on_failure
expire_in: 1 day
script:
- apk add --no-cache git
- git config --global user.name "Shopsys Bot"
- git config --global user.email "[email protected]"
- git clean -fdx
- git checkout "$CI_COMMIT_REF_NAME"
- cp -f ./gitlab/docker-compose-ci.yml ./docker-compose.yml
- docker compose up -d
- docker compose exec -T php-fpm php phing -D production.confirm.action=y composer-prod db-create frontend-api-generate-new-keys build-demo-dev-quick error-pages-generate
- GROUP=$GROUP docker compose run cypress-regenerate-screenshots
- git add ./storefront/cypress/snapshots/e2e
- git status
- |
if ! git diff --staged --quiet; then
if [ -z "$GROUP" ]; then
git commit -m "Regenerated Cypress screenshots"
else
git commit -m "Regenerated Cypress screenshots for ${GROUP} group"
fi
git fetch origin "$CI_COMMIT_REF_NAME"
git pull --rebase origin "$CI_COMMIT_REF_NAME"
git push https://shopsys_bot:[email protected]/ss6-projects/${CI_PROJECT_NAME}.git "$CI_COMMIT_REF_NAME" --force -v || (echo "Failed to push changes" && git log -n 5 && exit 1)
else
echo "No changes in snapshots, skipping commit."
fi
after_script:
- docker compose logs php-fpm > php-fpm-log.txt
- docker compose logs webserver > webserver-log.txt
- docker compose logs storefront > storefront-log.txt
interruptible: true
when: manual
review:
stage: review
environment:
name: "review/${CI_COMMIT_REF_SLUG}"
url: https://${CI_COMMIT_REF_SLUG}.${CI_PROJECT_NAME}.${REVIEW_URL}
on_stop: review:stop
auto_stop_in: 1 week
needs:
- build
- build-storefront
<<: *only-default
artifacts:
paths:
- schema.graphql
script:
- cp -f ./gitlab/docker-compose-ci-review.yml ./docker-compose.yml
- chmod +x ./gitlab/scripts/set-urls-for-review.sh && source ./gitlab/scripts/set-urls-for-review.sh
- convertToTraefikHosts "$HOSTS"
- setDomainsToDockerCompose
- docker compose down --rmi all -v --remove-orphans
- chmod +x ./gitlab/scripts/rabbitmq-vhost.sh && ./gitlab/scripts/rabbitmq-vhost.sh create ${COMPOSE_PROJECT_NAME}
- docker compose up -d
- setUrlsToDomainsUrls
- docker compose exec -T php-fpm php phing -D production.confirm.action=y clean db-create build-review-ci
- docker compose exec -T php-consumer php phing -D production.confirm.action=y frontend-api-generate-new-keys
- printDomains
tags:
- review
interruptible: true
review:stop:
stage: review
variables:
GIT_STRATEGY: none
needs:
- build
<<: *only-default
tags:
- review
script:
- cp -f ./gitlab/docker-compose-ci-review.yml ./docker-compose.yml
- docker compose exec -T php-fpm php phing -D production.confirm.action=y elasticsearch-index-delete
- docker compose down --rmi all -v --remove-orphans
- chmod +x ./gitlab/scripts/rabbitmq-vhost.sh && ./gitlab/scripts/rabbitmq-vhost.sh remove ${COMPOSE_PROJECT_NAME}
- /home/ci/clean.sh ${COMPOSE_PROJECT_NAME}
rules:
- if: '$MIRROR_ONLY == "true"'
when: never
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
when: manual
allow_failure: true
- if: '$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS'
when: never
- if: '$CI_COMMIT_BRANCH && $CI_PIPELINE_SOURCE != "schedule"'
when: manual
allow_failure: true
environment:
name: review/${CI_COMMIT_REF_SLUG}
action: stop
repository:clean:
stage: service
image: dwdraju/alpine-curl-jq
tags:
- service
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
before_script:
- chmod +x ./gitlab/scripts/repository-clean.sh
script:
- ./gitlab/scripts/repository-clean.sh
security:check:
stage: service
tags:
- service
needs:
- build
rules:
- if: '$CI_COMMIT_BRANCH == "master" && $CI_PIPELINE_SOURCE != "schedule"'
script:
- docker run -i ${TAG} composer security-check
- docker run -i ${STOREFRONT_TAG} pnpm audit --audit-level=high --ignore-registry-errors
service:merge_request:
stage: service
image: dwdraju/alpine-curl-jq
tags:
- service
needs: []
rules:
- if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
before_script:
- chmod +x ./gitlab/scripts/cancel-previous-pipelines.sh
- chmod +x ./gitlab/scripts/set-review-url-to-jira.sh
script:
- ./gitlab/scripts/cancel-previous-pipelines.sh
- ./gitlab/scripts/set-review-url-to-jira.sh
.deploy: &deploy
image:
name: shopsys/kubernetes-buildpack:1.2
stage: deploy
needs:
- build
- build-storefront
tags:
- deploy
rules:
- if: '$MIRROR_ONLY == "true"'
when: never
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
script:
- cd ./app/
- docker create -ti --name image ${TAG} bash
- docker cp image:/var/www/html/var/ ./
- echo "${KUBE_CONFIG}" > /root/.kube/config
- chmod +x ./deploy/deploy-project.sh && ./deploy/deploy-project.sh deploy
deploy:production:
<<: *deploy
resource_group: deploy_production
variables:
KUBE_CONFIG: ${KUBE_CONFIG_PROD}
rules:
- if: '$MIRROR_ONLY == "true"'
when: never
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- if: '$CI_COMMIT_BRANCH == "master"'
allow_failure: false
- if: '$CI_COMMIT_BRANCH =~ /^master-.*$/'
when: manual
allow_failure: false
environment:
name: production
url: https://${DOMAIN_HOSTNAME_1}
kubernetes:
namespace: ${PROJECT_NAME}
deploy:devel:
<<: *deploy
resource_group: deploy_devel
variables:
KUBE_CONFIG: ${KUBE_CONFIG_DEVEL}
rules:
- if: '$MIRROR_ONLY == "true"'
when: never
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- if: '$CI_COMMIT_BRANCH == "devel" || $CI_COMMIT_BRANCH =~ /^devel-.*$/'
environment:
name: devel
url: https://${DOMAIN_HOSTNAME_1}
kubernetes:
namespace: ${PROJECT_NAME}
deploy:alpha:
<<: *deploy
resource_group: deploy_alpha
variables:
KUBE_CONFIG: ${KUBE_CONFIG_DEVEL}
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- if: '$CI_COMMIT_BRANCH == "alpha" || $CI_COMMIT_BRANCH =~ /^alpha-.*$/'
environment:
name: devel-alpha
url: https://${DOMAIN_HOSTNAME_1}
kubernetes:
namespace: ${PROJECT_NAME}
after_script:
- sleep 20
- RUNNING_WEBSERVER_PHP_FPM_POD=$(kubectl get pods --namespace=${PROJECT_NAME} --field-selector=status.phase=Running -l app=webserver-php-fpm -o=jsonpath='{.items[0].metadata.name}')
- kubectl exec ${RUNNING_WEBSERVER_PHP_FPM_POD} --namespace=${PROJECT_NAME} -- php ./bin/console doctrine:query:sql "UPDATE setting_values SET value='Db4tLxuck2' WHERE name='feedHash'"
test:gatling:
stage: test
image:
name: shopsys/kubernetes-buildpack:1.2
tags:
- tests
variables:
GATLING_BASE_URL: ${GATLING_BASE_URL}
GATLING_PAGE_TEST_DURATION: '10'
GATLING_API_TEST_DURATION: '10'
GATLING_PAGE_USERS_COUNTS_LVL1: '2'
GATLING_PAGE_USERS_COUNTS_LVL2: '10'
GATLING_PAGE_USERS_COUNTS_LVL3: '15'
GATLING_RESULTS: ''
GATLING_STRESS_TEST_DURATION: '60'
GATLING_STRESS_TEST_USERS_COUNTS: '100'
needs: []
rules:
- if: '$CI_PIPELINE_SOURCE == "schedule"'
when: never
- if: '$CI_COMMIT_BRANCH == "master" || $CI_COMMIT_BRANCH == "devel"'
when: manual
allow_failure: true
before_script:
- chmod +x ./gatling/run.sh
script:
- cd ./gatling
- ./run.sh
artifacts:
paths:
- gatling/results
when: always
expire_in: 1 day