-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
96 lines (91 loc) · 3.89 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
# SPDX-FileCopyrightText: 2019-2024 Michael Picht <[email protected]>
#
# SPDX-License-Identifier: GPL-3.0-or-later
# Pipeline to build repman images for different architectures and store them
# under a multi-arch manifest on docker hub.
# The architecture-specific images are built in child pipelines (one for each
# architecture) and pushed to docker hub (build stage).
# In the deploy stage, a multi-arch manifest is created and pushed to docker hub
# as well. After that, architecture-specific tags are removed from docker hub.
#
# Note: Architecture-specific images have to be built separately by a specific
# runner for the corresponding architecture since a build using emulation
# (qemu) does not work. Although images could be built in one go with
# docker buildx build -platform=<PLATFORM1>,<PLATFORM2>,... , running
# images where emulation was used during build would lead to a runtime
# error
# General start condition: Execute jobs only if a tag was created or if the
# pipeline is started by the scheduler
.start_condition: &start_condition
rules:
- if: $CI_COMMIT_TAG
- if: $CI_PIPELINE_SOURCE == "schedule"
# Generate Dockerfiles for supported architectures. Since image names can
# contain '/', '/' cannot be used as separator in the sed statement. Instead,
# '#' is used.
generate-dockerfiles:
stage: .pre
script:
- |
sed "s#{{BASE_IMAGE}}#${BASE_IMAGE_aarch64}#" templates/Dockerfile > ./Dockerfile-aarch64
sed "s#{{BASE_IMAGE}}#${BASE_IMAGE_x86_64}#" templates/Dockerfile > ./Dockerfile-x86_64
artifacts:
paths:
- ./Dockerfile-aarch64
- ./Dockerfile-x86_64
# Build images for different architectures and push them to docker hub
build-aarch64-parent:
stage: build
<<: *start_condition
trigger:
include: ci/gitlab-ci.aarch64.yml
strategy: depend
variables:
PARENT_PIPELINE_ID: $CI_PIPELINE_ID
build-x86_64-parent:
stage: build
<<: *start_condition
trigger:
include: ci/gitlab-ci.x86_64.yml
strategy: depend
variables:
PARENT_PIPELINE_ID: $CI_PIPELINE_ID
# Create multi arch manifests and push them do docker hub
build_multi-arch:
stage: deploy
<<: *start_condition
image: docker:23.0.3
services:
- docker:23.0.3-dind
before_script:
# Add dependencies of the tag remove script
- apk add --no-cache bash curl jq
# Login to docker hub
- echo -n $DH_ACCESS_TOKEN | docker login -u "$DH_USERNAME" --password-stdin $DH_URL
script:
# Create multi arch manifest with tag "latest" and push it to docker hub
- docker manifest create ${DH_IMAGE}:latest --amend ${DH_IMAGE}:aarch64-latest --amend ${DH_IMAGE}:x86_64-latest
- docker manifest push --purge ${DH_IMAGE}:latest
# In case the pipeline was started because a new tag was created: Create a
# multi arch manifest with a tag for the new release and push it to docker
# hub
- |
if [[ -n "${CI_COMMIT_TAG}" ]]; then
docker manifest create ${DH_IMAGE}:${CI_COMMIT_TAG#v} --amend ${DH_IMAGE}:aarch64-latest --amend ${DH_IMAGE}:x86_64-latest
docker manifest push --purge ${DH_IMAGE}:${CI_COMMIT_TAG#v}
fi
# In case the pipeline was started by the scheduler: Create a multi arch
# manifest with a tag for the current date and push it to docker hub
- |
if [[ "${CI_PIPELINE_SOURCE}" == "schedule" ]]; then
d=$(date +%Y%m%d)
docker manifest create ${DH_IMAGE}:${d} --amend ${DH_IMAGE}:aarch64-latest --amend ${DH_IMAGE}:x86_64-latest
docker manifest push --purge ${DH_IMAGE}:${d}
fi
# Remove architecture-specific tags from docker hub (they are not required
# anymore, and it is very unlikely that they were referred to since they
# were just created by the build jobs)
- ci/rm_from_docker_hub.sh $DH_USERNAME $DH_PASSWORD $DH_REPO_NAME aarch64-latest x86_64-latest
after_script:
# Logout from docker hub
- docker logout $DH_URL