forked from drupal-composer/drupal-project
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path.gitlab-ci.yml
More file actions
346 lines (323 loc) · 9.01 KB
/
.gitlab-ci.yml
File metadata and controls
346 lines (323 loc) · 9.01 KB
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
include:
- template: Auto-DevOps.gitlab-ci.yml
###################################
## Global Workflow Variables ##
###################################
variables:
IMAGE_TAG_RELEASE: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_VERIFY: 1
DOCKER_CERT_PATH: "/certs/client"
GIT_DEPTH: "5"
THEME_DIRECTORY: "docroot/themes/custom/NAMEOFTHEME"
TEST_DISABLED: "true"
CODE_QUALITY_DISABLED: "true"
LICENSE_MANAGEMENT_DISABLED: "true"
BROWSER_PERFORMANCE_DISABLED: "true"
LOAD_PERFORMANCE_DISABLED: "true"
SAST_DISABLED: "true"
SECRET_DETECTION_DISABLED: "true"
DEPENDENCY_SCANNING_DISABLED: "true"
CONTAINER_SCANNING_DISABLED: "true"
DAST_DISABLED: "true"
CODE_INTELLIGENCE_DISABLED: "true"
POSTGRES_ENABLED: "false"
.base:
# See https://gitlab.com/gitlab-org/cluster-integration/cluster-applications/
image: "registry.gitlab.com/gitlab-org/cluster-integration/cluster-applications:v2.0.0"
before_script:
- chmod 400 "$KUBECONFIG" # Workaround for https://gitlab.com/gitlab-org/gitlab/-/issues/327912
- gl-use-kube-context
#########################
## Workflow Stages ##
#########################
stages:
- prepare
- lint
- build
- test
- deploy # dummy stage to follow the template guidelines
- review
- dast
- staging
- canary
- production
- incremental rollout 10%
- incremental rollout 25%
- incremental rollout 50%
- incremental rollout 100%
- performance
- cleanup
#################
## Anchors ##
#################
.before_script:
before_script: &before_script
- until docker info; do sleep 1; done
- echo "$DOCKER_REGISTRY_PASSWORD" | docker login -u "$DOCKER_REGISTRY_USER" --password-stdin
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
.composer-cache:
cache: &composer_cache
key: $CI_COMMIT_REF_SLUG
paths:
- vendor/
policy: pull-push
.node-cache:
cache: &node_cache
key: $CI_COMMIT_REF_SLUG
paths:
- $THEME_DIRECTORY/node_modules/
policy: pull-push
#####################
## Preparation ##
#####################
php-prepare:
image: fabean/pipeline-server:php8.2-node18
stage: prepare
tags:
- kubernetes
- cluster
script:
- composer install
cache:
- <<: *composer_cache
policy: pull-push
rules:
- if: '$BUILD_DISABLED'
when: never
- if: '$AUTO_DEVOPS_PLATFORM_TARGET == "EC2"'
when: never
- if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
node-prepare:
image: node:18-alpine
stage: prepare
tags:
- kubernetes
- cluster
script:
- cd $THEME_DIRECTORY
- yarn install
cache:
- <<: *node_cache
policy: pull-push
rules:
- if: '$BUILD_DISABLED'
when: never
- if: '$AUTO_DEVOPS_PLATFORM_TARGET == "EC2"'
when: never
- if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
##############################
## Drupal Rector Checks ##
##############################
drupal-rector-theme:
image: fabean/pipeline-server:php8.2-node18
services:
- docker:dind
stage: lint
tags:
- kubernetes
- cluster
script:
- composer install
- vendor/bin/rector process ./docroot/themes/custom/ --dry-run
cache:
- <<: *composer_cache
rules:
- if: '$BUILD_DISABLED'
when: never
- if: '$AUTO_DEVOPS_PLATFORM_TARGET == "EC2"'
when: never
- if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
needs: ["php-prepare"]
drupal-rector-modules:
image: fabean/pipeline-server:php8.2-node18
stage: lint
tags:
- kubernetes
- cluster
script:
- composer install
- vendor/bin/rector process ./docroot/modules/custom/ --dry-run
cache:
- <<: *composer_cache
rules:
- if: '$BUILD_DISABLED'
when: never
- if: '$AUTO_DEVOPS_PLATFORM_TARGET == "EC2"'
when: never
- if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
needs: ["php-prepare"]
######################
## Code Linting ##
######################
php-lint:
image: fabean/pipeline-server:php8.2-node18
stage: lint
tags:
- kubernetes
- cluster
script:
- composer install
- vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,md,yml --ignore=node_modules,bower_components,vendor,dist ./docroot/modules/custom/
cache:
- <<: *composer_cache
rules:
- if: '$BUILD_DISABLED'
when: never
- if: '$AUTO_DEVOPS_PLATFORM_TARGET == "EC2"'
when: never
- if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
needs: ["php-prepare"]
php-lint-theme:
image: fabean/pipeline-server:php8.2-node18
stage: lint
tags:
- kubernetes
- cluster
script:
- composer install
- vendor/bin/phpcs --standard=Drupal --extensions=php,module,inc,install,test,profile,theme,md,yml --ignore=node_modules,bower_components,vendor,dist ./docroot/themes/custom/
cache:
- <<: *composer_cache
rules:
- if: '$BUILD_DISABLED'
when: never
- if: '$AUTO_DEVOPS_PLATFORM_TARGET == "EC2"'
when: never
- if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
needs: ["php-prepare"]
theme-lint-frontend:
image: fabean/pipeline-server:php8.2-node18
stage: lint
tags:
- kubernetes
- cluster
script:
- cd $THEME_DIRECTORY
- npm install -g yarn
- yarn install
- yarn lint
cache:
- <<: *node_cache
rules:
- if: '$BUILD_DISABLED'
when: never
- if: '$AUTO_DEVOPS_PLATFORM_TARGET == "EC2"'
when: never
- if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
needs: ["node-prepare"]
##############################
## Auto DevOps Pipeline ##
##############################
.auto-deploy:
image: "registry.gitlab.com/gitlab-org/cluster-integration/auto-deploy-image:latest"
tags:
- kubernetes
- cluster
before_script:
- helm repo add --username gitlab-ci-token --password $CI_JOB_TOKEN koality-charts $CI_API_V4_URL/projects/632/packages/helm/stable
build:
variables:
DOCKER_TLS_CERTDIR: "/certs"
tags:
- kubernetes
- cluster
before_script: *before_script
cache:
- <<: *node_cache
- <<: *composer_cache
rules:
- if: '$BUILD_DISABLED'
when: never
- if: '$AUTO_DEVOPS_PLATFORM_TARGET == "EC2"'
when: never
- if: '$CI_COMMIT_BRANCH || $CI_COMMIT_TAG'
needs: ["php-lint", "php-lint-theme", drupal-rector-theme, "drupal-rector-modules", "theme-lint-frontend"]
build-cron:
extends: build
script:
- |
if [[ -z "$CI_COMMIT_TAG" ]]; then
export CI_APPLICATION_REPOSITORY=${CI_APPLICATION_REPOSITORY:-$CI_REGISTRY_IMAGE/$CI_COMMIT_REF_SLUG}/cron
export CI_APPLICATION_TAG=${CI_APPLICATION_TAG:-$CI_COMMIT_SHA}
else
export CI_APPLICATION_REPOSITORY=${CI_APPLICATION_REPOSITORY:-$CI_REGISTRY_IMAGE}/cron
export CI_APPLICATION_TAG=${CI_APPLICATION_TAG:-$CI_COMMIT_TAG}
fi
- /build/build.sh
rules:
- if: '$BUILD_DISABLED'
when: never
- if: '$AUTO_DEVOPS_PLATFORM_TARGET == "EC2"'
when: never
- if: '$CI_COMMIT_BRANCH || $CI_COMMIT_TAG'
needs: ["php-lint", "php-lint-theme", drupal-rector-theme, "drupal-rector-modules", "theme-lint-frontend"]
review:
extends: .auto-deploy
stage: review
tags:
- kubernetes
- cluster
script:
- auto-deploy check_kube_domain
- auto-deploy download_chart
- auto-deploy use_kube_context
- auto-deploy ensure_namespace
- auto-deploy initialize_tiller
- auto-deploy create_secret
- auto-deploy deploy
- auto-deploy persist_environment_url
environment:
name: review/$CI_COMMIT_REF_NAME
url: http://$CI_PROJECT_ID-$CI_ENVIRONMENT_SLUG.$KUBE_INGRESS_BASE_DOMAIN
on_stop: stop_review
auto_stop_in: '1 week'
artifacts:
paths: [environment_url.txt, tiller.log]
when: always
rules:
- if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
when: never
- if: '$REVIEW_DISABLED'
when: never
- if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
when: manual
needs: ["build", "build-cron"]
stop review:
extends: .auto-deploy
stage: cleanup
tags:
- kubernetes
- cluster
variables:
GIT_STRATEGY: none
script:
- auto-deploy use_kube_context
- auto-deploy initialize_tiller
- auto-deploy delete
environment:
name: review/$CI_COMMIT_REF_NAME
action: stop
allow_failure: true
rules:
- if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never
- if: '$CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH'
when: never
- if: '$REVIEW_DISABLED'
when: never
- if: '$CI_COMMIT_TAG || $CI_COMMIT_BRANCH'
when: manual
needs: ["review"]
staging:
rules:
- if: '($CI_KUBERNETES_ACTIVE == null || $CI_KUBERNETES_ACTIVE == "") && ($KUBECONFIG == null || $KUBECONFIG == "")'
when: never
- if: '$CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH'
when: never
- if: '$STAGING_ENABLED'
needs: ["build", "build-cron"]