forked from DataDog/documentation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
472 lines (445 loc) · 15.1 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
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
stages:
- bootstrap
- build
- post-deploy
- cleanup
variables:
PREVIEW_CONFIG: "config/preview.yaml"
LIVE_CONFIG: "config/live.yaml"
ARTIFACT_RESOURCE: "public"
LIVE_DOMAIN: "https://docs.datadoghq.com/"
PREVIEW_DOMAIN: "https://docs-staging.datadoghq.com/"
# datadog-ci
DATADOG_SITE: 'datadoghq.com'
DATADOG_SUBDOMAIN: 'dd-corpsite'
FORCE_COLOR: '1'
GIT_DEPTH: 50
# gitlab checkout
DOCS_REPO_NAME: documentation
REPO_URL: "https://gitlab-ci-token:${CI_JOB_TOKEN}@gitlab.ddbuild.io/DataDog/${DOCS_REPO_NAME}.git"
# ================== copy scripts =============== #
before_script:
- "[ -d local/bin ] && find local/bin/ -type f -exec cp {} /usr/local/bin \\;" # load scripts
- "[ -d local/etc ] && find local/etc/ -type f -exec cp {} /etc \\;" # load configs
- "[ -f /usr/local/bin/helpers.sh ] && source /usr/local/bin/helpers.sh" # source helpers so they are available in the container
- "[ -f /etc/profile ] && source /etc/profile" # for golang on path
- mkdir -p logs
cache: &cache
key: $CI_COMMIT_REF_SLUG-$CI_PROJECT_DIR
paths:
- node_modules/
- tmp/.htmltest/
# ================== templates ================== #
.base_template: &base_template
image: 486234852809.dkr.ecr.us-east-1.amazonaws.com/ci/corp-ci:master
tags:
- "runner:main"
except:
- tags
only:
- branches
# ================== Install Node Dependencies ================== #
install_dependencies:
<<: *base_template
stage: bootstrap
cache:
<<: *cache
variables:
GIT_STRATEGY: none
script:
- git version
- git clone --branch $CI_COMMIT_REF_NAME --depth 1 --filter=blob:none --no-checkout $REPO_URL sparse-docs
- cd sparse-docs && git sparse-checkout init --cone && git sparse-checkout set local && git checkout $CI_COMMIT_REF_NAME && cd ..
- mkdir -p ./local/bin/sh && cp --remove-destination ./sparse-docs/local/bin/sh/preinstall.sh ./local/bin/sh/preinstall.sh
- cp --remove-destination ./sparse-docs/package.json ./package.json
- cp --remove-destination ./sparse-docs/yarn.lock ./yarn.lock
- yarn install --link-duplicates --frozen-lockfile --cache-folder .yarn
- rm -rf ./sparse-docs # cleanup runner
only:
changes:
- yarn.lock
# ================== preview ================== #
# If the branch has a name of <slack-user>/<feature-name> then ci builds a preview site
build_preview:
<<: *base_template
stage: build
cache:
<<: *cache
policy: pull
environment: "preview"
variables:
URL: ${PREVIEW_DOMAIN}
CONFIG: ${PREVIEW_CONFIG}
MESSAGE: ":gift_heart: Your preview site is available!\nNow running tests..."
CONFIGURATION_FILE: "./local/bin/py/build/configurations/pull_config_preview.yaml"
LOCAL: "False"
script:
- post_dd_event "documentation deploy ${CI_COMMIT_REF_NAME} started" "${CI_PROJECT_URL}/pipelines/${CI_PIPELINE_ID}" "info"
- touch Makefile.config
- make BRANCH=${CI_COMMIT_REF_NAME} examples
- sync_integration_descriptions
- ./local/bin/py/build/pull_rbac.py $(get_secret 'dd-api-key') $(get_secret 'dd-app-key')
#- sync_integration_descriptions_cached
- placehold_translations
- update_preview_baseurl
- yarn run prebuild
- yarn run build:preview
# remove service_checks json as we don't need to s3 push that..
- rm -rf data/service_checks
- in-isolation deploy_preview > logs/deploy.txt
# remove static images so we can skip from artifact passed in gitlab
- remove_static_from_repo
- notify_slack "<https://github.com/DataDog/documentation/commit/${CI_COMMIT_SHA}|${CI_COMMIT_REF_NAME}> is ready for preview. <${CI_PROJECT_URL}/pipelines/${CI_PIPELINE_ID}| checks running>." "#31b834"
artifacts:
paths:
- ${ARTIFACT_RESOURCE}
- ./integrations_data
- .github/
- .vale.ini
- .htmltest.yml
- ./logs
only:
- /.+?\/[a-zA-Z0-9_-]+/
interruptible: true
link_checks_preview:
<<: *base_template
stage: post-deploy
cache: {}
environment: "preview"
variables:
URL: ${PREVIEW_DOMAIN}
GIT_STRATEGY: none
script:
- post_dd_event "documentation htmltest ${CI_COMMIT_REF_NAME} started" "${CI_PROJECT_URL}/pipelines/${CI_PIPELINE_ID}" "info"
- find ./public -name "*.html" -exec sed -i -e "s#https://docs-staging.datadoghq.com/$CI_COMMIT_REF_NAME/#/#g" {} +
- find ./public -name "*.html" -exec sed -i -e "s#/api/v1/#/api/latest/#g" {} +
- find ./public -name "*.html" -exec sed -i -e "s#/api/v2/#/api/latest/#g" {} +
- htmltest
after_script:
- "[ -f /usr/local/bin/helpers.sh ] && source /usr/local/bin/helpers.sh" # source helpers
- RESULT="⛈ htmltest result; the following issues were found:\n$(tail -n +2 ./tmp/.htmltest/htmltest.log)\n--------------------" # output all but first line
- if grep -q "not exist" tmp/.htmltest/htmltest.log; then notify_slack "${RESULT}" "#31b834"; fi
only:
- /.+?\/[a-zA-Z0-9_-]+/
artifacts:
paths:
- ./tmp/.htmltest
interruptible: true
missing_tms_preview:
<<: *base_template
stage: post-deploy
environment: "preview"
allow_failure: true
cache: {}
variables:
GIT_STRATEGY: none
dependencies:
- build_preview
script:
- check_missing_tms
only:
- /.+?\/[a-zA-Z0-9_-]+/
interruptible: true
index_algolia_preview:
image:
name: 486234852809.dkr.ecr.us-east-1.amazonaws.com/docsearch-scraper:v2978988-4692ed5-0.8
entrypoint: [""] # force an empty entrypoint (see https://gitlab.com/gitlab-org/gitlab-runner/issues/2692)
tags: ["runner:main"]
stage: post-deploy
cache:
<<: *cache
policy: pull
environment: "preview"
timeout: 1h 30m
script:
- |-
echo APPLICATION_ID=$(get_secret 'ci.documentation.algolia_preview_application_id') > .env
echo API_KEY=$(get_secret 'ci.documentation.algolia_preview_api_key') >> .env
export DISPLAY=:99
Xvfb :99 -ac &
echo "n" | docsearch run ./local/etc/algolia/docs_datadoghq_preview.json
dependencies:
- build_preview
when: manual
only:
- /.+?\/[a-zA-Z0-9_-]+/
interruptible: true
replica_algolia_preview:
<<: *base_template
stage: post-deploy
cache:
<<: *cache
policy: pull
environment: "preview"
script:
- ALGOLIA_APP_ID=$(get_secret 'algolia_preview_application_id') ALGOLIA_ADMIN_KEY=$(get_secret 'algolia_preview_api_key') yarn run algolia:config
dependencies:
- build_preview
when: manual
only:
- /.+?\/[a-zA-Z0-9_-]+/
interruptible: true
sourcemaps_preview:
<<: *base_template
stage: post-deploy
cache:
<<: *cache
policy: pull
environment: "preview"
script:
# Rename any js.map files to include SHA if correlating JS file is fingerprinted. Hugo's asset build system seems to lose the fingerprint value when generating source maps.
- find ./public -type f -name "*.*.js" -exec bash -c 'x={}; hash=$(basename $x | cut -d '.' -f 2); map=${x/$hash./}.map; mv $map ${map/.js/.$hash.js}' \;
- DATADOG_API_KEY="$(get_secret 'dd-api-key')" ./node_modules/.bin/datadog-ci sourcemaps upload ./public/static --service docs --minified-path-prefix "https://docs-staging.datadoghq.com/${CI_COMMIT_REF_NAME}/static/" --release-version "${CI_COMMIT_SHORT_SHA}"
dependencies:
- build_preview
allow_failure: true
only:
- /.+?\/[a-zA-Z0-9_-]+/
interruptible: true
# ================== live ================== #
build_live:
<<: *base_template
stage: build
cache:
<<: *cache
policy: pull
environment: "live"
variables:
CONFIG: ${LIVE_CONFIG}
URL: ${LIVE_DOMAIN}
UNTRACKED_EXTRAS: "data"
CONFIGURATION_FILE: "./local/bin/py/build/configurations/pull_config.yaml"
LOCAL: "False"
script:
- post_dd_event "documentation deploy ${CI_COMMIT_REF_NAME} started" "${CI_PROJECT_URL}/pipelines/${CI_PIPELINE_ID}" "info"
- notify_slack "<https://github.com/DataDog/documentation/commit/${CI_COMMIT_SHA}|${CI_COMMIT_SHA:0:8}> sent to gitlab for production deployment. <${CI_PROJECT_URL}/pipelines/${CI_PIPELINE_ID}|details>" "#FFD700"
- touch Makefile.config
- make clean-examples
- make examples
- sync_integration_descriptions
- sync_integration_metrics
- ./local/bin/py/build/pull_rbac.py $(get_secret 'dd-api-key') $(get_secret 'dd-app-key')
- placehold_translations
- yarn run prebuild
- yarn run build:live
- in-isolation deploy_live
- create_artifact
- create_artifact_ignored
- remove_static_from_repo
artifacts:
when: on_success
paths:
- ${ARTIFACT_RESOURCE}
- ./integrations_data
- content/en
- .htmltest.yml
expire_in: 1 week
only:
- master
index_internal_doc:
stage: post-deploy
cache: {}
environment: "live"
image: registry.ddbuild.io/datadoc/webapp:prod-released
dependencies:
- build_live
only:
- master
except: [ tags, schedules ]
tags: ["runner:main"]
script:
- INDEXING_SERVICE=https://datadoc.ddbuild.io index-repository hugo https://docs.datadoghq.com/ "Datadog" "Public Documentation" --source_folder=content/en --tags="team:Documentation,source:hugo-website,visibility:public,github-repository:documentation"
test_live_link_checks:
<<: *base_template
stage: post-deploy
cache: {}
environment: "live"
variables:
URL: ${LIVE_DOMAIN}
GIT_STRATEGY: none
script:
- post_dd_event "documentation htmltest ${CI_COMMIT_REF_NAME} started" "${CI_PROJECT_URL}/pipelines/${CI_PIPELINE_ID}" "info"
- find ./public -name "*.html" -exec sed -i -e "s#https://docs.datadoghq.com/#/#g" {} +
- find ./public -name "*.html" -exec sed -i -e "s#/api/v1/#/api/latest/#g" {} +
- find ./public -name "*.html" -exec sed -i -e "s#/api/v2/#/api/latest/#g" {} +
- htmltest
after_script:
- "[ -f /usr/local/bin/helpers.sh ] && source /usr/local/bin/helpers.sh" # source helpers
- RESULT="⛈ htmltest result; the following issues were found:\n$(tail -n +2 ./tmp/.htmltest/htmltest.log)\n--------------------" # output all but first line
- if grep -q "not exist" tmp/.htmltest/htmltest.log; then notify_slack "${RESULT}" "#31b834"; fi
only:
- master
artifacts:
paths:
- ./tmp/.htmltest
index_algolia:
image:
name: 486234852809.dkr.ecr.us-east-1.amazonaws.com/docsearch-scraper:v2978988-4692ed5-0.8
entrypoint: [ "" ] # force an empty entrypoint (see https://gitlab.com/gitlab-org/gitlab-runner/issues/2692)
tags: ["runner:main"]
stage: post-deploy
cache:
<<: *cache
policy: pull
environment: "live"
timeout: 1h 30m
script:
- |-
echo APPLICATION_ID=$(get_secret 'ci.documentation.algolia_docsearch_application_id') > .env
echo API_KEY=$(get_secret 'ci.documentation.algolia_docsearch_api_key') >> .env
export DISPLAY=:99
Xvfb :99 -ac &
echo "n" | docsearch run ./local/etc/algolia/docs_datadoghq.json
dependencies:
- build_live
only:
- schedules
replica_algolia:
<<: *base_template
stage: post-deploy
cache:
<<: *cache
policy: pull
environment: "live"
script:
- ALGOLIA_APP_ID=$(get_secret 'algolia_docsearch_application_id') ALGOLIA_ADMIN_KEY=$(get_secret 'algolia_docsearch_api_key') yarn run algolia:config
dependencies:
- build_live
only:
- schedules
sourcemaps_live:
<<: *base_template
stage: post-deploy
cache:
<<: *cache
policy: pull
environment: "live"
script:
# Rename any js.map files to include SHA if correlating JS file is fingerprinted. Hugo's asset build system seems to lose the fingerprint value when generating source maps.
- find ./public -type f -name "*.*.js" -exec bash -c 'x={}; hash=$(basename $x | cut -d '.' -f 2); map=${x/$hash./}.map; mv $map ${map/.js/.$hash.js}' \;
- DATADOG_API_KEY="$(get_secret 'dd-api-key')" ./node_modules/.bin/datadog-ci sourcemaps upload ./public/static --service docs --minified-path-prefix "https://docs.datadoghq.com/static/" --release-version "${CI_COMMIT_SHORT_SHA}"
dependencies:
- build_live
allow_failure: true
only:
- master
evaluate_missing_metrics:
<<: *base_template
stage: post-deploy
cache: {}
environment: "live"
script:
- chmod +x ./local/bin/py/missing_metrics.py && ./local/bin/py/missing_metrics.py -k $(get_secret 'dd-demo-api-key') -p $(get_secret 'dd-demo-app-key') -a $(get_secret 'dd-api-key') -b $(get_secret 'dd-app-key')
when: manual
only:
- master
# Uploads git ignored source (EN) files to Transifex as part of the nightly build.
# The translation syncing pipeline is triggered by github webhook, but these files are not in git.
# This allows some dynamically built content (such as integrations) to be localized automatically.
manage_ignored_translations:on-schedule:
<<: *base_template
stage: post-deploy
cache: {}
environment: "live"
only:
- master
script:
- echo "Downloading ignored translation source files..."
- manage_ignored_translation_files
when: manual
# Legacy translations nightly job
# manage_translations:on-schedule:
# <<: *base_template
# stage: post-deploy
# cache:
# <<: *cache
# policy: pull
# environment: "live"
# variables:
# URL: ${PREVIEW_DOMAIN}
# CONFIG: ${PREVIEW_CONFIG}
# script:
# - |-
# if [[ $(date +%u) -lt 6 ]]; then
# nodenv shell 14.16.0
# [ -d ./node_modules ] && rm -rf ./node_modules
# yarn add https://s3.amazonaws.com/origin-static-assets/corp-node-packages/master/translate-v1.0.42.tgz
# DATADOG_API_KEY="$(get_secret 'dd_synthetic_api_key_prod')" manage_translations "${APIKEY}";
# fi
# chmod +x ./local/bin/py/translate_metrics.py && ./local/bin/py/translate_metrics.py -k "${APIKEY}" -a $(get_secret 'dd_api_key')
# artifacts:
# paths:
# - translate-debug.log
# only:
# - schedules
test_missing_tms_live:
<<: *base_template
stage: post-deploy
cache: {}
environment: "live"
variables:
GIT_STRATEGY: none
dependencies:
- build_live
script:
- check_missing_tms
only:
- master
test_pa11y:
<<: *base_template
stage: post-deploy
cache:
<<: *cache
policy: pull
environment: "live"
dependencies:
- build_live
script:
- node ./local/bin/js/pa11y.js --env live --dd_api_key $(get_secret 'dd-api-key')
only:
- schedules
#rollback_live:
# <<: *base_template
# stage: cleanup
# environment: "live"
# when: on_failure
# script:
# - rollback_env
# only:
# - master
tag_successful_live_pipeline:
<<: *base_template
stage: cleanup
cache: {}
environment: "live"
when: on_success
script:
- tag_successful_pipeline
only:
- master
post_success_event_to_dd_live:
<<: *base_template
stage: cleanup
cache: {}
environment: "live"
variables:
GIT_STRATEGY: none
when: on_success
script:
- post_dd_event "documentation deploy ${CI_COMMIT_REF_NAME} succeeded" "${CI_PROJECT_URL}/pipelines/${CI_PIPELINE_ID}" "success"
- post_dd_metric "documentation.pipeline.completed" "1" "" "success"
only:
- master
post_failure_event_to_dd_live:
<<: *base_template
stage: cleanup
cache: {}
environment: "live"
variables:
GIT_STRATEGY: none
when: on_failure
script:
- post_dd_event "documentation deploy ${CI_COMMIT_REF_NAME} failed" "${CI_PROJECT_URL}/pipelines/${CI_PIPELINE_ID}" "error"
- post_dd_metric "documentation.pipeline.completed" "0" "" "failure"
only:
- master