-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.gitlab-ci.yml
153 lines (138 loc) · 4.69 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
stages:
- build
- test_prep
- test
- publish
- trigger_prep
- trigger
variables:
GO_VERSION:
description: "The version of the image: `docker.io/library/golang` to use for testing"
value: "1.22.0"
SKOPEO_VERSION:
description: "Version of Docker image `quay.io/skopeo/stable` for publishing images"
value: "v1.13.3"
MULTIPLATFORM_PLATFORMS:
description: "Comma-separated list of targets to build os/arch[/<version>]"
value: "linux/amd64,linux/arm64,linux/arm/v6,linux/arm/v7"
DOCKER_REGISTRY: "docker.io"
DOCKER_REPOSITORY: northerntech/nt-connect
GITHUB_STATUS_API_URL: "https://api.github.com/repos/NorthernTechHQ/$CI_PROJECT_NAME/statuses/$CI_COMMIT_SHA"
include:
- project: 'Northern.tech/Mender/mendertesting'
file: '.gitlab-ci-check-golang-lint.yml'
- project: 'Northern.tech/Mender/mendertesting'
file: '.gitlab-ci-check-golang-unittests-v2.yml'
- project: 'Northern.tech/Mender/mendertesting'
file: '.gitlab-ci-check-commits.yml'
- project: 'Northern.tech/Mender/mendertesting'
file: '.gitlab-ci-check-license.yml'
- project: 'Northern.tech/Mender/mendertesting'
file: '.gitlab-ci-github-status-updates.yml'
- project: 'Northern.tech/Mender/mendertesting'
file: '.gitlab-ci-check-docker-build.yml'
build:docker:
rules:
- when: never
script: ["true"]
build:archive:
image: "golang:${GO_VERSION}"
variables:
GIT_STRATEGY: clone
GIT_DEPTH: 0
stage: build
script:
- export CGO_ENABLED=0
- |-
echo "${MULTIPLATFORM_PLATFORMS}" | \
tr ',' '\n' | tr '/' ' ' | \
while read -r GOOS GOARCH VARIANT; do
export GOOS GOARCH;
if test "${GOARCH}" = "arm"; then
export GOARM="${VARIANT#v}"
fi
make dist
done
artifacts:
paths:
- dist/
publish:docker:
rules:
- when: never
script: ["true"]
publish:image:mender:
rules:
- when: never
script: ["true"]
publish:image-multiplatform:saas:
rules:
- when: never
script: ["true"]
publish:image:saas:
rules:
- when: never
script: ["true"]
trigger:saas:sync-staging-component:
rules:
- when: never
script: ["true"]
build:docker-multiplatform:
rules:
- if: '$CI_COMMIT_REF_NAME =~ /^(main|staging)$/'
when: always
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+)?/'
when: always
- when: manual
allow_failure: true
publish:docker-multiplatform:
rules:
- if: '$CI_COMMIT_REF_NAME =~ /^(main|staging)$/'
when: always
- if: '$CI_COMMIT_TAG =~ /^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z-]+)?/'
when: manual
- when: never
stage: publish
image:
name: "quay.io/skopeo/stable:${SKOPEO_VERSION}"
# https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#override-the-entrypoint-of-an-image
entrypoint: [""]
services: []
before_script:
# Use same variables for loading the image, while DOCKER_PUBLISH_COMMIT_TAG will be ignored
- skopeo login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
- skopeo login -u $DOCKER_HUB_USERNAME -p $DOCKER_HUB_PASSWORD docker.io
script:
- export DOCKER_TAG=$(printf "%s" "${CI_COMMIT_REF_NAME}" | sed -E 's/^v([0-9]+\.[0-9]+\.[0-9]+)/\1/')
- |
if echo "$DOCKER_TAG" | grep -qE '[0-9]+\.[0-9]+\.[0-9]+'; then
# Ref is a semantic version copy a previously published staging version
# Create "x.y.z" tag and update "x.y" and "latest"
major=$(echo "$DOCKER_TAG" | cut -d '.' -f1)
minor=$(echo "$DOCKER_TAG" | cut -d '.' -f2)
skopeo copy --multi-arch all \
"docker://${DOCKER_REPOSITORY}:${CI_COMMIT_SHA}" \
"docker://${DOCKER_REPOSITORY}:${DOCKER_TAG}"
skopeo copy --multi-arch all \
"docker://${DOCKER_REPOSITORY}:${DOCKER_TAG}" \
"docker://${DOCKER_REPOSITORY}:${major}.${minor}"
skopeo copy --multi-arch all \
"docker://${DOCKER_REPOSITORY}:${CI_COMMIT_SHA}" \
"docker://${DOCKER_REPOSITORY}:latest"
else
# Ref is staging or main
# Update "<ref-name>" and "<git-sha>" tags
skopeo copy --multi-arch all \
"docker://${CI_REGISTRY_IMAGE}:${CI_PIPELINE_ID}" \
"docker://${DOCKER_REPOSITORY}:${CI_COMMIT_SHA}"
skopeo copy --multi-arch all \
"docker://${DOCKER_REPOSITORY}:${CI_COMMIT_SHA}" \
"docker://${DOCKER_REPOSITORY}:${CI_COMMIT_REF_NAME}"
fi
artifacts: {}
test:unit:
image: "golang:${GO_VERSION}"
stage: test
before_script:
- apt-get -qq update && apt-get install -yq $(cat deb-requirements.txt)
# start the dbus service
- service dbus start