Skip to content

Commit

Permalink
Merge pull request #33 from ika-rwth-aachen/slim
Browse files Browse the repository at this point in the history
  • Loading branch information
lreiher authored Oct 26, 2024
2 parents 19155d4 + 3257ce0 commit 8f66397
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 177 deletions.
91 changes: 86 additions & 5 deletions .gitlab-ci/docker-ros.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ variables:
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
SLIM_IMAGE_NAME: ${IMAGE_NAME} # Image name of slim run image
SLIM_IMAGE_TAG: ${IMAGE_TAG}-slim # Image tag of slim run 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_SLIM: 'true' # Enable an extra slimmed run image via slim (only if run stage is targeted)
SLIM_BUILD_ARGS: '--sensor-ipc-mode proxy --continue-after=10 --show-clogs --http-probe=false' # Arguments to `slim build` (except for `--target` and `--tag`)
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
RMW_IMPLEMENTATION: 'rmw_cyclonedds_cpp' # RMW implementation to use (only for ROS 2)
Expand All @@ -47,19 +51,26 @@ variables:

_RUN_IMAGE: ${IMAGE_NAME}:${IMAGE_TAG}
_DEV_IMAGE: ${DEV_IMAGE_NAME}:${DEV_IMAGE_TAG}
_SLIM_IMAGE: ${SLIM_IMAGE_NAME}:${SLIM_IMAGE_TAG}

