-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.gitlab-ci.yml
502 lines (468 loc) · 14 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
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
stages:
- build
- test
- test-report-aggregate
- deploy
- publish
- cleanup
variables:
# Variables required by Common CI jobs
CI_COMMON_JOB_VERSION: 'd4e29410ea168096e1a822f77c7ce741d9cfb57a'
DOCKER_BUILDER_TAG: '$CI_COMMON_JOB_VERSION'
DOCKER_DIND_TAG: '$CI_COMMON_JOB_VERSION'
IMAGE_REMOVER_TAG: '$CI_COMMON_JOB_VERSION'
BLOG_APP_SRC_DIR: 'apps/blog/'
include:
- template: Workflows/Branch-Pipelines.gitlab-ci.yml
- project: 'hive/common-ci-configuration'
ref: d4e29410ea168096e1a822f77c7ce741d9cfb57a # develop
file: '/templates/docker_image_jobs.gitlab-ci.yml'
.docker_build_template:
extends: .docker_image_builder_job_template
stage: build
before_script:
- !reference [.docker_image_builder_job_template, before_script]
- |
echo -e "\e[0Ksection_start:$(date +%s):login[collapsed=true]\r\e[0KLogging to Docker registry..."
docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
echo -e "\e[0Ksection_end:$(date +%s):login\r\e[0K"
script:
- |
echo -e "\e[0Ksection_start:$(date +%s):tag[collapsed=true]\r\e[0KDetermining tag for the new image..."
if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
export TAG="latest"
else
echo "Running on branch '$CI_COMMIT_BRANCH': tag = $CI_COMMIT_REF_SLUG"
export TAG="$CI_COMMIT_REF_SLUG"
fi
echo -e "\e[0Ksection_end:$(date +%s):tag\r\e[0K"
echo -e "\e[0Ksection_start:$(date +%s):build[collapsed=true]\r\e[0KBaking image "$CI_REGISTRY_IMAGE/${TURBO_APP_NAME}:${TAG}"..."
git config --global --add safe.directory "$CI_PROJECT_DIR"
scripts/build_instance.sh --progress=plain "$CI_PROJECT_DIR"
echo "IMAGE_NAME=${CI_REGISTRY_IMAGE}/${TURBO_APP_NAME}:${CI_COMMIT_SHORT_SHA}" > docker-build.env
echo "Unique image tag:"
cat docker-build.env
echo -e "\e[0Ksection_end:$(date +%s):build\r\e[0K"
artifacts:
paths:
- docker-build.env
reports:
dotenv: docker-build.env
tags:
- public-runner-docker
docker-build-auth:
extends: .docker_build_template
variables:
TURBO_APP_SCOPE: '@hive/auth'
TURBO_APP_PATH: '/apps/auth'
TURBO_APP_NAME: 'auth'
docker-build-blog:
extends: .docker_build_template
variables:
TURBO_APP_SCOPE: '@hive/blog'
TURBO_APP_PATH: '/apps/blog'
TURBO_APP_NAME: 'blog'
docker-build-wallet:
extends: .docker_build_template
variables:
TURBO_APP_SCOPE: '@hive/wallet'
TURBO_APP_PATH: '/apps/wallet'
TURBO_APP_NAME: 'wallet'
.node-job:
extends: .job-defaults
image:
name: node:20.11.1-alpine3.18
entrypoint: []
stage: test
before_script:
- corepack enable
- corepack prepare pnpm@latest-9 --activate
- pnpm config set store-dir .pnpm-store
script:
- |
echo -e "\e[0Ksection_start:$(date +%s):deps[collapsed=true]\r\e[0KInstalling dependencies..."
pnpm install --frozen-lockfile
echo -e "\e[0Ksection_end:$(date +%s):deps\r\e[0K"
cache:
key: '$TURBO_APP_SCOPE-cache-2'
paths:
- .npm/
- .pnpm-store/
- .next/
artifacts:
name: '$CI_JOB_NAME-$CI_COMMIT_REF_NAME'
when: always
expire_in: 1 week
tags:
- public-runner-docker
.e2e_tests_template:
extends: .node-job
image: mcr.microsoft.com/playwright:v1.49.1-jammy
variables:
CI_DEBUG_SERVICES: true
FF_NETWORK_PER_BUILD: 1
REACT_APP_API_ENDPOINT: https://api.hive.blog
REACT_APP_IMAGES_ENDPOINT: https://images.hive.blog/
DENSER_URL: https://caddy
parallel:
matrix:
- PROJECT: ['chromium', 'firefox', 'webkit']
SHARD_INDEX: [1, 2, 3, 4, 5]
SHARD_TOTAL: 5
script:
- !reference [.node-job, script]
- |
echo -e "\e[0Ksection_start:$(date +%s):tests[collapsed=false]\r\e[0KRunning tests..."
cd .$TURBO_APP_PATH
npx playwright test --project=$PROJECT --shard=$SHARD_INDEX/$SHARD_TOTAL --update-snapshots
echo -e "\e[0Ksection_end:$(date +%s):tests\r\e[0K"
artifacts:
paths:
- .${TURBO_APP_PATH}/playwright-report/
- .${TURBO_APP_PATH}/test-results/
- .${TURBO_APP_PATH}/junit/
reports:
junit: .${TURBO_APP_PATH}/junit/**/**/results.xml
e2e-tests-blog:
extends: .e2e_tests_template
needs:
- docker-build-blog
services:
- name: $IMAGE_NAME
alias: denser
variables:
HEALTHCHECK_TCP_PORT: '3000'
- name: caddy:2.7.6
command:
- caddy
- reverse-proxy
- --from=https://caddy
- --to=denser:3000
- --internal-certs
variables:
TURBO_APP_SCOPE: '@hive/blog'
TURBO_APP_PATH: '/apps/blog'
PORT: 3000
e2e-tests-wallet:
extends: .e2e_tests_template
needs:
- docker-build-wallet
services:
- name: $IMAGE_NAME
alias: denser
variables:
HEALTHCHECK_TCP_PORT: '4000'
- name: caddy:2.7.6
command:
- caddy
- reverse-proxy
- --from=https://caddy
- --to=denser:4000
- --internal-certs
variables:
TURBO_APP_SCOPE: '@hive/wallet'
TURBO_APP_PATH: '/apps/wallet'
PORT: 4000
.e2e_report_aggregate_template:
extends: .node-job
stage: test-report-aggregate
when: always
image: mcr.microsoft.com/playwright:v1.49.1-jammy
script:
- cd .$TURBO_APP_PATH
- pnpm install -D playwright-merge-html-reports
- ./node_modules/.bin/playwright test tests/merge-reports --config playwright.merge.config.ts
artifacts:
paths:
- .${TURBO_APP_PATH}/merged-html-report/
- .${TURBO_APP_PATH}/junit/
e2e-report-aggregate-blog:
extends: .e2e_report_aggregate_template
needs:
- e2e-tests-blog
variables:
TURBO_APP_SCOPE: '@hive/blog'
TURBO_APP_PATH: '/apps/blog'
PROJECTS: '["chromium", "firefox", "webkit"]'
SHARD_TOTAL: 5
e2e-report-aggregate-wallet:
extends: .e2e_report_aggregate_template
needs:
- e2e-tests-wallet
variables:
TURBO_APP_SCOPE: '@hive/wallet'
TURBO_APP_PATH: '/apps/wallet'
PROJECTS: '["chromium", "firefox", "webkit"]'
SHARD_TOTAL: 5
publish:
image:
name: node:20.11.1-alpine3.18
entrypoint: []
extends: .job-defaults
stage: deploy
script:
# Extract a few values from package.json
- NPM_PACKAGE_NAME=$(node -p "require('./package.json').name")
- NPM_PACKAGE_VERSION=$(node -p "require('./package.json').version")
# Validate that the package name is properly scoped to the project's root namespace.
# For more information, see https://docs.gitlab.com/ee/user/packages/npm_registry/#package-naming-convention
- |
if [[ ! $NPM_PACKAGE_NAME =~ ^@$CI_PROJECT_ROOT_NAMESPACE/ ]]; then
echo "Invalid package scope! Packages must be scoped in the root namespace of the project, e.g. \"@${CI_PROJECT_ROOT_NAMESPACE}/${CI_PROJECT_NAME}\""
echo 'For more information, see https://docs.gitlab.com/ee/user/packages/npm_registry/#package-naming-convention'
exit 1
fi
# Compare the version in package.json to all published versions.
# If the package.json version has not yet been published, run `npm publish`.
- |
if [[ "$(npm view ${NPM_PACKAGE_NAME} versions)" != *"'${NPM_PACKAGE_VERSION}'"* ]]; then
npm publish
echo "Successfully published version ${NPM_PACKAGE_VERSION} of ${NPM_PACKAGE_NAME} to GitLab's NPM registry: ${CI_PROJECT_URL}/-/packages"
else
echo "Version ${NPM_PACKAGE_VERSION} of ${NPM_PACKAGE_NAME} has already been published, so no new version has been published."
fi
rules:
- if: '$CI_COMMIT_TAG && $CI_COMMIT_REF_PROTECTED == "true"'
when: manual
allow_failure: true
tags:
- public-runner-docker
.deploy_template_for_staging:
extends: .job-defaults
stage: deploy
before_script:
- |
echo -e "\e[0Ksection_start:$(date +%s):login[collapsed=true]\r\e[0KLogging to Docker registry..."
docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
echo -e "\e[0Ksection_end:$(date +%s):login\r\e[0K"
script:
- |
scripts/run_instance.sh \
--image="$IMAGE_NAME" \
--app-scope="$TURBO_APP_SCOPE" \
--app-path="$TURBO_APP_PATH" \
--api-endpoint="$API_ENDPOINT" \
--chain-id="$CHAIN_ID" \
--images-endpoint="$IMAGES_ENDPOINT" \
--name="$CONTAINER_NAME" \
--port=$PORT \
--detach
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: manual
allow_failure: true
tags:
- hs-denser
staging:deploy-auth:
extends: .deploy_template_for_staging
needs:
- docker-build-auth
variables:
PORT: 7000
API_ENDPOINT: https://api.hive.blog
IMAGES_ENDPOINT: https://images.hive.blog/
CONTAINER_NAME: denser-auth
TURBO_APP_SCOPE: '@hive/auth'
TURBO_APP_PATH: '/apps/auth'
environment:
name: staging-auth
action: start
on_stop: staging:stop-auth
staging:deploy-blog:
extends: .deploy_template_for_staging
needs:
- docker-build-blog
variables:
PORT: 3000
API_ENDPOINT: https://api.hive.blog
IMAGES_ENDPOINT: https://images.hive.blog/
WALLET_ENDPOINT: https://wallet.openhive.network
CONTAINER_NAME: denser-blog
TURBO_APP_SCOPE: '@hive/blog'
TURBO_APP_PATH: '/apps/blog'
environment:
name: staging-blog
action: start
on_stop: staging:stop-blog
staging:deploy-wallet:
extends: .deploy_template_for_staging
needs:
- docker-build-wallet
variables:
PORT: 4000
API_ENDPOINT: https://api.hive.blog
IMAGES_ENDPOINT: https://images.hive.blog/
CONTAINER_NAME: denser-wallet
TURBO_APP_SCOPE: '@hive/wallet'
TURBO_APP_PATH: '/apps/wallet'
environment:
name: staging-wallet
action: start
on_stop: staging:stop-wallet
.stop_template_for_staging:
extends: .job-defaults
stage: deploy
script:
- docker ps -q --filter "name=$CONTAINER_NAME" | grep -q . && docker stop $CONTAINER_NAME
rules:
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
when: manual
allow_failure: true
tags:
- hs-denser
staging:stop-auth:
extends: .stop_template_for_staging
needs:
- staging:deploy-auth
environment:
name: staging-auth
action: stop
variables:
CONTAINER_NAME: denser-auth
GIT_STRATEGY: none
staging:stop-blog:
extends: .stop_template_for_staging
needs:
- staging:deploy-blog
environment:
name: staging-blog
action: stop
variables:
CONTAINER_NAME: denser-blog
GIT_STRATEGY: none
staging:stop-wallet:
extends: .stop_template_for_staging
needs:
- staging:deploy-wallet
environment:
name: staging-wallet
action: stop
variables:
CONTAINER_NAME: denser-wallet
GIT_STRATEGY: none
review:deploy-auth:
extends: staging:deploy-auth
variables:
CONTAINER_NAME: denser-review-auth
PORT: 7001
AUTH_PORT: 7001
API_ENDPOINT: https://api.fake.openhive.network/
CHAIN_ID: '42'
IMAGES_ENDPOINT: https://images.hive.blog/
SITE_DOMAIN: https://auth.fake.openhive.network
LOGGING_BROWSER_ENABLED: false
LOGGING_LOG_LEVEL: info
environment:
name: review-auth
action: start
on_stop: review:stop-auth
review:deploy-blog:
extends: staging:deploy-blog
variables:
CONTAINER_NAME: denser-review-blog
PORT: 3001
BLOG_PORT: 3001
API_ENDPOINT: https://api.fake.openhive.network/
CHAIN_ID: '42'
IMAGES_ENDPOINT: https://images.hive.blog/
WALLET_ENDPOINT: https://wallet.fake.openhive.network
SITE_DOMAIN: https://blog.fake.openhive.network
LOGGING_BROWSER_ENABLED: false
LOGGING_LOG_LEVEL: info
environment:
name: review-blog
action: start
on_stop: review:stop-blog
review:deploy-wallet:
extends: staging:deploy-wallet
variables:
CONTAINER_NAME: denser-review-wallet
PORT: 4001
WALLET_PORT: 4001
API_ENDPOINT: https://api.fake.openhive.network/
CHAIN_ID: '42'
IMAGES_ENDPOINT: https://images.hive.blog/
SITE_DOMAIN: https://wallet.fake.openhive.network
BLOG_DOMAIN: https://blog.fake.openhive.network
LOGGING_BROWSER_ENABLED: false
LOGGING_LOG_LEVEL: info
environment:
name: review-wallet
action: start
on_stop: review:stop-wallet
review:stop-auth:
extends: staging:stop-auth
needs:
- review:deploy-auth
variables:
CONTAINER_NAME: denser-review-auth
environment:
name: review-auth
action: stop
review:stop-blog:
extends: staging:stop-blog
needs:
- review:deploy-blog
variables:
CONTAINER_NAME: denser-review-blog
environment:
name: review-blog
action: stop
review:stop-wallet:
extends: staging:stop-wallet
needs:
- review:deploy-wallet
variables:
CONTAINER_NAME: denser-review-wallet
environment:
name: review-wallet
action: stop
build_and_publish_auth_image:
stage: publish
extends: .publish_docker_image_template
variables:
TURBO_APP_SCOPE: '@hive/auth'
TURBO_APP_PATH: '/apps/auth'
TURBO_APP_NAME: 'auth'
before_script:
- !reference [.publish_docker_image_template, before_script]
script:
- scripts/ci-helpers/build_and_publish_instance.sh
tags:
- public-runner-docker
- hived-for-tests
build_and_publish_blog_image:
stage: publish
extends: .publish_docker_image_template
variables:
TURBO_APP_SCOPE: '@hive/blog'
TURBO_APP_PATH: '/apps/blog'
TURBO_APP_NAME: 'blog'
before_script:
- !reference [.publish_docker_image_template, before_script]
script:
- scripts/ci-helpers/build_and_publish_instance.sh
tags:
- public-runner-docker
- hived-for-tests
build_and_publish_wallet_image:
stage: publish
extends: .publish_docker_image_template
variables:
TURBO_APP_SCOPE: '@hive/wallet'
TURBO_APP_PATH: '/apps/wallet'
TURBO_APP_NAME: 'wallet'
before_script:
- !reference [.publish_docker_image_template, before_script]
script:
- scripts/ci-helpers/build_and_publish_instance.sh
tags:
- public-runner-docker
- hived-for-tests
buildkit_cache_cleanup:
stage: cleanup
extends: .buildkit_cleanup_job_template
needs: []
variables:
CACHE_REPOSITORIES: 'auth/cache,blog/cache,wallet/cache'