From 091508d470d7fab0bd304e79098f6af66cfa8613 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Busch Date: Tue, 13 Jun 2023 18:27:54 +0200 Subject: [PATCH 1/8] rm command variable from job --- .gitlab-ci/docker-ros.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitlab-ci/docker-ros.yml b/.gitlab-ci/docker-ros.yml index 5b84159..d1f4bab 100644 --- a/.gitlab-ci/docker-ros.yml +++ b/.gitlab-ci/docker-ros.yml @@ -141,7 +141,6 @@ run-amd64: variables: _PLATFORM: amd64 _TARGET: run - COMMAND: ${COMMAND} IMAGE: ${_IMAGE_RUN_CI_AMD64} ENABLE_SINGLEARCH_PUSH: 'true' _IMAGE_POSTFIX: _${CI_COMMIT_REF_SLUG}_ci @@ -158,7 +157,6 @@ run-arm64: variables: _PLATFORM: arm64 _TARGET: run - COMMAND: ${COMMAND} IMAGE: ${_IMAGE_RUN_CI_ARM64} ENABLE_SINGLEARCH_PUSH: 'true' _IMAGE_POSTFIX: _${CI_COMMIT_REF_SLUG}_ci From 195bcad00ac084fe51a1d4acd53ae2580060c382 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Busch Date: Tue, 13 Jun 2023 18:28:15 +0200 Subject: [PATCH 2/8] make push stage work with os/arch --- .gitlab-ci/docker-ros.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab-ci/docker-ros.yml b/.gitlab-ci/docker-ros.yml index d1f4bab..aa34497 100644 --- a/.gitlab-ci/docker-ros.yml +++ b/.gitlab-ci/docker-ros.yml @@ -21,7 +21,7 @@ variables: 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_INDUSTRIAL_CI: 'true' # 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`) @@ -228,10 +228,10 @@ Test dev-arm64: if [[ "${PLATFORM}" =~ amd64 && "${PLATFORM}" =~ arm64 ]]; then [[ "${TARGET}" =~ dev ]] && docker manifest create ${IMG_DEV} --amend ${_IMAGE_DEV_CI_AMD64} --amend ${_IMAGE_DEV_CI_ARM64} [[ "${TARGET}" =~ run ]] && docker manifest create ${IMG_RUN} --amend ${_IMAGE_RUN_CI_AMD64} --amend ${_IMAGE_RUN_CI_ARM64} - elif [[ "${PLATFORM}" == amd64 ]]; then + elif [[ "${PLATFORM}" =~ amd64 ]]; then [[ "${TARGET}" =~ dev ]] && docker manifest create ${IMG_DEV} --amend ${_IMAGE_DEV_CI_AMD64} [[ "${TARGET}" =~ run ]] && docker manifest create ${IMG_RUN} --amend ${_IMAGE_RUN_CI_AMD64} - elif [[ "${PLATFORM}" == arm64 ]]; then + elif [[ "${PLATFORM}" =~ arm64 ]]; then [[ "${TARGET}" =~ dev ]] && docker manifest create ${IMG_DEV} --amend ${_IMAGE_DEV_CI_ARM64} [[ "${TARGET}" =~ run ]] && docker manifest create ${IMG_RUN} --amend ${_IMAGE_RUN_CI_ARM64} fi From f733d3599d76cefde9b8cf4632d1d2d2e92a7d32 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Busch Date: Tue, 13 Jun 2023 18:35:53 +0200 Subject: [PATCH 3/8] fix typo --- .gitlab-ci/docker-ros.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab-ci/docker-ros.yml b/.gitlab-ci/docker-ros.yml index aa34497..fb55c66 100644 --- a/.gitlab-ci/docker-ros.yml +++ b/.gitlab-ci/docker-ros.yml @@ -21,7 +21,7 @@ variables: 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: 'true' # Enable industrial_ci + 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`) From a9a78ecc9c8fb729b25f0417c2477575a3056883 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Busch Date: Wed, 14 Jun 2023 16:00:40 +0200 Subject: [PATCH 4/8] check platform condition in script --- .gitlab-ci/docker-ros.yml | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/.gitlab-ci/docker-ros.yml b/.gitlab-ci/docker-ros.yml index fb55c66..70ffa90 100644 --- a/.gitlab-ci/docker-ros.yml +++ b/.gitlab-ci/docker-ros.yml @@ -97,19 +97,23 @@ default: .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 + if [[ "${PLATFORM}" =~ ${_PLATFORM} ]]; then + 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" + else + echo "Do not build image for ${_PLATFORM}!" 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.*/ + - if: $TARGET =~ /.*dev.*/ variables: _PLATFORM: amd64 _TARGET: dev @@ -122,7 +126,7 @@ dev-arm64: extends: .build tags: [privileged, arm64] rules: - - if: $PLATFORM =~ /.*arm64.*/ && $TARGET =~ /.*dev.*/ + - if: $TARGET =~ /.*dev.*/ variables: _PLATFORM: arm64 _TARGET: dev @@ -137,7 +141,7 @@ run-amd64: - job: dev-amd64 optional: true rules: - - if: $PLATFORM =~ /.*amd64.*/ && $TARGET =~ /.*run.*/ + - if: $TARGET =~ /.*run.*/ variables: _PLATFORM: amd64 _TARGET: run @@ -153,7 +157,7 @@ run-arm64: - job: dev-arm64 optional: true rules: - - if: $PLATFORM =~ /.*arm64.*/ && $TARGET =~ /.*run.*/ + - if: $TARGET =~ /.*run.*/ variables: _PLATFORM: arm64 _TARGET: run @@ -224,6 +228,8 @@ Test dev-arm64: - if: $PLATFORM == '' || $TARGET == '' when: never script: + - echo $PLATFORM + - echo $CI_RUNNER_EXECUTABLE_ARCH - |- if [[ "${PLATFORM}" =~ amd64 && "${PLATFORM}" =~ arm64 ]]; then [[ "${TARGET}" =~ dev ]] && docker manifest create ${IMG_DEV} --amend ${_IMAGE_DEV_CI_AMD64} --amend ${_IMAGE_DEV_CI_ARM64} From d11d0da6aa27db3bd2fa231c99e38875aab4b426 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Busch Date: Wed, 14 Jun 2023 17:59:22 +0200 Subject: [PATCH 5/8] skip job in before_script --- .gitlab-ci/docker-ros.yml | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/.gitlab-ci/docker-ros.yml b/.gitlab-ci/docker-ros.yml index 70ffa90..fc085b5 100644 --- a/.gitlab-ci/docker-ros.yml +++ b/.gitlab-ci/docker-ros.yml @@ -77,6 +77,7 @@ default: - privileged - amd64 before_script: + - if [[ ${_PLATFORM} ]] && ! [[ "${PLATFORM}" =~ ${_PLATFORM} ]]; then echo "job will not run for this architecture (${_PLATFORM})" && exit 0; fi - echo -e "section_start:`date +%s`:setup_section[collapsed=true]\r\e[0K[docker-ros] Setup docker-ros" - apk add bash - cd ${BUILD_CONTEXT} @@ -97,17 +98,13 @@ default: .build: script: - |- - if [[ "${PLATFORM}" =~ ${_PLATFORM} ]]; then - 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" - else - echo "Do not build image for ${_PLATFORM}!" + 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 @@ -174,6 +171,7 @@ run-arm64: 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: + - if [[ ${_PLATFORM} ]] && ! [[ "${PLATFORM}" =~ ${_PLATFORM} ]]; then echo "job will not run for this architecture (${_PLATFORM})" && exit 0; fi - docker login -u ${REGISTRY_USER} -p ${REGISTRY_PASSWORD} ${REGISTRY} - apk add --update bash coreutils grep tar - |- @@ -191,7 +189,7 @@ Test dev-amd64: - job: dev-amd64 optional: true rules: - - if: $ENABLE_INDUSTRIAL_CI == 'true' && $PLATFORM =~ /.*amd64.*/ + - if: $ENABLE_INDUSTRIAL_CI == 'true' variables: DOCKER_IMAGE: ${_IMAGE_DEV_CI_AMD64} _PLATFORM: amd64 @@ -204,7 +202,7 @@ Test dev-arm64: - job: dev-arm64 optional: true rules: - - if: $ENABLE_INDUSTRIAL_CI == 'true' && $PLATFORM =~ /.*arm64.*/ + - if: $ENABLE_INDUSTRIAL_CI == 'true' variables: DOCKER_IMAGE: ${_IMAGE_DEV_CI_ARM64} _PLATFORM: arm64 From e2054a455dcd77082b4c8dfc1a368b9864d1db2f Mon Sep 17 00:00:00 2001 From: Jean-Pierre Busch Date: Wed, 14 Jun 2023 18:17:11 +0200 Subject: [PATCH 6/8] improve entrypoint --- docker/entrypoint.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 5771f19..2456281 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -18,11 +18,11 @@ if [[ $DOCKER_UID && $DOCKER_GID ]]; then --password "$(openssl passwd -1 $DOCKER_USER)" \ $DOCKER_USER && \ touch /home/$DOCKER_USER/.sudo_as_admin_successful - chown -R $DOCKER_USER:$DOCKER_USER $WORKSPACE - ln -s $WORKSPACE /home/$DOCKER_USER/ws - cd /home/$DOCKER_USER/ws cp /root/.bashrc /home/$DOCKER_USER - chown $DOCKER_USER:$DOCKER_USER /home/$DOCKER_USER/.bashrc + ln -s $WORKSPACE /home/$DOCKER_USER/ws + chown -R $DOCKER_USER:$DOCKER_USER $WORKSPACE + chown -R $DOCKER_USER:$DOCKER_USER /home/$DOCKER_USER + [[ $(pwd) == "$WORKSPACE" ]] && cd /home/$DOCKER_USER/ws exec gosu $DOCKER_USER "$@" else exec "$@" From a0fdeb768c50429e56f412c1e387f324c3778a52 Mon Sep 17 00:00:00 2001 From: Jean-Pierre Busch <110477057+jpbusch@users.noreply.github.com> Date: Wed, 14 Jun 2023 20:10:28 +0200 Subject: [PATCH 7/8] remove temporary echos --- .gitlab-ci/docker-ros.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitlab-ci/docker-ros.yml b/.gitlab-ci/docker-ros.yml index fc085b5..e6b45cb 100644 --- a/.gitlab-ci/docker-ros.yml +++ b/.gitlab-ci/docker-ros.yml @@ -226,8 +226,6 @@ Test dev-arm64: - if: $PLATFORM == '' || $TARGET == '' when: never script: - - echo $PLATFORM - - echo $CI_RUNNER_EXECUTABLE_ARCH - |- if [[ "${PLATFORM}" =~ amd64 && "${PLATFORM}" =~ arm64 ]]; then [[ "${TARGET}" =~ dev ]] && docker manifest create ${IMG_DEV} --amend ${_IMAGE_DEV_CI_AMD64} --amend ${_IMAGE_DEV_CI_ARM64} From b9e38543a16fdf8d8a57832eb7a2c67a5c172a7b Mon Sep 17 00:00:00 2001 From: Jean-Pierre Busch <110477057+jpbusch@users.noreply.github.com> Date: Thu, 15 Jun 2023 00:17:52 +0200 Subject: [PATCH 8/8] improve output for skipped job Co-authored-by: Lennart Reiher --- .gitlab-ci/docker-ros.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab-ci/docker-ros.yml b/.gitlab-ci/docker-ros.yml index e6b45cb..b938cf2 100644 --- a/.gitlab-ci/docker-ros.yml +++ b/.gitlab-ci/docker-ros.yml @@ -77,7 +77,7 @@ default: - privileged - amd64 before_script: - - if [[ ${_PLATFORM} ]] && ! [[ "${PLATFORM}" =~ ${_PLATFORM} ]]; then echo "job will not run for this architecture (${_PLATFORM})" && exit 0; fi + - if [[ -n ${_PLATFORM} ]] && ! [[ "${PLATFORM}" =~ ${_PLATFORM} ]]; then echo "Platform '${_PLATFORM}' is skipped; can be enabled by adding '${_PLATFORM}' to the 'PLATFORM' variable" && exit 0; fi - echo -e "section_start:`date +%s`:setup_section[collapsed=true]\r\e[0K[docker-ros] Setup docker-ros" - apk add bash - cd ${BUILD_CONTEXT} @@ -171,7 +171,7 @@ run-arm64: 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: - - if [[ ${_PLATFORM} ]] && ! [[ "${PLATFORM}" =~ ${_PLATFORM} ]]; then echo "job will not run for this architecture (${_PLATFORM})" && exit 0; fi + - if [[ -n ${_PLATFORM} ]] && ! [[ "${PLATFORM}" =~ ${_PLATFORM} ]]; then echo "Platform '${_PLATFORM}' is skipped; can be enabled by adding '${_PLATFORM}' to the 'PLATFORM' variable" && exit 0; fi - docker login -u ${REGISTRY_USER} -p ${REGISTRY_PASSWORD} ${REGISTRY} - apk add --update bash coreutils grep tar - |-