_IMAGE_DEV_CI: ${_DEV_IMAGE}_${CI_COMMIT_REF_SLUG}_ci
_IMAGE_RUN_CI: ${_RUN_IMAGE}_${CI_COMMIT_REF_SLUG}_ci
_IMAGE_SLIM_CI: ${_SLIM_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_SLIM_CI_AMD64: ${_IMAGE_SLIM_CI}-amd64
_IMAGE_SLIM_CI_ARM64: ${_IMAGE_SLIM_CI}-arm64
_IMAGE_DEV_LATEST: ${DEV_IMAGE_NAME}:latest-dev
_IMAGE_RUN_LATEST: ${IMAGE_NAME}:latest
_IMAGE_SLIM_LATEST: ${SLIM_IMAGE_NAME}:latest-slim
_IMAGE_DEV_TARGET_TAG: ${_DEV_IMAGE}-${CI_COMMIT_TAG}
_IMAGE_RUN_TARGET_TAG: ${_RUN_IMAGE}-${CI_COMMIT_TAG}
_IMAGE_SLIM_TARGET_TAG: ${_SLIM_IMAGE}-${CI_COMMIT_TAG}
_IMAGE_DEV_TAG: ${DEV_IMAGE_NAME}:${CI_COMMIT_TAG}-dev
_IMAGE_RUN_TAG: ${IMAGE_NAME}:${CI_COMMIT_TAG}
_IMAGE_SLIM_TAG: ${SLIM_IMAGE_NAME}:${CI_COMMIT_TAG}-slim

GIT_SUBMODULE_STRATEGY: recursive
DOCKER_DRIVER: overlay2
Expand All @@ -71,6 +82,7 @@ stages:
- Build dev Images
- Build run Images
- Test ROS Industrial CI
- Slim Images
- Push Multi-Arch Images


Expand All @@ -83,7 +95,7 @@ default:
- amd64
before_script:
- echo -e "section_start:`date +%s`:setup_section[collapsed=true]\r\e[0K[docker-ros] Setup docker-ros"
- apk add bash
- apk add --update bash
- cd ${BUILD_CONTEXT}
- |-
if [[ ! -d docker/docker-ros ]]; then
Expand Down Expand Up @@ -120,6 +132,7 @@ dev-amd64:
_TARGET: dev
IMAGE: ${_IMAGE_DEV_CI_AMD64}
ENABLE_SINGLEARCH_PUSH: 'true'
ENABLE_SLIM: 'false'
_IMAGE_POSTFIX: _${CI_COMMIT_REF_SLUG}_ci

dev-arm64:
Expand All @@ -133,6 +146,7 @@ dev-arm64:
_TARGET: dev
IMAGE: ${_IMAGE_DEV_CI_ARM64}
ENABLE_SINGLEARCH_PUSH: 'true'
ENABLE_SLIM: 'false'
_IMAGE_POSTFIX: _${CI_COMMIT_REF_SLUG}_ci

run-amd64:
Expand All @@ -148,6 +162,7 @@ run-amd64:
_TARGET: run
IMAGE: ${_IMAGE_RUN_CI_AMD64}
ENABLE_SINGLEARCH_PUSH: 'true'
ENABLE_SLIM: 'false'
_IMAGE_POSTFIX: _${CI_COMMIT_REF_SLUG}_ci

run-arm64:
Expand All @@ -164,10 +179,12 @@ run-arm64:
_TARGET: run
IMAGE: ${_IMAGE_RUN_CI_ARM64}
ENABLE_SINGLEARCH_PUSH: 'true'
ENABLE_SLIM: 'false'
_IMAGE_POSTFIX: _${CI_COMMIT_REF_SLUG}_ci


.test:
stage: Test ROS Industrial CI
variables:
UPSTREAM_WORKSPACE: ${BUILD_CONTEXT}/.repos
TARGET_WORKSPACE: ${BUILD_CONTEXT}
Expand All @@ -190,7 +207,6 @@ run-arm64:
script: .industrial_ci/gitlab.sh

Test dev-amd64:
stage: Test ROS Industrial CI
extends: .test
needs:
- job: dev-amd64
Expand All @@ -201,7 +217,6 @@ Test dev-amd64:
_PLATFORM: amd64

Test dev-arm64:
stage: Test ROS Industrial CI
extends: .test
tags: [privileged, arm64]
needs:
Expand All @@ -213,7 +228,6 @@ Test dev-arm64:
_PLATFORM: arm64

Test run-amd64:
stage: Test ROS Industrial CI
extends: .test
needs:
- job: run-amd64
Expand All @@ -224,7 +238,6 @@ Test run-amd64:
_PLATFORM: amd64

Test run-arm64:
stage: Test ROS Industrial CI
extends: .test
needs:
- job: run-arm64
Expand All @@ -235,6 +248,51 @@ Test run-arm64:
_PLATFORM: arm64


.slim:
stage: Slim Images
before_script:
- apk add --update --upgrade curl tar
- curl -L -o ds.tar.gz ${SLIM_DOWNLOAD_URL}
- tar -xvf ds.tar.gz
- cd dist_linux*
- docker login -u ${REGISTRY_USER} -p ${REGISTRY_PASSWORD} ${REGISTRY}
- docker pull ${FAT_IMAGE}
script:
- ./slim build --target ${FAT_IMAGE} --tag ${SLIM_IMAGE} ${SLIM_BUILD_ARGS}
- docker push ${SLIM_IMAGE}

Slim run-amd64:
stage: Slim Images
extends: .slim
needs:
- job: run-amd64
optional: true
- job: Test run-amd64
optional: true
rules:
- if: $ENABLE_SLIM == 'true' && $PLATFORM =~ /.*amd64.*/ && $TARGET =~ /.*run.*/
variables:
FAT_IMAGE: ${_IMAGE_RUN_CI_AMD64}
SLIM_IMAGE: ${_IMAGE_SLIM_CI_AMD64}
SLIM_DOWNLOAD_URL: "https://github.com/slimtoolkit/slim/releases/download/1.40.11/dist_linux.tar.gz"

Slim run-arm64:
stage: Slim Images
extends: .slim
tags: [privileged, arm64]
needs:
- job: run-arm64
optional: true
- job: Test run-arm64
optional: true
rules:
- if: $ENABLE_SLIM == 'true' && $PLATFORM =~ /.*arm64.*/ && $TARGET =~ /.*run.*/
variables:
FAT_IMAGE: ${_IMAGE_RUN_CI_ARM64}
SLIM_IMAGE: ${_IMAGE_SLIM_CI_ARM64}
SLIM_DOWNLOAD_URL: "https://github.com/slimtoolkit/slim/releases/download/1.40.11/dist_linux_arm64.tar.gz"


.push:
needs:
- job: dev-amd64
Expand All @@ -253,6 +311,10 @@ Test run-arm64:
optional: true
- job: Test run-arm64
optional: true
- job: Slim run-amd64
optional: true
- job: Slim run-arm64
optional: true
rules:
- if: $PLATFORM == '' || $TARGET == ''
when: never
Expand All @@ -267,6 +329,10 @@ Test run-arm64:
docker manifest create ${IMG_RUN} --amend ${_IMAGE_RUN_CI_AMD64} --amend ${_IMAGE_RUN_CI_ARM64}
docker manifest push ${IMG_RUN}
fi
if [[ "${ENABLE_SLIM}" == 'true' && "${TARGET}" =~ run ]]; then
docker manifest create ${IMG_SLIM} --amend ${_IMAGE_SLIM_CI_AMD64} --amend ${_IMAGE_SLIM_CI_ARM64}
docker manifest push ${IMG_SLIM}
fi
elif [[ "${PLATFORM}" =~ amd64 ]]; then
if [[ "${TARGET}" =~ dev ]]; then
docker pull ${_IMAGE_DEV_CI_AMD64}
Expand All @@ -278,6 +344,11 @@ Test run-arm64:
docker tag ${_IMAGE_RUN_CI_AMD64} ${IMG_RUN}
docker push ${IMG_RUN}
fi
if [[ "${ENABLE_SLIM}" == 'true' && "${TARGET}" =~ run ]]; then
docker pull ${_IMAGE_SLIM_CI_AMD64}
docker tag ${_IMAGE_SLIM_CI_AMD64} ${IMG_SLIM}
docker push ${IMG_SLIM}
fi
elif [[ "${PLATFORM}" =~ arm64 ]]; then
if [[ "${TARGET}" =~ dev ]]; then
docker pull ${_IMAGE_DEV_CI_ARM64}
Expand All @@ -289,6 +360,11 @@ Test run-arm64:
docker tag ${_IMAGE_RUN_CI_ARM64} ${IMG_RUN}
docker push ${IMG_RUN}
fi
if [[ "${ENABLE_SLIM}" == 'true' && "${TARGET}" =~ run ]]; then
docker pull ${_IMAGE_SLIM_CI_ARM64}
docker tag ${_IMAGE_SLIM_CI_ARM64} ${IMG_SLIM}
docker push ${IMG_SLIM}
fi
fi
Push CI:
Expand All @@ -302,6 +378,7 @@ Push CI:
variables:
IMG_DEV: ${_IMAGE_DEV_CI}
IMG_RUN: ${_IMAGE_RUN_CI}
IMG_SLIM: ${_IMAGE_SLIM_CI}

Push:
stage: Push Multi-Arch Images
Expand All @@ -312,6 +389,7 @@ Push:
variables:
IMG_DEV: ${_DEV_IMAGE}
IMG_RUN: ${_RUN_IMAGE}
IMG_SLIM: ${_SLIM_IMAGE}

Push latest:
stage: Push Multi-Arch Images
Expand All @@ -322,6 +400,7 @@ Push latest:
variables:
IMG_DEV: ${_IMAGE_DEV_LATEST}
IMG_RUN: ${_IMAGE_RUN_LATEST}
IMG_SLIM: ${_IMAGE_SLIM_LATEST}

Push target tag:
stage: Push Multi-Arch Images
Expand All @@ -332,6 +411,7 @@ Push target tag:
variables:
IMG_DEV: ${_IMAGE_DEV_TARGET_TAG}
IMG_RUN: ${_IMAGE_RUN_TARGET_TAG}
IMG_SLIM: ${_IMAGE_SLIM_TARGET_TAG}

Push tag:
stage: Push Multi-Arch Images
Expand All @@ -342,3 +422,4 @@ Push tag:
variables:
IMG_DEV: ${_IMAGE_DEV_TAG}
IMG_RUN: ${_IMAGE_RUN_TAG}
IMG_SLIM: ${_IMAGE_SLIM_TAG}
Loading

0 comments on commit 8f66397

Please sign in to comment.