/
.gitlab-ci.yml
318 lines (299 loc) · 9.73 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
stages:
- build
- test
- 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}
STOREFRONT_TAG: ${CI_REGISTRY_IMAGE}/${CI_COMMIT_REF_SLUG}:${CI_COMMIT_SHA}-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-project --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} -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; ./check-schema.sh && php phing composer-dev standards"
interruptible: true
test:storefront-standards-with-codegen:
stage: test
<<: *only-default
image: node:18.15.0-alpine
tags:
- tests
needs:
- build-storefront
before_script:
- corepack enable
- corepack prepare --activate pnpm@8.6.0
- pnpm config set store-dir .pnpm-store
- 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 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
artifacts:
paths:
- storefront/cypress/videos/
- storefront/cypress/screenshots/
- php-fpm-log.txt
- webserver-log.txt
- storefront-log.txt
when: on_failure
expire_in: 1 day
script:
- cp -f ./gitlab/docker-compose-ci-storefront-acceptance.yml ./docker-compose.yml
- docker-compose up -d
- docker-compose exec -T php-fpm sed -i "s/http:\/\/127.0.0.1:8000/http:\/\/webserver:8080/g" config/domains_urls.yaml
- 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
- 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
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 && ./gitlab/scripts/set-urls-for-review.sh setDomainsToDockerCompose
- docker-compose down --rmi all -v --remove-orphans
- docker-compose up -d
- ./gitlab/scripts/set-urls-for-review.sh setUrlsToDomainsUrls
- docker-compose exec -T php-fpm php phing -D production.confirm.action=y clean db-create build-review-ci
- ./gitlab/scripts/set-urls-for-review.sh 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
- /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
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:0.9
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}
test:gatling:
stage: test
image:
name: shopsys/kubernetes-buildpack:0.9
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