-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy path.gitlab-ci.yml
497 lines (465 loc) · 16.2 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
# You can override the included template(s) by including variable overrides
# SAST customization: https://docs.gitlab.com/ee/user/application_security/sast/#customizing-the-sast-settings
# Secret Detection customization: https://docs.gitlab.com/ee/user/application_security/secret_detection/#customizing-settings
# Dependency Scanning customization: https://docs.gitlab.com/ee/user/application_security/dependency_scanning/#customizing-the-dependency-scanning-settings
# Container Scanning customization: https://docs.gitlab.com/ee/user/application_security/container_scanning/#customizing-the-container-scanning-settings
# Note that environment variables can be set in several places
# See https://docs.gitlab.com/ee/ci/variables/#cicd-variable-precedence
stages:
- build
- test
- deploy
- manifest
include:
- remote: https://gitlab.com/yobasystems/gitlab-ci-templates/raw/master/container_scanning_all_arch.yml
- template: Security/Secret-Detection.gitlab-ci.yml
- template: Security/SAST.gitlab-ci.yml
.build_template: &build_definition
image: yobasystems/alpine-docker:dind
stage: build
script:
- echo "Build Timestamp ${CI_COMMIT_TIMESTAMP} - ${CI_COMMIT_SHORT_SHA}"
- echo "Building for ARCH=${ARCH}, PLATFORM=${PLATFORM}"
- apk add --update git
- cd alpine-nginx-${ARCH}/
- docker build
--build-arg VCS_REF=${CI_COMMIT_SHORT_SHA}
--build-arg BUILD_DATE=${CI_COMMIT_TIMESTAMP}
-t ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH}
--platform linux/${PLATFORM}
.
- echo "$CI_JOB_TOKEN" | docker login -u gitlab-ci-token "$CI_REGISTRY" --password-stdin
- docker push ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH}
amd64 alpine-nginx build:
<<: *build_definition
tags:
- amd64
variables:
ARCH: amd64
PLATFORM: amd64
arm32v7 alpine-nginx build:
<<: *build_definition
tags:
- armhf
variables:
ARCH: armhf
PLATFORM: arm/v7
arm64v8 alpine-nginx build:
<<: *build_definition
tags:
- aarch64
variables:
ARCH: aarch64
PLATFORM: arm64/v8
sast:
stage: test
.deploy_template: &deploy_definition
image: yobasystems/alpine-docker:dind
stage: deploy
rules:
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
script:
- echo "$CI_JOB_TOKEN" | docker login -u gitlab-ci-token "$CI_REGISTRY" --password-stdin
- echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
- echo "$QUAY_PASSWORD" | docker login -u "$QUAY_USERNAME" quay.io --password-stdin
- echo "$GITHUB_TOKEN" | docker login ghcr.io -u "$GITHUB_USERNAME" --password-stdin
- docker pull ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH}
- docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH} $CI_REGISTRY_IMAGE:${ARCH}
- docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH} $DOCKER_REGISTRY_DOCKERHUB_REPO:${ARCH}
- docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH} quay.io/$DOCKER_REGISTRY_QUAY_REPO:${ARCH}
- docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH} ghcr.io/$DOCKER_REGISTRY_GHCR_REPO:${ARCH}
- docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH} $CI_REGISTRY_IMAGE:${ARCH2}
- docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH} $DOCKER_REGISTRY_DOCKERHUB_REPO:${ARCH2}
- docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH} quay.io/$DOCKER_REGISTRY_QUAY_REPO:${ARCH2}
- docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH} ghcr.io/$DOCKER_REGISTRY_GHCR_REPO:${ARCH2}
- docker push $CI_REGISTRY_IMAGE:${ARCH}
- docker push $DOCKER_REGISTRY_DOCKERHUB_REPO:${ARCH}
- docker push quay.io/$DOCKER_REGISTRY_QUAY_REPO:${ARCH}
- docker push ghcr.io/$DOCKER_REGISTRY_GHCR_REPO:${ARCH}
- docker push $CI_REGISTRY_IMAGE:${ARCH2}
- docker push $DOCKER_REGISTRY_DOCKERHUB_REPO:${ARCH2}
- docker push quay.io/$DOCKER_REGISTRY_QUAY_REPO:${ARCH2}
- docker push ghcr.io/$DOCKER_REGISTRY_GHCR_REPO:${ARCH2}
- |
if [[ "$CI_COMMIT_TAG" ]]; then
docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH} $CI_REGISTRY_IMAGE:${CI_COMMIT_TAG}-${ARCH}
docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH} $DOCKER_REGISTRY_DOCKERHUB_REPO:${CI_COMMIT_TAG}-${ARCH}
docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH} quay.io/$DOCKER_REGISTRY_QUAY_REPO:${CI_COMMIT_TAG}-${ARCH}
docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH} ghcr.io/$DOCKER_REGISTRY_GHCR_REPO:${CI_COMMIT_TAG}-${ARCH}
docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH} $CI_REGISTRY_IMAGE:${CI_COMMIT_TAG}-${ARCH2}
docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH} $DOCKER_REGISTRY_DOCKERHUB_REPO:${CI_COMMIT_TAG}-${ARCH2}
docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH} quay.io/$DOCKER_REGISTRY_QUAY_REPO:${CI_COMMIT_TAG}-${ARCH2}
docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH} ghcr.io/$DOCKER_REGISTRY_GHCR_REPO:${CI_COMMIT_TAG}-${ARCH2}
docker push $CI_REGISTRY_IMAGE:${CI_COMMIT_TAG}-${ARCH}
docker push $DOCKER_REGISTRY_DOCKERHUB_REPO:${CI_COMMIT_TAG}-${ARCH}
docker push quay.io/$DOCKER_REGISTRY_QUAY_REPO:${CI_COMMIT_TAG}-${ARCH}
docker push ghcr.io/$DOCKER_REGISTRY_GHCR_REPO:${CI_COMMIT_TAG}-${ARCH}
docker push $CI_REGISTRY_IMAGE:${CI_COMMIT_TAG}-${ARCH2}
docker push $DOCKER_REGISTRY_DOCKERHUB_REPO:${CI_COMMIT_TAG}-${ARCH2}
docker push quay.io/$DOCKER_REGISTRY_QUAY_REPO:${CI_COMMIT_TAG}-${ARCH2}
docker push ghcr.io/$DOCKER_REGISTRY_GHCR_REPO:${CI_COMMIT_TAG}-${ARCH2}
fi
amd64 alpine-nginx deploy:
<<: *deploy_definition
tags:
- amd64
variables:
ARCH: amd64
ARCH2: x86_64
PLATFORM: amd64
needs:
- amd64 alpine-nginx build
arm32v7 alpine-nginx deploy:
<<: *deploy_definition
tags:
- armhf
variables:
ARCH: armhf
ARCH2: arm32v7
PLATFORM: arm/v7
needs:
- arm32v7 alpine-nginx build
arm64v8 alpine-nginx deploy:
<<: *deploy_definition
tags:
- aarch64
variables:
ARCH: aarch64
ARCH2: arm64v8
PLATFORM: arm64/v8
needs:
- arm64v8 alpine-nginx build
amd64 alpine-nginx-git build:
<<: *build_definition
tags:
- amd64
variables:
ARCH: amd64
PLATFORM: amd64
VARIANT: git
script:
- echo "Build Timestamp ${CI_COMMIT_TIMESTAMP} - ${CI_COMMIT_SHORT_SHA}"
- echo "Building for ARCH=${ARCH}, PLATFORM=${PLATFORM}, VARIANT=${VARIANT}"
- apk add --update git
- cd alpine-nginx-${VARIANT}-${ARCH}/
- docker build
--build-arg VCS_REF=${CI_COMMIT_SHORT_SHA}
--build-arg BUILD_DATE=${CI_COMMIT_TIMESTAMP}
-t ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH}-${VARIANT}
--platform linux/${PLATFORM}
.
- echo "$CI_JOB_TOKEN" | docker login -u gitlab-ci-token "$CI_REGISTRY" --password-stdin
- docker push ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH}-${VARIANT}
arm32v7 alpine-nginx-git build:
<<: *build_definition
tags:
- armhf
variables:
ARCH: armhf
PLATFORM: arm/v7
VARIANT: git
script:
- !reference [amd64 alpine-nginx-git build, script]
arm64v8 alpine-nginx-git build:
<<: *build_definition
tags:
- aarch64
variables:
ARCH: aarch64
PLATFORM: arm64/v8
VARIANT: git
script:
- !reference [amd64 alpine-nginx-git build, script]
amd64 alpine-nginx-git-ssh build:
<<: *build_definition
tags:
- amd64
variables:
ARCH: amd64
PLATFORM: amd64
VARIANT: git-ssh
script:
- !reference [amd64 alpine-nginx-git build, script]
arm32v7 alpine-nginx-git-ssh build:
<<: *build_definition
tags:
- armhf
variables:
ARCH: armhf
PLATFORM: arm/v7
VARIANT: git-ssh
script:
- !reference [amd64 alpine-nginx-git build, script]
arm64v8 alpine-nginx-git-ssh build:
<<: *build_definition
tags:
- aarch64
variables:
ARCH: aarch64
PLATFORM: arm64/v8
VARIANT: git-ssh
script:
- !reference [amd64 alpine-nginx-git build, script]
amd64 alpine-nginx-stable build:
<<: *build_definition
tags:
- amd64
variables:
ARCH: amd64
PLATFORM: amd64
VARIANT: stable
script:
- !reference [amd64 alpine-nginx-git build, script]
arm32v7 alpine-nginx-stable build:
<<: *build_definition
tags:
- armhf
variables:
ARCH: armhf
PLATFORM: arm/v7
VARIANT: stable
script:
- !reference [amd64 alpine-nginx-git build, script]
arm64v8 alpine-nginx-stable build:
<<: *build_definition
tags:
- aarch64
variables:
ARCH: aarch64
PLATFORM: arm64/v8
VARIANT: stable
script:
- !reference [amd64 alpine-nginx-git build, script]
amd64 alpine-nginx-git deploy:
<<: *deploy_definition
variables:
ARCH: amd64
ARCH2: x86_64
PLATFORM: amd64
VARIANT: git
needs:
- amd64 alpine-nginx-git build
script:
- echo "$CI_JOB_TOKEN" | docker login -u gitlab-ci-token "$CI_REGISTRY" --password-stdin
- echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
- echo "$QUAY_PASSWORD" | docker login -u "$QUAY_USERNAME" quay.io --password-stdin
- echo "$GITHUB_TOKEN" | docker login ghcr.io -u "$GITHUB_USERNAME" --password-stdin
- docker pull ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH}-${VARIANT}
- docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH}-${VARIANT} $CI_REGISTRY_IMAGE:${ARCH}-${VARIANT}
- docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH}-${VARIANT} $DOCKER_REGISTRY_DOCKERHUB_REPO:${ARCH}-${VARIANT}
- docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH}-${VARIANT} quay.io/$DOCKER_REGISTRY_QUAY_REPO:${ARCH}-${VARIANT}
- docker tag ${CI_REGISTRY_IMAGE}/${CI_COMMIT_SHORT_SHA}:${ARCH}-${VARIANT} ghcr.io/$DOCKER_REGISTRY_GHCR_REPO:${ARCH}-${VARIANT}
- docker push $CI_REGISTRY_IMAGE:${ARCH}-${VARIANT}
- docker push $DOCKER_REGISTRY_DOCKERHUB_REPO:${ARCH}-${VARIANT}
- docker push quay.io/$DOCKER_REGISTRY_QUAY_REPO:${ARCH}-${VARIANT}
- docker push ghcr.io/$DOCKER_REGISTRY_GHCR_REPO:${ARCH}-${VARIANT}
manifest creation git:
image: yobasystems/alpine-docker:dind
stage: manifest
needs:
- amd64 alpine-nginx-git deploy
- arm32v7 alpine-nginx-git deploy
- arm64v8 alpine-nginx-git deploy
rules:
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
variables:
VARIANT: git
script:
- mkdir -p ~/.docker
- echo '{"experimental":"enabled"}' > ~/.docker/config.json
- echo "$CI_JOB_TOKEN" | docker login -u gitlab-ci-token "$CI_REGISTRY" --password-stdin
- echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
- echo "$QUAY_PASSWORD" | docker login -u "$QUAY_USERNAME" quay.io --password-stdin
- echo "$GITHUB_TOKEN" | docker login ghcr.io -u "$GITHUB_USERNAME" --password-stdin
- |
create_and_push_manifest() {
repo=$1
tag=$2
docker manifest create $repo:$tag \
$repo:amd64-${VARIANT} \
$repo:armhf-${VARIANT} \
$repo:aarch64-${VARIANT}
docker manifest annotate $repo:$tag $repo:amd64-${VARIANT} --os linux --arch amd64
docker manifest annotate $repo:$tag $repo:armhf-${VARIANT} --os linux --arch arm --variant v7
docker manifest annotate $repo:$tag $repo:aarch64-${VARIANT} --os linux --arch arm64 --variant v8
docker manifest push $repo:$tag
}
- |
for repo in $CI_REGISTRY_IMAGE $DOCKER_REGISTRY_DOCKERHUB_REPO quay.io/$DOCKER_REGISTRY_QUAY_REPO ghcr.io/$DOCKER_REGISTRY_GHCR_REPO; do
create_and_push_manifest $repo ${VARIANT}
done
arm32v7 alpine-nginx-git deploy:
<<: *deploy_definition
tags:
- armhf
variables:
ARCH: armhf
ARCH2: arm32v7
PLATFORM: arm/v7
VARIANT: git
needs:
- arm32v7 alpine-nginx-git build
script:
- !reference [amd64 alpine-nginx-git deploy, script]
arm64v8 alpine-nginx-git deploy:
<<: *deploy_definition
tags:
- aarch64
variables:
ARCH: aarch64
ARCH2: arm64v8
PLATFORM: arm64/v8
VARIANT: git
needs:
- arm64v8 alpine-nginx-git build
script:
- !reference [amd64 alpine-nginx-git deploy, script]
amd64 alpine-nginx-git-ssh deploy:
<<: *deploy_definition
tags:
- amd64
variables:
ARCH: amd64
ARCH2: x86_64
PLATFORM: amd64
VARIANT: git-ssh
needs:
- amd64 alpine-nginx-git-ssh build
script:
- !reference [amd64 alpine-nginx-git deploy, script]
arm32v7 alpine-nginx-git-ssh deploy:
<<: *deploy_definition
tags:
- armhf
variables:
ARCH: armhf
ARCH2: arm32v7
PLATFORM: arm/v7
VARIANT: git-ssh
needs:
- arm32v7 alpine-nginx-git-ssh build
script:
- !reference [amd64 alpine-nginx-git deploy, script]
arm64v8 alpine-nginx-git-ssh deploy:
<<: *deploy_definition
tags:
- aarch64
variables:
ARCH: aarch64
ARCH2: arm64v8
PLATFORM: arm64/v8
VARIANT: git-ssh
needs:
- arm64v8 alpine-nginx-git-ssh build
script:
- !reference [amd64 alpine-nginx-git deploy, script]
amd64 alpine-nginx-stable deploy:
<<: *deploy_definition
tags:
- amd64
variables:
ARCH: amd64
ARCH2: x86_64
PLATFORM: amd64
VARIANT: stable
needs:
- amd64 alpine-nginx-stable build
script:
- !reference [amd64 alpine-nginx-git deploy, script]
arm32v7 alpine-nginx-stable deploy:
<<: *deploy_definition
tags:
- armhf
variables:
ARCH: armhf
ARCH2: arm32v7
PLATFORM: arm/v7
VARIANT: stable
needs:
- arm32v7 alpine-nginx-stable build
script:
- !reference [amd64 alpine-nginx-git deploy, script]
arm64v8 alpine-nginx-stable deploy:
<<: *deploy_definition
tags:
- aarch64
variables:
ARCH: aarch64
ARCH2: arm64v8
PLATFORM: arm64/v8
VARIANT: stable
needs:
- arm64v8 alpine-nginx-stable build
script:
- !reference [amd64 alpine-nginx-git deploy, script]
manifest creation git-ssh:
image: yobasystems/alpine-docker:dind
stage: manifest
needs:
- amd64 alpine-nginx-git-ssh deploy
- arm32v7 alpine-nginx-git-ssh deploy
- arm64v8 alpine-nginx-git-ssh deploy
rules:
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
variables:
VARIANT: git-ssh
script:
- !reference [manifest creation git, script]
manifest creation stable:
image: yobasystems/alpine-docker:dind
stage: manifest
needs:
- amd64 alpine-nginx-stable deploy
- arm32v7 alpine-nginx-stable deploy
- arm64v8 alpine-nginx-stable deploy
rules:
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
variables:
VARIANT: stable
script:
- !reference [manifest creation git, script]
manifest creation version:
image: yobasystems/alpine-docker:dind
stage: manifest
needs:
- amd64 alpine-nginx deploy
- arm32v7 alpine-nginx deploy
- arm64v8 alpine-nginx deploy
rules:
- if: $CI_COMMIT_TAG
script:
- mkdir -p ~/.docker
- echo '{"experimental":"enabled"}' > ~/.docker/config.json
- echo "$CI_JOB_TOKEN" | docker login -u gitlab-ci-token "$CI_REGISTRY" --password-stdin
- echo "$DOCKERHUB_PASSWORD" | docker login -u "$DOCKERHUB_USERNAME" --password-stdin
- echo "$QUAY_PASSWORD" | docker login -u "$QUAY_USERNAME" quay.io --password-stdin
- echo "$GITHUB_TOKEN" | docker login ghcr.io -u "$GITHUB_USERNAME" --password-stdin
- |
create_and_push_manifest() {
repo=$1
tag=$2
docker manifest create $repo:$tag --amend \
$repo:amd64 \
$repo:armhf \
$repo:aarch64
docker manifest annotate $repo:$tag $repo:amd64 --os linux --arch amd64
docker manifest annotate $repo:$tag $repo:armhf --os linux --arch arm --variant v7
docker manifest annotate $repo:$tag $repo:aarch64 --os linux --arch arm64 --variant v8
docker manifest push $repo:$tag
}
- echo "Processing tag $CI_COMMIT_TAG"
- VERSION=$(echo $CI_COMMIT_TAG | cut -d- -f1)
- MAJOR=$(echo $VERSION | cut -d. -f1)
- MINOR=$(echo $VERSION | cut -d. -f2)
- PATCH=$(echo $VERSION | cut -d. -f3)
- |
for repo in $CI_REGISTRY_IMAGE $DOCKER_REGISTRY_DOCKERHUB_REPO quay.io/$DOCKER_REGISTRY_QUAY_REPO ghcr.io/$DOCKER_REGISTRY_GHCR_REPO; do
create_and_push_manifest $repo $CI_COMMIT_TAG
create_and_push_manifest $repo $MAJOR
create_and_push_manifest $repo $MAJOR.$MINOR
create_and_push_manifest $repo $MAJOR.$MINOR.$PATCH
done