-
Notifications
You must be signed in to change notification settings - Fork 73
/
.gitlab-ci.yml
210 lines (198 loc) · 8.42 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
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-mariadb-${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 mariadb build:
<<: *build_definition
tags:
- amd64
variables:
ARCH: amd64
PLATFORM: amd64
arm32v7 mariadb build:
<<: *build_definition
tags:
- armhf
variables:
ARCH: armhf
PLATFORM: arm/v7
arm64v8 mariadb 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 mariadb deploy:
<<: *deploy_definition
tags:
- amd64
variables:
ARCH: amd64
ARCH2: x86_64
PLATFORM: amd64
needs:
- amd64 mariadb build
arm32v7 mariadb deploy:
<<: *deploy_definition
tags:
- armhf
variables:
ARCH: armhf
ARCH2: arm32v7
PLATFORM: arm/v7
needs:
- arm32v7 mariadb build
arm64v8 mariadb deploy:
<<: *deploy_definition
tags:
- aarch64
variables:
ARCH: aarch64
ARCH2: arm64v8
PLATFORM: arm64/v8
needs:
- arm64v8 mariadb build
manifest creation latest:
image: yobasystems/alpine-docker:dind
stage: manifest
needs:
- amd64 mariadb deploy
- arm32v7 mariadb deploy
- arm64v8 mariadb deploy
rules:
- if: $CI_COMMIT_TAG
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
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 \
$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
}
- |
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 latest
done
manifest creation version:
image: yobasystems/alpine-docker:dind
stage: manifest
needs:
- manifest creation latest
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 \
$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