-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.gitlab-ci.yml
127 lines (122 loc) · 4.15 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
.before-script-build: &before-script-build
- |
if [[ ! -z "$CI_BUILD_PLATFORMS" ]]; then
export OS_ARCH=`echo $CI_BUILD_PLATFORMS | tr ' ' '\n' | \
sed 's|\/||2' | sed 's|\/|-|' | tr '\n' ' '`
fi
- export CI_APP_REPO=${CI_APP_REPO:-$CI_REGISTRY_IMAGE}
- >
echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER
--password-stdin $CI_REGISTRY
- |
if [[ -z "$R_VERSION" ]]; then
export R_VERSION=`sed -n "s|^R_VERSION=\(.*\)|\1|p" sample..env`
fi
.build:
image: glcr.b-data.ch/docker/docker:dind
stage: build
services:
- name: glcr.b-data.ch/docker/docker:dind
alias: docker
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: "/certs"
BUILDX_NO_DEFAULT_ATTESTATIONS: "true"
before_script:
- *before-script-build
build:version-linux-amd64:
extends: .build
tags:
- arch:amd64
- os:linux
script:
- >
docker build
--build-arg IMAGE
--build-arg R_VERSION
-t $CI_APP_REPO/$R_VERSION/$IMAGE-linux-amd64
-f build.Dockerfile .
- docker push $CI_APP_REPO/$R_VERSION/$IMAGE-linux-amd64
- |
if [[ "$TAG_LATEST" == "true" ]]; then
docker tag $CI_APP_REPO/$R_VERSION/$IMAGE-linux-amd64 \
$CI_APP_REPO/latest/$IMAGE-linux-amd64
docker push $CI_APP_REPO/latest/$IMAGE-linux-amd64
fi
rules:
- if: $CI_COMMIT_BRANCH == "main" && $CI_BUILD_PLATFORMS =~ /(linux\/amd64)/
changes:
- build.Dockerfile
- sample..env
build:version-linux-arm64v8:
extends: .build
tags:
- arch:arm64/v8
- os:linux
script:
- >
docker build
--build-arg IMAGE
--build-arg R_VERSION
-t $CI_APP_REPO/$R_VERSION/$IMAGE-linux-arm64v8
-f build.Dockerfile .
- docker push $CI_APP_REPO/$R_VERSION/$IMAGE-linux-arm64v8
- |
if [[ "$TAG_LATEST" == "true" ]]; then
docker tag $CI_APP_REPO/$R_VERSION/$IMAGE-linux-arm64v8 \
$CI_APP_REPO/latest/$IMAGE-linux-arm64v8
docker push $CI_APP_REPO/latest/$IMAGE-linux-arm64v8
fi
rules:
- if: $CI_COMMIT_BRANCH == "main" && $CI_BUILD_PLATFORMS =~ /(linux\/arm64\/v8)/
changes:
- build.Dockerfile
- sample..env
build-manifest:version-linux-multiarch:
extends: .build
needs: ["build:version-linux-amd64", "build:version-linux-arm64v8"]
script:
- |
for i in $OS_ARCH; do
export CI_MANIFEST_LIST="$CI_MANIFEST_LIST $CI_APP_REPO/$R_VERSION/$IMAGE-$i"
done
- |
docker manifest create $CI_APP_REPO/$R_VERSION/$IMAGE $CI_MANIFEST_LIST
if echo $OS_ARCH | grep "linux-arm64v8" >/dev/null ; then
docker manifest annotate --variant v8 $CI_APP_REPO/$R_VERSION/$IMAGE \
$CI_APP_REPO/$R_VERSION/$IMAGE-linux-arm64v8
fi
docker manifest push $CI_APP_REPO/$R_VERSION/$IMAGE
- |
if [[ "$TAG_LATEST" == "true" ]]; then
docker manifest create $CI_APP_REPO/latest/$IMAGE $CI_MANIFEST_LIST
if echo $OS_ARCH | grep "linux-arm64v8" >/dev/null ; then
docker manifest annotate --variant v8 $CI_APP_REPO/latest/$IMAGE \
$CI_APP_REPO/$R_VERSION/$IMAGE-linux-arm64v8
fi
docker manifest push $CI_APP_REPO/latest/$IMAGE
fi
- |
if [[ ! -z "$ADD_IMAGES" ]]; then
for i in $ADD_IMAGES; do
docker manifest create $CI_APP_REPO/$R_VERSION/$i $CI_MANIFEST_LIST
if echo $OS_ARCH | grep "linux-arm64v8" >/dev/null ; then
docker manifest annotate --variant v8 $CI_APP_REPO/$R_VERSION/$i \
$CI_APP_REPO/$R_VERSION/$IMAGE-linux-arm64v8
fi
docker manifest push $CI_APP_REPO/$R_VERSION/$i
if [[ "$TAG_LATEST" == "true" ]]; then
docker manifest create $CI_APP_REPO/latest/$i $CI_MANIFEST_LIST
if echo $OS_ARCH | grep "linux-arm64v8" >/dev/null ; then
docker manifest annotate --variant v8 $CI_APP_REPO/latest/$i \
$CI_APP_REPO/$R_VERSION/$IMAGE-linux-arm64v8
fi
docker manifest push $CI_APP_REPO/latest/$i
fi
done
fi
rules:
- if: $CI_COMMIT_BRANCH == "main"
changes:
- build.Dockerfile
- sample..env