-
Notifications
You must be signed in to change notification settings - Fork 15
/
docker-ros.yml
335 lines (308 loc) · 12.5 KB
/
docker-ros.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
workflow:
rules:
- if: $CI_PIPELINE_SOURCE == "parent_pipeline" # run child pipeline if triggered by parent pipeline
- if: $CI_PIPELINE_SOURCE == "merge_request_event" # run merge request pipeline if triggered by merge request
- if: $CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS # don't run branch pipeline if open merge request exists
when: never
- if: $CI_COMMIT_BRANCH # run branch pipeline if triggered by commit
- if: $CI_COMMIT_TAG # run tag pipeline with specific image tags if triggered by tag
variables:
TARGET: run # Target stage of Dockerfile (comma-separated list) [dev|run]
PLATFORM: amd64 # Target platform architecture (comma-separated list) [amd64|arm64|...]
BASE_IMAGE: '' # Base image name:tag (required)
COMMAND: '' # Launch command of run image (required if target=run)
IMAGE_NAME: ${CI_REGISTRY_IMAGE} # Image name of run image
IMAGE_TAG: latest # Image tag of run image
DEV_IMAGE_NAME: ${IMAGE_NAME} # Image name of dev image
DEV_IMAGE_TAG: ${IMAGE_TAG}-dev # Image tag of dev image
BUILD_CONTEXT: . # Build context of Docker build process
REGISTRY: ${CI_REGISTRY} # Docker registry to push images to
REGISTRY_USER: ${CI_REGISTRY_USER} # Docker registry username
REGISTRY_PASSWORD: ${CI_REGISTRY_PASSWORD} # Docker registry password
ENABLE_INDUSTRIAL_CI: 'false' # Enable industrial_ci
ENABLE_SINGLEARCH_PUSH: 'false' # Enable push of single arch images with [-amd64|-arm64] postfix
ENABLE_PUSH_AS_LATEST: 'false' # Push images with tag `latest`/`latest-dev` in addition to the configured image names
ROS_DISTRO: '' # ROS Distro (required if ROS is not installed in `base-image`)
GIT_HTTPS_SERVER: ${CI_SERVER_HOST} # Server URL (without protocol) for cloning private Git repositories via HTTPS
GIT_HTTPS_USER: gitlab-ci-token # Username for cloning private Git repositories via HTTPS
GIT_HTTPS_PASSWORD: ${CI_JOB_TOKEN} # Password for cloning private Git repositories via HTTPS
GIT_SSH_PRIVATE_KEY: '' # SSH private key for cloning private Git repositories via SSH
GIT_SSH_KNOWN_HOST_KEYS: '' # Known SSH host keys for cloning private Git repositories via SSH (may be obtained using `ssh-keyscan`)
ADDITIONAL_DEBS_FILE: docker/additional-debs.txt # Relative filepath to file containing additional apt deb packages to install
ENABLE_RECURSIVE_ADDITIONAL_DEBS: 'false' # Enable recursive discovery of files named `additional-debs-file`
ADDITIONAL_FILES_DIR: docker/additional-files # Relative path to directory containing additional files to copy into image"
ADDITIONAL_PIP_FILE: docker/additional-pip-requirements.txt # Relative filepath to file containing additional pip packages to install
ENABLE_RECURSIVE_ADDITIONAL_PIP: 'false' # Enable recursive discovery of files named `additional-pip-file`
CUSTOM_SCRIPT_FILE: docker/custom.sh # Relative filepath to script containing custom installation commands
ENABLE_RECURSIVE_CUSTOM_SCRIPT: 'false' # Enable recursive discovery of files named `custom-script-file`
# -----
DOCKER_ROS_GIT_REF: main
_RUN_IMAGE: ${IMAGE_NAME}:${IMAGE_TAG}
_DEV_IMAGE: ${DEV_IMAGE_NAME}:${DEV_IMAGE_TAG}
_IMAGE_DEV_CI: ${_DEV_IMAGE}_${CI_COMMIT_REF_SLUG}_ci
_IMAGE_RUN_CI: ${_RUN_IMAGE}_${CI_COMMIT_REF_SLUG}_ci
_IMAGE_DEV_CI_AMD64: ${_IMAGE_DEV_CI}-amd64
_IMAGE_DEV_CI_ARM64: ${_IMAGE_DEV_CI}-arm64
_IMAGE_RUN_CI_AMD64: ${_IMAGE_RUN_CI}-amd64
_IMAGE_RUN_CI_ARM64: ${_IMAGE_RUN_CI}-arm64
_IMAGE_DEV_LATEST: ${DEV_IMAGE_NAME}:latest-dev
_IMAGE_RUN_LATEST: ${IMAGE_NAME}:latest
_IMAGE_DEV_TARGET_TAG: ${_DEV_IMAGE}-${CI_COMMIT_TAG}
_IMAGE_RUN_TARGET_TAG: ${_RUN_IMAGE}-${CI_COMMIT_TAG}
_IMAGE_DEV_TAG: ${DEV_IMAGE_NAME}:${CI_COMMIT_TAG}-dev
_IMAGE_RUN_TAG: ${IMAGE_NAME}:${CI_COMMIT_TAG}
GIT_SUBMODULE_STRATEGY: recursive
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: /certs
DOCKER_BUILDKIT: 1
stages:
- Build dev Images
- Build run Images
- Test ROS Industrial CI
- Push Multi-Arch Images
default:
image: docker:20.10.22-git
services:
- docker:20.10.22-dind
tags:
- privileged
- amd64
before_script:
- echo -e "section_start:`date +%s`:setup_section[collapsed=true]\r\e[0K[docker-ros] Setup docker-ros"
- apk add bash
- cd ${BUILD_CONTEXT}
- |-
if [[ ! -d docker/docker-ros ]]; then
mkdir -p docker
git clone --depth=1 https://github.com/ika-rwth-aachen/docker-ros.git docker/docker-ros
cd docker/docker-ros
git fetch origin ${DOCKER_ROS_GIT_REF}
git checkout FETCH_HEAD
cd -
fi
- docker login -u ${REGISTRY_USER} -p ${REGISTRY_PASSWORD} ${REGISTRY}
- docker context create buildx-context
- docker buildx create --use buildx-context
- echo -e "section_end:`date +%s`:setup_section\r\e[0K"
.build:
script:
- |-
if [[ ${CI_RUNNER_EXECUTABLE_ARCH} != ${_PLATFORM} && ${CI_RUNNER_EXECUTABLE_ARCH} != linux/${_PLATFORM} ]]; then
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
fi
TARGET=${_TARGET} PLATFORM=${_PLATFORM} ./docker/docker-ros/scripts/ci.sh
echo -e "section_start:`date +%s`:push_section[collapsed=true]\r\e[0K[docker-ros] Push ${IMAGE}"
docker push ${IMAGE}
echo -e "section_end:`date +%s`:push_section\r\e[0K"
dev-amd64:
stage: Build dev Images
extends: .build
rules:
- if: $PLATFORM =~ /.*amd64.*/ && $TARGET =~ /.*dev.*/
variables:
_PLATFORM: amd64
_TARGET: dev
IMAGE: ${_IMAGE_DEV_CI_AMD64}
ENABLE_SINGLEARCH_PUSH: 'true'
_IMAGE_POSTFIX: _${CI_COMMIT_REF_SLUG}_ci
dev-arm64:
stage: Build dev Images
extends: .build
tags: [privileged, arm64]
rules:
- if: $PLATFORM =~ /.*arm64.*/ && $TARGET =~ /.*dev.*/
variables:
_PLATFORM: arm64
_TARGET: dev
IMAGE: ${_IMAGE_DEV_CI_ARM64}
ENABLE_SINGLEARCH_PUSH: 'true'
_IMAGE_POSTFIX: _${CI_COMMIT_REF_SLUG}_ci
run-amd64:
stage: Build run Images
extends: .build
needs:
- job: dev-amd64
optional: true
rules:
- if: $PLATFORM =~ /.*amd64.*/ && $TARGET =~ /.*run.*/
variables:
_PLATFORM: amd64
_TARGET: run
IMAGE: ${_IMAGE_RUN_CI_AMD64}
ENABLE_SINGLEARCH_PUSH: 'true'
_IMAGE_POSTFIX: _${CI_COMMIT_REF_SLUG}_ci
run-arm64:
stage: Build run Images
extends: .build
tags: [privileged, arm64]
needs:
- job: dev-arm64
optional: true
rules:
- if: $PLATFORM =~ /.*arm64.*/ && $TARGET =~ /.*run.*/
variables:
_PLATFORM: arm64
_TARGET: run
IMAGE: ${_IMAGE_RUN_CI_ARM64}
ENABLE_SINGLEARCH_PUSH: 'true'
_IMAGE_POSTFIX: _${CI_COMMIT_REF_SLUG}_ci
.test:
variables:
UPSTREAM_WORKSPACE: ${BUILD_CONTEXT}/.repos
TARGET_WORKSPACE: ${BUILD_CONTEXT}
ADDITIONAL_DEBS: git
AFTER_INIT_EMBED: git config --global url.https://${GIT_HTTPS_USER}:${GIT_HTTPS_PASSWORD}@${GIT_HTTPS_SERVER}.insteadOf https://${GIT_HTTPS_SERVER}
DOCKER_RUN_OPTS: -u root:root
before_script:
- docker login -u ${REGISTRY_USER} -p ${REGISTRY_PASSWORD} ${REGISTRY}
- apk add --update bash coreutils grep tar
- |-
if [[ ${CI_RUNNER_EXECUTABLE_ARCH} != ${_PLATFORM} && ${CI_RUNNER_EXECUTABLE_ARCH} != linux/${_PLATFORM} ]]; then
docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
fi
- git clone --branch master --depth 1 https://github.com/ros-industrial/industrial_ci.git .industrial_ci
- test -f ${BUILD_CONTEXT}/.repos || echo "repositories:" > ${BUILD_CONTEXT}/.repos
script: .industrial_ci/gitlab.sh
Test dev-amd64:
stage: Test ROS Industrial CI
extends: .test
needs:
- job: dev-amd64
rules:
- if: $ENABLE_INDUSTRIAL_CI == 'true' && $PLATFORM =~ /.*amd64.*/ && $TARGET =~ /.*dev.*/
variables:
DOCKER_IMAGE: ${_IMAGE_DEV_CI_AMD64}
_PLATFORM: amd64
Test dev-arm64:
stage: Test ROS Industrial CI
extends: .test
tags: [privileged, arm64]
needs:
- job: dev-arm64
rules:
- if: $ENABLE_INDUSTRIAL_CI == 'true' && $PLATFORM =~ /.*arm64.*/ && $TARGET =~ /.*dev.*/
variables:
DOCKER_IMAGE: ${_IMAGE_DEV_CI_ARM64}
_PLATFORM: arm64
Test run-amd64:
stage: Test ROS Industrial CI
extends: .test
needs:
- job: run-amd64
rules:
- if: $ENABLE_INDUSTRIAL_CI == 'true' && $PLATFORM =~ /.*amd64.*/ && $TARGET !~ /.*dev.*/
variables:
DOCKER_IMAGE: ${_IMAGE_RUN_CI_AMD64}
_PLATFORM: amd64
Test run-arm64:
stage: Test ROS Industrial CI
extends: .test
needs:
- job: run-arm64
rules:
- if: $ENABLE_INDUSTRIAL_CI == 'true' && $PLATFORM =~ /.*arm64.*/ && $TARGET !~ /.*dev.*/
variables:
DOCKER_IMAGE: ${_IMAGE_RUN_CI_ARM64}
_PLATFORM: arm64
.push:
needs:
- job: dev-amd64
optional: true
- job: dev-arm64
optional: true
- job: run-amd64
optional: true
- job: run-arm64
optional: true
- job: Test dev-amd64
optional: true
- job: Test dev-arm64
optional: true
- job: Test run-amd64
optional: true
- job: Test run-arm64
optional: true
rules:
- if: $PLATFORM == '' || $TARGET == ''
when: never
script:
- |-
if [[ "${PLATFORM}" =~ amd64 && "${PLATFORM}" =~ arm64 ]]; then
if [[ "${TARGET}" =~ dev ]]; then
docker manifest create ${IMG_DEV} --amend ${_IMAGE_DEV_CI_AMD64} --amend ${_IMAGE_DEV_CI_ARM64}
docker manifest push ${IMG_DEV}
fi
if [[ "${TARGET}" =~ run ]]; then
docker manifest create ${IMG_RUN} --amend ${_IMAGE_RUN_CI_AMD64} --amend ${_IMAGE_RUN_CI_ARM64}
docker manifest push ${IMG_RUN}
fi
elif [[ "${PLATFORM}" =~ amd64 ]]; then
if [[ "${TARGET}" =~ dev ]]; then
docker pull ${_IMAGE_DEV_CI_AMD64}
docker tag ${_IMAGE_DEV_CI_AMD64} ${IMG_DEV}
docker push ${IMG_DEV}
fi
if [[ "${TARGET}" =~ run ]]; then
docker pull ${_IMAGE_RUN_CI_AMD64}
docker tag ${_IMAGE_RUN_CI_AMD64} ${IMG_RUN}
docker push ${IMG_RUN}
fi
elif [[ "${PLATFORM}" =~ arm64 ]]; then
if [[ "${TARGET}" =~ dev ]]; then
docker pull ${_IMAGE_DEV_CI_ARM64}
docker tag ${_IMAGE_DEV_CI_ARM64} ${IMG_DEV}
docker push ${IMG_DEV}
fi
if [[ "${TARGET}" =~ run ]]; then
docker pull ${_IMAGE_RUN_CI_ARM64}
docker tag ${_IMAGE_RUN_CI_ARM64} ${IMG_RUN}
docker push ${IMG_RUN}
fi
fi
Push CI:
stage: Push Multi-Arch Images
extends: .push
rules:
- !reference [.push, rules]
- if: $CI_COMMIT_TAG
when: never
- if: $CI_COMMIT_BRANCH != $CI_DEFAULT_BRANCH
variables:
IMG_DEV: ${_IMAGE_DEV_CI}
IMG_RUN: ${_IMAGE_RUN_CI}
Push:
stage: Push Multi-Arch Images
extends: .push
rules:
- !reference [.push, rules]
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
variables:
IMG_DEV: ${_DEV_IMAGE}
IMG_RUN: ${_RUN_IMAGE}
Push latest:
stage: Push Multi-Arch Images
extends: .push
rules:
- !reference [.push, rules]
- if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $ENABLE_PUSH_AS_LATEST == 'true'
variables:
IMG_DEV: ${_IMAGE_DEV_LATEST}
IMG_RUN: ${_IMAGE_RUN_LATEST}
Push target tag:
stage: Push Multi-Arch Images
extends: .push
rules:
- !reference [.push, rules]
- if: $CI_COMMIT_TAG
variables:
IMG_DEV: ${_IMAGE_DEV_TARGET_TAG}
IMG_RUN: ${_IMAGE_RUN_TARGET_TAG}
Push tag:
stage: Push Multi-Arch Images
extends: .push
rules:
- !reference [.push, rules]
- if: $CI_COMMIT_TAG && $ENABLE_PUSH_AS_LATEST == 'true'
variables:
IMG_DEV: ${_IMAGE_DEV_TAG}
IMG_RUN: ${_IMAGE_RUN_TAG}