forked from LINBIT/linstor-operator-builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.gitlab-ci.yml
289 lines (274 loc) · 10.5 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
stages:
- prepare
- build
- build_olm
- test
- deploy
variables:
GIT_SUBMODULE_STRATEGY: recursive
VIRTER_VERSION: v0.25.0
VMSHED_VERSION: v0.20.1
K8S_TEST_VERSION: v2.5.0
# Upstream uses a newer version. This is fine, as we only use this version for building the CSV.
# Newer versions do not support "operator-sdk generate csv"
OPERATOR_SDK_VERSION: v0.18.0
OPM_VERSION: v1.15.3
HELM_VERSION: v3.4.1
CRANE_VERSION: v0.8.0
YQ_VERSION: 3.3.4
JQ_VERSION: "1.6"
prepare-version:
image: python:3
stage: prepare
rules:
- if: $CI_COMMIT_TAG
- if: $CI_MERGE_REQUEST_ID
- if: $CI_COMMIT_BRANCH == 'master'
variables:
# git describe needs full history access
GIT_DEPTH: 0
# git describe does not need the submodule
GIT_SUBMODULE_STRATEGY: none
script:
- SEMVER=$(hack/getsemver.py)
- echo "SEMVER=${SEMVER}" >> .ci-build.env
- echo "TAG=v${SEMVER/+/-}" >> .ci-build.env
artifacts:
reports:
dotenv: .ci-build.env
prepare-bins:
image: ${BUILD_HELPER_IMAGE}
stage: prepare
rules:
- if: $CI_COMMIT_TAG
- if: $CI_MERGE_REQUEST_ID
- if: $CI_COMMIT_BRANCH == 'master'
script:
- . /usr/local/bin/gitlab-utils.sh
- ci_prepare_tools
- ci_fetch_binary virter virter-$VIRTER_VERSION https://github.com/LINBIT/virter/releases/download/$VIRTER_VERSION/virter-linux-amd64
- ci_fetch_binary vmshed vmshed-$VMSHED_VERSION https://github.com/LINBIT/vmshed/releases/download/$VMSHED_VERSION/vmshed-linux-amd64
- ci_fetch_binary create-k8s-test-configs create-k8s-test-configs-$K8S_TEST_VERSION $LINBIT_REGISTRY_URL/repository/tools/create-k8s-test-configs:$K8S_TEST_VERSION
- ci_fetch_binary operator-sdk operator-sdk-$OPERATOR_SDK_VERSION https://github.com/operator-framework/operator-sdk/releases/download/$OPERATOR_SDK_VERSION/operator-sdk-$OPERATOR_SDK_VERSION-x86_64-linux-gnu
- ci_fetch_binary opm opm-$OPM_VERSION https://github.com/operator-framework/operator-registry/releases/download/$OPM_VERSION/linux-amd64-opm
- ci_fetch_binary yq yq-$YQ_VERSION https://github.com/mikefarah/yq/releases/download/$YQ_VERSION/yq_linux_amd64
- ci_fetch_binary jq jq-$JQ_VERSION https://github.com/stedolan/jq/releases/download/jq-$JQ_VERSION/jq-linux64
- ci_fetch_tar helm-$HELM_VERSION https://get.helm.sh/helm-$HELM_VERSION-linux-amd64.tar.gz -z
- ci_fetch_tar crane-$CRANE_VERSION https://github.com/google/go-containerregistry/releases/download/$CRANE_VERSION/go-containerregistry_Linux_x86_64.tar.gz -z
cache:
key: $VIRTER_VERSION-$VMSHED_VERSION-$K8S_TEST_VERSION-$OPERATOR_SDK_VERSION-$OPM_VERSION-$YQ_VERSION-$JQ_VERSION-$HELM_VERSION-$CRANE_VERSION
paths:
- download
artifacts:
paths:
- bin
- download
prepare-tools:
tags:
- docker
- amd64
stage: prepare
rules:
- if: $CI_MERGE_REQUEST_ID
when: manual
allow_failure: true
- if: $CI_COMMIT_BRANCH == 'master'
when: manual
allow_failure: true
script:
- ln -snf $DOCKER_AUTH_CONFIG_FILE $HOME/.docker/config.json
- docker build -f .gitlab/Dockerfile.operator-sdk-tools -t $LINBIT_DOCKER_REGISTRY/linstor-operator-test/operator-sdk:latest .gitlab
- docker push $LINBIT_DOCKER_REGISTRY/linstor-operator-test/operator-sdk:latest
build_chart:
rules:
- if: $CI_COMMIT_TAG
- if: $CI_MERGE_REQUEST_ID
- if: $CI_COMMIT_BRANCH == 'master'
stage: build
script:
- export "PATH=$PWD/bin:$PATH"
- helm repo add linstor https://charts.linstor.io
- make chart SEMVER=$SEMVER
- curl --fail --user $LINBIT_REGISTRY_USER:$LINBIT_REGISTRY_PASSWORD --upload-file out/helm/linstor-$SEMVER.tgz $LINBIT_REGISTRY_HELM/
tags:
- shell
build_operator:
rules:
- if: $CI_COMMIT_TAG
- if: $CI_MERGE_REQUEST_ID
- if: $CI_COMMIT_BRANCH == 'master'
stage: build
# https://github.com/containerd/containerd/issues/5978
retry: 1
script:
- export "PATH=$PWD/bin:$PATH"
- if [ -n "$CI_COMMIT_TAG" ]; then NOCACHE=true ; else NOCACHE=false ; fi
- TARGET=$LINBIT_DOCKER_REGISTRY/linstor-operator-test/linstor-operator:$TAG
- ln -snf $DOCKER_AUTH_CONFIG_FILE $HOME/.docker/config.json
- make linstor-operator
- docker buildx build --pull --push --platform $PUBLISH_PLATFORMS -t $TARGET linstor-operator --no-cache=$NOCACHE
- echo "OPERATOR_IMAGE=$LINBIT_DOCKER_REGISTRY/linstor-operator-test/linstor-operator:$TAG" > .build.env
artifacts:
reports:
dotenv:
- .build.env
tags:
- multiarch
build_olm:
rules:
- if: $CI_COMMIT_TAG
- if: $CI_MERGE_REQUEST_ID
- if: $CI_COMMIT_BRANCH == 'master'
stage: build_olm
script:
- export "PATH=$PWD/bin:$PATH"
- ln -snf $DOCKER_AUTH_CONFIG_FILE $HOME/.docker/config.json
- helm repo add linstor https://charts.linstor.io
- make olm SEMVER=$SEMVER OLM_REGISTRY=$LINBIT_DOCKER_REGISTRY/linstor-operator-test
- docker build -t $LINBIT_DOCKER_REGISTRY/linstor-operator-test/linstor-operator-bundle:$TAG out/olm-bundle/$SEMVER/
- docker push $LINBIT_DOCKER_REGISTRY/linstor-operator-test/linstor-operator-bundle:$TAG
- opm index add --permissive --mode semver --build-tool docker --from-index $LINBIT_DOCKER_REGISTRY/linstor-operator-test/catalog:latest --bundles $LINBIT_DOCKER_REGISTRY/linstor-operator-test/linstor-operator-bundle:$TAG --tag $LINBIT_DOCKER_REGISTRY/linstor-operator-test/catalog:latest --bundles $LINBIT_DOCKER_REGISTRY/linstor-operator-test/linstor-operator-bundle:$TAG --tag $LINBIT_DOCKER_REGISTRY/linstor-operator-test/catalog:latest
- docker push $LINBIT_DOCKER_REGISTRY/linstor-operator-test/catalog:latest
tags:
- docker
deploy_olm:
rules:
- if: $CI_COMMIT_TAG
- if: $CI_MERGE_REQUEST_ID
- if: $CI_COMMIT_BRANCH == 'master'
stage: test
image: $LINBIT_DOCKER_REGISTRY/linstor-operator-test/operator-sdk:latest
script:
- operator-sdk bundle validate --verbose --image-builder none $LINBIT_DOCKER_REGISTRY/linstor-operator-test/linstor-operator-bundle:$TAG
dependencies:
# Explicitly: do not depend on prepare-bins, we want out own version of operator-sdk
- build_olm
- prepare-version
.test:
stage: test
tags:
- libvirt
allow_failure: true
script:
- export PATH=$CI_PROJECT_DIR/bin:$PATH
- create-k8s-test-configs -stable-releases-to-check=4 -include-next=1 -base-image=alma-9
- cp test-helm-config.yaml virter/operator-to-test.yml
- cd virter
- yq write --inplace operator-to-test.yml 'operator.image' "$OPERATOR_IMAGE"
- >
vmshed
--pull-template "${LINBIT_DOCKER_REGISTRY}/vm/{{ .Image }}:latest"
--nvms $(( ${LINBIT_CI_MAX_CPUS:-20} / 3 ))
--torun $TO_RUN
--variant "$VARIANT"
--set values.DockerRegistryMirror=https://${DOCKER_REGISTRY_MIRROR}
--set values.DrbdRegistryMirror=https://${DRBD_REGISTRY_MIRROR}
--set values.K8sGcrIoMirror=https://${K8S_REGISTRY_MIRROR}
--set values.RegistryK8sIoMirror=https://${REGISTRY_K8S_IO_MIRROR}
--set values.DrbdIoUser=$PUBLISH_REGISTRY_USER
--set values.DrbdIoPassword=$PUBLISH_REGISTRY_PASSWORD
--set values.JustKubeadmImage=$LINBIT_DOCKER_REGISTRY/linstor-kubernetes-tests/just-kubeadm:$K8S_TEST_VERSION
--set values.HelmImage=$LINBIT_DOCKER_REGISTRY/linstor-kubernetes-tests/helm:$K8S_TEST_VERSION
--set values.TestImage=$LINBIT_DOCKER_REGISTRY/linstor-kubernetes-tests/tests:$K8S_TEST_VERSION
--set values.HelmLinstorRepo=$LINBIT_REGISTRY_HELM
--set values.HelmLinstorVersion=$SEMVER
--set "values.Skip=$SKIP"
--set "values.Focus=$FOCUS"
--set values.LinstorValues=/virter/workspace/operator-to-test.yml
artifacts:
when: always
paths:
- virter/
reports:
junit:
- virter/tests-out/test-results/*.xml
- virter/tests-out/log/**/*-report.xml
test-chart:
extends: .test
rules:
- if: $CI_COMMIT_TAG
- if: $CI_MERGE_REQUEST_ID
- if: $CI_COMMIT_BRANCH == 'master'
stage: test
tags:
- libvirt
timeout: 30m
variables:
TO_RUN: chart,operator
VARIANT: "k8s-backend,etcd-backend,no-helm-install"
test-e2e:
extends: .test
rules:
- if: $CI_COMMIT_TAG
when: manual
- if: $CI_MERGE_REQUEST_ID
when: manual
- if: $CI_COMMIT_BRANCH == 'master'
when: manual
stage: test
tags:
- libvirt
timeout: 4h
variables:
TO_RUN: k8s-e2e-storage
SKIP: "Slow|LinuxOnly|xfs|ext3|ext4|immediate-binding|retain policy|readOnly|read-only|exec|multiple|subPath"
container_scanning:
stage: test
rules:
- if: $CI_MERGE_REQUEST_ID
- if: $CI_COMMIT_BRANCH == 'master'
- if: $CI_COMMIT_TAG
image:
name: docker.io/aquasec/trivy:latest
entrypoint: [""]
script:
- trivy --version
- trivy image --exit-code 0 --format template --template "@/contrib/html.tpl" -o container-scan.html "$OPERATOR_IMAGE"
# Prints full report
- trivy image --exit-code 0 "$OPERATOR_IMAGE"
# Fail on critical (unfixed) vulnerabilities
- trivy image --exit-code 1 --ignore-unfixed --severity CRITICAL "$OPERATOR_IMAGE"
# Ideally, we would use container_scanning for the artifact here. That is currently a paid feature, so we have to use code quality
artifacts:
when: always
expose_as: "Container Scan"
paths:
- container-scan.html
publish-image:
stage: deploy
rules:
- if: $CI_COMMIT_TAG
- if: $CI_MERGE_REQUEST_ID
when: manual
allow_failure: true
image:
# Wait for https://github.com/google/go-containerregistry/issues/1183 before upgrading
name: gcr.io/go-containerregistry/crane/debug:v0.7.0
entrypoint: [ "" ]
script:
- mkdir -p $HOME/.docker
- ln -snf $DOCKER_PUBLISH_AUTH_CONFIG_FILE $HOME/.docker/config.json
- for PLATFORM in $(echo $PUBLISH_PLATFORMS | tr ',' '\n') ; do
- ARCH=${PLATFORM#*/}
- crane copy --platform $PLATFORM $OPERATOR_IMAGE $PUBLISH_REGISTRY/$ARCH/linstor-operator:$TAG
- crane tag $PUBLISH_REGISTRY/$ARCH/linstor-operator:$TAG latest
- done
publish-chart:
stage: deploy
rules:
- if: $CI_COMMIT_TAG
- if: $CI_MERGE_REQUEST_ID
when: manual
allow_failure: true
script:
- export "PATH=$PWD/bin:$PATH"
- eval $(ssh-agent -s)
- trap 'ssh-agent -k' EXIT
- cat $GITHUB_DEPLOY_KEY | ssh-add -
- export GIT_AUTHOR_NAME="LinbitPRBot"
- export GIT_COMMITTER_NAME="LinbitPRBot"
- export GIT_AUTHOR_EMAIL="linbitprbot@users.noreply.github.com"
- export GIT_COMMITTER_EMAIL="linbitprbot@users.noreply.github.com"
- make publish SEMVER=$SEMVER UPSTREAMGIT=git@github.com:LINBIT/linstor-operator-builder.git
tags:
- shell