-
Notifications
You must be signed in to change notification settings - Fork 38
/
base_autodevops.yml
422 lines (371 loc) · 8.5 KB
/
base_autodevops.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
421
422
#
include:
- /base_azure_db_stage.yml
- /base_create_namespace_stage.yml
- /base_delete_useless_k8s_ns_stage.yml
- /base_deploy_app_chart_stage.yml
- /base_deploy_kosko_stage.yml
- /base_docker_helm_image_stage.yml
- /base_docker_kubectl_image_stage.yml
- /base_notify_github_stage.yml
- /base_register_docker_stage.yml
- /base_register_kaniko_stage.yml
- /base_semantic_release_stage.yml
- /base_trigger_stage.yml
- /base_yarn_stage.yml
#
workflow:
rules:
# Skip GitHub pull requests pipelines
- if: $CI_PIPELINE_SOURCE == 'external_pull_request_event'
when: never
# Otherwise include the job and set to run normally
- when: always
#
stages:
- Install
- Code Quality
- Registration
- Release
- Deploy
#
variables:
GIT_STRATEGY: fetch
GIT_DEPTH: 5
#
AUTO_DEVOPS_DEV_ENVIRONMENT_NAME: "-dev"
AUTO_DEVOPS_PREPROD_ENVIRONMENT_NAME: "-dev"
AUTO_DEVOPS_PROD_ENVIRONMENT_NAME: "prod"
# To activate the auto release
# AUTO_DEVOPS_RELEASE_AUTO: "🔖"
# AUTO_DEVOPS_PRODUCTION_AUTO: "🚀"
# To disable some quality check
# AUTO_DEVOPS_QUALITY_DISABLED: "🛑"
# AUTO_DEVOPS_TEST_DISABLED: "🛑"
# AUTO_DEVOPS_KANIKO: "Oh yeah!"
#
#
#
.production_rule: &autodevops_production_rule
if: "$PRODUCTION && $CI_COMMIT_TAG"
.trigger_rule: &autodevops_trigger_rule
if: "$PRODUCTION || $TRIGGER"
.autodevops_base_rules:
rules:
- &autodevops_global_skip_case
<<: *autodevops_trigger_rule
when: never
- when: on_success
#
#
#
.autodevops_trigger_release:
extends:
- .base_trigger_release_stage
- .autodevops_base_rules
stage: .post
rules:
- <<: *autodevops_global_skip_case
- if: "$CI_COMMIT_TAG"
when: never
- if: "$AUTO_DEVOPS_RELEASE_AUTO && $CI_COMMIT_MESSAGE =~ /^chore(release): version/"
when: never
- if: "$AUTO_DEVOPS_RELEASE_AUTO && ($CI_COMMIT_REF_NAME == 'master' || $CI_COMMIT_REF_NAME == 'beta' || $CI_COMMIT_REF_NAME == 'alpha') && $CI_COMMIT_MESSAGE !~ /^chore(release): version/"
when: on_success
- when: manual
Trigger Release:
extends: .autodevops_trigger_release
.autodevops_release:
extends:
- .base_semantic_release_stage
rules:
- if: $TRIGGER == "RELEASE"
variables:
GIT_DEPTH: 4242
SEMANTIC_RELEASE_ARGS: ""
stage: Release
Release:
extends: .autodevops_release
#
.autodevops_trigger_production:
stage: .post
rules:
- if: $PRODUCTION || $TRIGGER
when: never
- if: $CI_COMMIT_TAG && $AUTO_DEVOPS_PRODUCTION_AUTO && $CI_COMMIT_TAG =~ /^v\d+\.\d+\.\d+$/
when: on_success
- if: "$CI_COMMIT_TAG"
when: manual
extends: .base_trigger_production_stage
Trigger Production:
extends: .autodevops_trigger_production
#
.autodevops_install:
extends:
- .base_yarn
- .autodevops_base_rules
interruptible: true
#
#
#
#
#
#
.autodevops_lint:
rules:
- <<: *autodevops_trigger_rule
when: never
- if: "$AUTO_DEVOPS_QUALITY_DISABLED"
when: never
- if: "$CI_COMMIT_TAG"
when: never
- when: always
extends:
- .base_yarn_script
- .autodevops_base_rules
needs:
- job: Install
artifacts: true
script:
- yarn lint
#
.autodevops_test:
rules:
- <<: *autodevops_trigger_rule
when: never
- if: "$AUTO_DEVOPS_TEST_DISABLED"
when: never
- if: "$CI_COMMIT_TAG"
when: never
- when: always
extends:
- .base_yarn_script
- .autodevops_base_rules
needs:
- job: Install
artifacts: true
script:
- yarn test
.autodevops_k8s_test:
needs: []
rules:
- <<: *autodevops_trigger_rule
when: never
- if: "$AUTO_DEVOPS_TEST_DISABLED"
when: never
- exists:
- .k8s/package.json
extends:
- .base_kosko_k8s_test
- .autodevops_base_rules
#
.autodevops_build:
extends:
- .base_yarn_build_next
- .autodevops_base_rules
needs:
- job: Install
artifacts: true
#
#
#
#
#
#
.autodevops_register_docker_image:
extends:
- .base_register_docker_stage
stage: Registration
needs:
- job: Build
artifacts: true
variables:
CONTEXT: .
IMAGE_NAME: $CI_REGISTRY_IMAGE
rules:
- <<: *autodevops_trigger_rule
when: never
- if: "$AUTO_DEVOPS_KANIKO"
when: never
- when: on_success
.autodevops_register_image:
extends:
- .autodevops_register_docker_image
.autodevops_register_kaniko_image:
extends:
- .base_register_kaniko_stage
stage: Registration
needs:
- job: Build
artifacts: true
variables:
CONTEXT: .
IMAGE_NAME: $CI_PROJECT_NAME
rules:
- <<: *autodevops_trigger_rule
when: never
- if: "$AUTO_DEVOPS_KANIKO"
when: on_success
- when: never
#
#
#
#
#
#
.deploy_stage:
stage: Deploy
extends:
- .base_deploy_kosko_stage
cache:
key: deploy-${CI_COMMIT_REF_SLUG}
paths:
- ${CI_PROJECT_DIR}/dotenv.env
- ${CI_PROJECT_DIR}/.cache
- ${K8S_FOLDER}/node_modules
after_script:
- echo "CI_ENVIRONMENT_URL=${CI_ENVIRONMENT_URL}" >> dotenv.env
#
.autodevops_review:
extends:
- .deploy_stage
rules:
- if: "$PRODUCTION || $TRIGGER || $CI_COMMIT_TAG"
when: never
- when: on_success
variables:
KOSKO_APPEND_YAML_FROM: .k8s/environments/dev/manifests
KOSKO_GENERATE_ARGS: >-
--env dev
environment:
auto_stop_in: 3 day
name: ${CI_COMMIT_REF_NAME}${AUTO_DEVOPS_DEV_ENVIRONMENT_NAME}
on_stop: Stop review
url: https://${CI_ENVIRONMENT_SLUG}-${CI_PROJECT_NAME}.${KUBE_INGRESS_BASE_DOMAIN}
Review:
extends: .autodevops_review
.autodevops_preprod:
extends:
- .deploy_stage
- .autodevops_review
rules:
- if: "$PRODUCTION || $TRIGGER"
when: never
- if: "$CI_COMMIT_TAG"
variables:
KOSKO_APPEND_YAML_FROM: .k8s/environments/preprod/manifests
KOSKO_GENERATE_ARGS: >-
--env preprod
environment:
auto_stop_in: 1 month
name: preprod${AUTO_DEVOPS_PREPROD_ENVIRONMENT_NAME}
on_stop: Stop preprod
url: https://preprod-${CI_PROJECT_NAME}.${KUBE_INGRESS_BASE_DOMAIN}
Preprod:
extends: .autodevops_preprod
.autodevops_production:
extends:
- .deploy_stage
rules:
- <<: *autodevops_production_rule
variables:
KOSKO_APPEND_YAML_FROM: .k8s/environments/prod/manifests
KUBE_NAMESPACE: ${CI_PROJECT_NAME}
KOSKO_GENERATE_ARGS: >-
--env prod "!(_*)"
environment:
name: ${AUTO_DEVOPS_PROD_ENVIRONMENT_NAME}
url: https://${CI_PROJECT_NAME}.${KUBE_INGRESS_BASE_DOMAIN}
Production:
extends: .autodevops_production
#
#
#
.autodevops_stop_review:
image: ghcr.io/socialgouv/docker/no-k8s:6.65.0
stage: .post
rules:
- if: "$PRODUCTION || $TRIGGER || $CI_COMMIT_TAG"
when: never
- when: manual
environment:
name: ${CI_COMMIT_REF_NAME}${AUTO_DEVOPS_DEV_ENVIRONMENT_NAME}
action: stop
allow_failure: true
dependencies: []
variables:
GIT_STRATEGY: none
script:
- echo "kubectl delete namespace ${KUBE_NAMESPACE}"
- |
[[ -n $AUTO_DEVOPS_ENABLE_KAPP ]] && kapp -y delete -a ${CI_PROJECT_NAME} --namespace ${KUBE_NAMESPACE}
- kubectl delete namespace "${KUBE_NAMESPACE}"
Stop review:
extends: .autodevops_stop_review
.autodevops_stop_preprod:
extends:
- .autodevops_stop_review
environment:
name: preprod${AUTO_DEVOPS_PREPROD_ENVIRONMENT_NAME}
action: stop
rules:
- if: "$PRODUCTION || $TRIGGER"
when: never
- if: "$CI_COMMIT_TAG"
when: manual
Stop preprod:
extends: .autodevops_stop_preprod
#
#
#
.autodevops_notify_starting_deployment:
extends:
- .base_notify_pending_stage
stage: Deploy
rules:
- if: "$TRIGGER"
when: never
- if: "$AUTO_DEVOPS_NOTIFY_DISABLED"
when: never
- when: on_success
Notify Starting Deployment:
extends: .autodevops_notify_starting_deployment
#
.notify:
stage: .post
dependencies:
- Notify Starting Deployment
cache:
key: deploy-${CI_COMMIT_REF_SLUG}
paths:
- ${CI_PROJECT_DIR}/dotenv.env
policy: pull
before_script:
- |
set -x
. dotenv.env
export HOST=$CI_ENVIRONMENT_URL
.autodevops_notify_fail:
extends:
- .base_notify_fail_stage
- .notify
rules:
- if: "$TRIGGER"
when: never
- if: "$AUTO_DEVOPS_NOTIFY_DISABLED"
when: never
- when: on_failure
Notify Fail:
extends: .autodevops_notify_fail
.autodevops_notify_success:
extends:
- .base_notify_success_stage
- .notify
rules:
- if: "$TRIGGER"
when: never
- if: "$AUTO_DEVOPS_NOTIFY_DISABLED"
when: never
- when: on_success
Notify Success:
extends: .autodevops_notify_success