-
Notifications
You must be signed in to change notification settings - Fork 16
/
.gitlab-ci.yml
443 lines (414 loc) · 17.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
variables:
# Packages versions
# NOTE: when adding variables here update also trigger from mender-qa:
# https://github.com/mendersoftware/mender-qa/blob/master/gitlab-pipeline/stage/trigger-packages.yml
MENDER_VERSION:
value: "master"
description: "Version of mender repository"
MENDER_CONNECT_VERSION:
value: "master"
description: "Version of mender-connect repository"
MENDER_CONFIGURE_VERSION:
value: "master"
description: "Version of mender-configure repository"
MENDER_ARTIFACT_VERSION:
value: "master"
description: "Version of mender-artifact repository"
MENDER_APP_UPDATE_MODULE_VERSION:
value: "master"
description: "Version of mender-app-update-module repository"
MENDER_SETUP_VERSION:
value: "master"
description: "Version of mender-setup repository"
MENDER_SNAPSHOT_VERSION:
value: "master"
description: "Version of mender-snapshot repository"
MENDER_FLASH_VERSION:
value: "master"
description: "Version of mender-flash repository"
MENDER_GATEWAY_VERSION:
value: "master"
description: "Version of mender-gateway repository"
MENDER_MONITOR_VERSION:
value: "master"
description: "Version of monitor-client repository"
# Bucket name
S3_BUCKET_NAME: "mender"
S3_BUCKET_NAME_PRIVATE: "mender-binaries"
# Legacy path for mender-client: <version>/$S3_BUCKET_SUBPATH/...
S3_BUCKET_SUBPATH: "dist-packages/debian"
S3_BUCKET_SUBPATH_GATEWAY: "mender-gateway/debian"
S3_BUCKET_SUBPATH_MONITOR: "mender-monitor/debian"
# APT repo path for incoming packages
S3_BUCKET_REPO_PATH: "repos/debian/incoming"
# Scripts folder subpath
S3_BUCKET_SCRIPTS_PATH: "repos/scripts"
# GPG key for build, to be set by CI/CD variables
GPG_PRIV_KEY_BUILD: ""
TEST_MENDER_DIST_PACKAGES:
value: "true"
options:
- "true"
- "false"
description: "Whether to run acceptance tests"
PUBLISH_MENDER_DIST_PACKAGES_AUTOMATIC:
value: "false"
options:
- "true"
- "false"
description: |-
Whether to publish packages automatically - they can always be published manually
# Workaround for GitLab intermittent networking
FF_NETWORK_PER_BUILD: 1
# Builder image version
IMAGE_VERSION: "master"
# Debian suffix
OVERRIDE_DEBIAN_SUFFIX:
value: ""
description: |-
Overrides Debian suffix, which by default is "-1". Use it to manually build (and publish)
a new version of a package from already released (git tagged) software.
# Don't slow down aws cli commands with connections to IMDS: we're not in AWS
AWS_EC2_METADATA_DISABLED: "true"
# NOTE: To add distributions, modify first the matrix in mender-test-containers repository
.mender-dist-packages-image-matrix:
parallel:
matrix:
- DISTRO: debian
RELEASE: [bullseye, bookworm]
ARCH: [amd64, arm64]
- DISTRO: ubuntu
RELEASE: [focal, jammy, noble]
ARCH: [amd64, armhf, arm64]
.mender-dist-packages-image-matrix-armhf:
parallel:
matrix:
- DISTRO: debian
RELEASE: [bullseye, bookworm]
ARCH: [armhf]
.dind-login: &dind-login
- mkdir -p $HOME/.docker && echo $DOCKER_AUTH_CONFIG > $HOME/.docker/config.json
- docker login --username $CI_REGISTRY_USER --password $CI_REGISTRY_PASSWORD $CI_REGISTRY
include:
- project: 'Northern.tech/Mender/mendertesting'
file: '.gitlab-ci-check-commits-signoffs.yml'
- project: 'Northern.tech/Mender/mendertesting'
file: '.gitlab-ci-check-license.yml'
- project: 'Northern.tech/Mender/mendertesting'
file: '.gitlab-ci-check-python3-format.yml'
- project: 'Northern.tech/Mender/mendertesting'
file: '.gitlab-ci-github-status-updates.yml'
stages:
- build:orig
- build:packages
- test
- publish
build:orig:debian:bullseye:amd64:
stage: build:orig
rules:
- if: $CI_COMMIT_BRANCH == "production"
when: never
- when: on_success
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/docker:26-cli
tags:
- mender-qa-worker-generic
services:
- name: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/docker:26-dind
alias: docker
variables:
DISTRO: "debian"
RELEASE: "bullseye"
ARCH: "amd64"
before_script:
- *dind-login
script:
- apk --update --no-cache add bash
- if [[ "${MENDER_VERSION}" =~ ^3\..* ]]; then
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-client $MENDER_VERSION true
- else
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-client4 $MENDER_VERSION true
- fi
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-connect $MENDER_CONNECT_VERSION true
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-configure $MENDER_CONFIGURE_VERSION true
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-artifact $MENDER_ARTIFACT_VERSION true
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-app-update-module $MENDER_APP_UPDATE_MODULE_VERSION true
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-setup $MENDER_SETUP_VERSION true
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-snapshot $MENDER_SNAPSHOT_VERSION true
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-flash $MENDER_FLASH_VERSION true
- find output -type f
artifacts:
paths:
- output/orig
build:packages:
stage: build:packages
rules:
- if: $CI_COMMIT_BRANCH == "production"
when: never
- when: on_success
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/docker:26-cli
tags:
- hetzner-amd-beefy
services:
- name: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/docker:26-dind
alias: docker
before_script:
- *dind-login
script:
- apk --update --no-cache add bash
- if [[ "${MENDER_VERSION}" =~ ^3\..* ]]; then
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-client $MENDER_VERSION
- else
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-client4 $MENDER_VERSION
- fi
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-connect $MENDER_CONNECT_VERSION
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-configure $MENDER_CONFIGURE_VERSION
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-artifact $MENDER_ARTIFACT_VERSION
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-app-update-module $MENDER_APP_UPDATE_MODULE_VERSION
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-setup $MENDER_SETUP_VERSION
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-snapshot $MENDER_SNAPSHOT_VERSION
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-flash $MENDER_FLASH_VERSION
- if [ -n "${MENDER_PRIVATE_REPO_ACCESS_TOKEN}" ]; then
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-gateway $MENDER_GATEWAY_VERSION
- ./docker-build-package $DISTRO $RELEASE $ARCH mender-monitor $MENDER_MONITOR_VERSION
- fi
- find output -type f
artifacts:
paths:
- output/commercial
- output/opensource
parallel: !reference [.mender-dist-packages-image-matrix, parallel]
build:packages:armhf:
extends: build:packages
tags:
- hetzner-arm
parallel: !reference [.mender-dist-packages-image-matrix-armhf, parallel]
test:check-commits:
only:
variables:
- '$TEST_MENDER_DIST_PACKAGES == "true"'
test:check-license:
rules:
- if: '$TEST_MENDER_DIST_PACKAGES == "true"'
test:check-python3-formatting:
rules:
- if: '$TEST_MENDER_DIST_PACKAGES == "true"'
.test:acceptance:
stage: test
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/docker:dind
tags:
- mender-qa-worker-generic
needs:
# Note that we are only testing packages from Debian bullseye
- "build:packages: [debian, bullseye, amd64]"
- "build:packages:armhf: [debian, bullseye, armhf]"
- "build:packages: [debian, bullseye, arm64]"
variables:
GIT_SUBMODULE_STRATEGY: recursive
before_script:
# DinD setup in Mender CI runners
- unset DOCKER_HOST
- unset DOCKER_TLS_VERIFY
- unset DOCKER_CERT_PATH
# Start dockerd in the background
- /usr/local/bin/dockerd &
# Wait for dockerd to start
- |-
MAX_WAIT=30
while [ ! -e "/var/run/docker.sock" ] && [ $MAX_WAIT -gt 0 ]; do
MAX_WAIT=$(($MAX_WAIT - 1))
sleep 1
done
# Verify that the docker server is up and running
- docker version
# Git submodules
- apk --update --no-cache add git
- git submodule sync --recursive
- git submodule update --init --recursive
# Log in to pull test image from registry.gitlab.com
- echo $CI_REGISTRY_PASSWORD | docker login -u $CI_REGISTRY_USER $CI_REGISTRY --password-stdin
# Install dependencies
- apk --update --no-cache add python3 py3-pip gcc openssh-client make openssl-dev
libffi-dev libc-dev python3-dev bash musl-dev rust cargo
- pip3 install --break-system-packages -r tests/requirements.txt
script:
- cd tests
- REFERENCE_DIST=debian-bullseye-amd64
- |-
commercial_tests_flags=""
if [ -f ${CI_PROJECT_DIR}/output/commercial/${REFERENCE_DIST}/mender-gateway-deb-version ] &&
[ -f ${CI_PROJECT_DIR}/output/commercial/${REFERENCE_DIST}/mender-monitor-deb-version ]; then
commercial_tests_flags="--commercial-tests"
commercial_tests_flags="$commercial_tests_flags --mender-gateway-version $MENDER_GATEWAY_VERSION"
commercial_tests_flags="$commercial_tests_flags --mender-gateway-deb-version $(cat ${CI_PROJECT_DIR}/output/commercial/${REFERENCE_DIST}/mender-gateway-deb-version)"
commercial_tests_flags="$commercial_tests_flags --mender-monitor-version $MENDER_MONITOR_VERSION"
commercial_tests_flags="$commercial_tests_flags --mender-monitor-deb-version $(cat ${CI_PROJECT_DIR}/output/commercial/${REFERENCE_DIST}/mender-monitor-deb-version)"
fi
- python3 -m pytest -v
--mender-client-version $MENDER_VERSION
--mender-client-deb-version $(cat ${CI_PROJECT_DIR}/output/opensource/${REFERENCE_DIST}/mender-client*-deb-version)
--mender-connect-version $MENDER_CONNECT_VERSION
--mender-connect-deb-version $(cat ${CI_PROJECT_DIR}/output/opensource/${REFERENCE_DIST}/mender-connect-deb-version)
--mender-configure-version $MENDER_CONFIGURE_VERSION
--mender-configure-deb-version $(cat ${CI_PROJECT_DIR}/output/opensource/${REFERENCE_DIST}/mender-configure-deb-version)
--mender-artifact-version $MENDER_ARTIFACT_VERSION
--mender-artifact-deb-version $(cat ${CI_PROJECT_DIR}/output/opensource/${REFERENCE_DIST}/mender-artifact-deb-version)
--mender-app-update-module-version $MENDER_APP_UPDATE_MODULE_VERSION
--mender-app-update-module-deb-version $(cat ${CI_PROJECT_DIR}/output/opensource/${REFERENCE_DIST}/mender-app-update-module-deb-version)
--mender-setup-version $MENDER_SETUP_VERSION
--mender-setup-deb-version $(cat ${CI_PROJECT_DIR}/output/opensource/${REFERENCE_DIST}/mender-setup-deb-version)
--mender-snapshot-version $MENDER_SNAPSHOT_VERSION
--mender-snapshot-deb-version $(cat ${CI_PROJECT_DIR}/output/opensource/${REFERENCE_DIST}/mender-snapshot-deb-version)
--mender-flash-version $MENDER_FLASH_VERSION
--mender-flash-deb-version $(cat ${CI_PROJECT_DIR}/output/opensource/${REFERENCE_DIST}/mender-flash-deb-version)
-m "${PYTEST_FILTER}"
${commercial_tests_flags}
--junit-xml results.xml
artifacts:
reports:
junit: tests/results.xml
test:acceptance:golang:
rules:
- if: $CI_COMMIT_BRANCH == "production"
when: never
- if: '$TEST_MENDER_DIST_PACKAGES == "true" && $MENDER_VERSION =~ /^[32]\.[0-9x]+\.[0-9x]+/'
extends: .test:acceptance
variables:
PYTEST_FILTER: "not cppclient"
test:acceptance:cpp:
rules:
- if: $CI_COMMIT_BRANCH == "production"
when: never
- if: '$TEST_MENDER_DIST_PACKAGES == "true" && $MENDER_VERSION =~ /^4\.[0-9x]\.[0-9x]/'
- if: '$TEST_MENDER_DIST_PACKAGES == "true" && $MENDER_VERSION == "master"'
extends: .test:acceptance
variables:
PYTEST_FILTER: "not golangclient"
test:acceptance:script:
rules:
- if: '$TEST_MENDER_DIST_PACKAGES == "true"'
extends: .test:acceptance
needs: []
script:
- cd scripts/tests
- python3 -m pytest -v --junit-xml results.xml
artifacts:
reports:
junit: scripts/tests/results.xml
.publish_helper_functions: &publish_helper_functions |
# Bash function to check if the string is a final tag
function is_final_tag () {
version="$1"
[[ "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] && return 0 || return $?
}
# Bash function to check if the string is a build tag
function is_build_tag () {
version="$1"
[[ "${version}" =~ ^[0-9]+\.[0-9]+\.[0-9]+-build[0-9]+$ ]] && return 0 || return $?
}
.template:publish:s3:apt-repo:
stage: publish
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/debian:12
tags:
- hetzner-amd-beefy
before_script:
- apt update && apt install -yyq awscli
# Lock the bucket to block concurrent jobs
- while aws s3 ls s3://$S3_BUCKET_NAME/$S3_BUCKET_REPO_PATH/lock; do
- rm -f /tmp/lock.in
- aws s3 cp s3://$S3_BUCKET_NAME/$S3_BUCKET_REPO_PATH/lock /tmp/lock.in
- echo "$S3_BUCKET_REPO_PATH locked by:"
- cat /tmp/lock.in
- echo "waiting 10s"
- sleep 10
- done
- rm -f /tmp/lock.in lock
- echo "${CI_PIPELINE_ID}.${CI_PROJECT_NAME}" >> lock
- aws s3 mv lock s3://$S3_BUCKET_NAME/$S3_BUCKET_REPO_PATH/lock
script:
# Upload files: first .buildinfo and .deb, then .changes
- for d in output/opensource/*; do
- find "$d" -name '*.buildinfo' -o -name '*.deb' -o -name '*.ddeb' -o -name '*.orig.tar.*' -o -name '*.debian.tar.*' -o -name '*.dsc' | while read -r file; do
- aws s3 cp "$file" "s3://$S3_BUCKET_NAME/$S3_BUCKET_REPO_PATH/${d}/"
- done
- find "$d" -name '*.changes' | while read -r file; do
- aws s3 cp "$file" "s3://$S3_BUCKET_NAME/$S3_BUCKET_REPO_PATH/${d}/"
- done
- done
after_script:
- apt update && apt install -yyq awscli
- aws s3 rm s3://$S3_BUCKET_NAME/$S3_BUCKET_REPO_PATH/lock
publish:s3:apt-repo:manual:
when: manual
extends: .template:publish:s3:apt-repo
publish:s3:apt-repo:automatic:
rules:
- if: '$PUBLISH_MENDER_DIST_PACKAGES_AUTOMATIC == "true"'
extends: .template:publish:s3:apt-repo
.publish-template:s3:scripts:install-mender-sh:
stage: publish
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/debian:12
before_script:
- apt update && apt install -yyq awscli
only:
changes:
- scripts/install-mender.sh
publish:staging:s3:scripts:install-mender-sh:
extends: .publish-template:s3:scripts:install-mender-sh
script:
- echo "Publishing install-mender.sh to S3 (staging)"
- aws s3 cp scripts/install-mender.sh s3://$S3_BUCKET_NAME/$S3_BUCKET_SCRIPTS_PATH/staging/install-mender.sh --content-type text/plain
- aws s3api put-object-acl --acl public-read --bucket ${S3_BUCKET_NAME} --key ${S3_BUCKET_SCRIPTS_PATH}/staging/install-mender.sh
only:
refs:
- master
publish:production:s3:scripts:install-mender-sh:
extends: .publish-template:s3:scripts:install-mender-sh
script:
- echo "Publishing install-mender.sh to S3 (production)"
- aws s3 cp scripts/install-mender.sh s3://$S3_BUCKET_NAME/$S3_BUCKET_SCRIPTS_PATH/install-mender.sh --content-type text/plain
- aws s3api put-object-acl --acl public-read --bucket ${S3_BUCKET_NAME} --key ${S3_BUCKET_SCRIPTS_PATH}/install-mender.sh
only:
refs:
- production
.template:publish:s3:
stage: publish
image: ${CI_DEPENDENCY_PROXY_DIRECT_GROUP_IMAGE_PREFIX}/debian:12
before_script:
- apt update && apt install -yyq awscli
- *publish_helper_functions
script:
- echo "Publishing ${PUBLISH_PACKAGE_PREFIX} version ${PUBLISH_PACKAGE_VERSION} to s3://${S3_BUCKET_NAME_PRIVATE}/${PUBLISH_PACKAGE_S3_SUBPATH}/${PUBLISH_PACKAGE_VERSION}/"
- find output/commercial -name "${PUBLISH_PACKAGE_PREFIX}*.deb" | while read -r file; do
- aws s3 cp "$file" s3://${S3_BUCKET_NAME_PRIVATE}/${PUBLISH_PACKAGE_S3_SUBPATH}/${PUBLISH_PACKAGE_VERSION}/
# Make copy for "master" to be consumed by get.mender.io script:
- if [ "${PUBLISH_PACKAGE_VERSION}" == "master" ]; then
- copy_filename=$(basename "$file" | sed 's/_[^\+]*/_master-1/; s/\+builder[^_]*//')
- aws s3 cp "$file" s3://${S3_BUCKET_NAME_PRIVATE}/${PUBLISH_PACKAGE_S3_SUBPATH}/${PUBLISH_PACKAGE_VERSION}/${copy_filename}
- fi
- done
.template:publish:s3:mender-monitor:
variables:
PUBLISH_PACKAGE_PREFIX: "mender-monitor"
PUBLISH_PACKAGE_VERSION: "$MENDER_MONITOR_VERSION"
PUBLISH_PACKAGE_S3_SUBPATH: "$S3_BUCKET_SUBPATH_MONITOR"
extends: .template:publish:s3
publish:s3:mender-monitor:manual:
when: manual
extends: .template:publish:s3:mender-monitor
publish:s3:mender-monitor:automatic:
rules:
- if: '$PUBLISH_MENDER_DIST_PACKAGES_AUTOMATIC == "true"'
extends: .template:publish:s3:mender-monitor
.template:publish:s3:mender-gateway:
variables:
PUBLISH_PACKAGE_PREFIX: "mender-gateway"
PUBLISH_PACKAGE_VERSION: "$MENDER_GATEWAY_VERSION"
PUBLISH_PACKAGE_S3_SUBPATH: "$S3_BUCKET_SUBPATH_GATEWAY"
extends: .template:publish:s3
publish:s3:mender-gateway:manual:
when: manual
extends: .template:publish:s3:mender-gateway
publish:s3:mender-gateway:automatic:
rules:
- if: '$PUBLISH_MENDER_DIST_PACKAGES_AUTOMATIC == "true"'
extends: .template:publish:s3:mender-gateway