Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integrate docker-slim for waaaaaaaay smaller run images #33

Merged
merged 28 commits into from
Oct 26, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
23fef56
remove unused templates
lreiher Sep 4, 2024
db39c16
test-integrate slim in gitlab-ci
lreiher Sep 4, 2024
01e5af7
fix missing deps in slim ci job
lreiher Sep 4, 2024
b049458
fix curl installation in slim job
lreiher Sep 4, 2024
e861964
fix slim arguments
lreiher Sep 4, 2024
e65cd1a
dont let slim pull
lreiher Sep 4, 2024
6ec5a09
try to fix slim in container
lreiher Sep 4, 2024
562ffd8
run containerized slim as suggested for gitlab ci in readme
lreiher Sep 4, 2024
ce568da
try another way of invoking slim in gitlab ci
lreiher Sep 4, 2024
48c071f
remove slim debug flags
lreiher Sep 5, 2024
b6c861c
add slim job for arm64
lreiher Sep 5, 2024
ebecb90
add variable to control slim image name
lreiher Sep 5, 2024
6144f8e
remove irrelevant todo comments
lreiher Oct 23, 2024
d619bdd
add flag for enabling slim
lreiher Oct 23, 2024
0be5da5
add slimmed image to multiarch push stage
lreiher Oct 23, 2024
3ca384d
add env to control slim build arguments
lreiher Oct 23, 2024
6235b2a
implement slimming in github ci
lreiher Oct 23, 2024
3e53048
remove slim report artifacts
lreiher Oct 24, 2024
fa95278
try to fix slim in github action
lreiher Oct 24, 2024
66a76a5
fix inputs in github ci action
lreiher Oct 24, 2024
d5d7533
fix missing tag in slim images in github ci
lreiher Oct 24, 2024
4c78b3a
move slim in github ci to ci.sh script
lreiher Oct 24, 2024
1b33b10
disable slim in ci.sh for gitlab ci as separate stage
lreiher Oct 25, 2024
cb56641
only install slim in ci.sh if enabled
lreiher Oct 25, 2024
e546c9e
explain slim in readme
lreiher Oct 25, 2024
d8901c5
test github ci
lreiher Oct 25, 2024
13b1ab1
bump version to v1.6.0
lreiher Oct 25, 2024
3257ce0
fix github ci push of slim image
lreiher Oct 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 86 additions & 5 deletions .gitlab-ci/docker-ros.yml
lreiher marked this conversation as resolved.
Show resolved Hide resolved
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
lreiher marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -186,7 +203,6 @@ run-arm64:
script: .industrial_ci/gitlab.sh

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

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

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

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


.slim:
stage: Slim Images
lreiher marked this conversation as resolved.
Show resolved Hide resolved
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 @@ -249,6 +307,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 @@ -263,6 +325,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 @@ -274,6 +340,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 @@ -285,6 +356,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 @@ -298,6 +374,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 @@ -308,6 +385,7 @@ Push:
variables:
IMG_DEV: ${_DEV_IMAGE}
IMG_RUN: ${_RUN_IMAGE}
IMG_SLIM: ${_SLIM_IMAGE}

Push latest:
stage: Push Multi-Arch Images
Expand All @@ -318,6 +396,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 @@ -328,6 +407,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 @@ -338,3 +418,4 @@ Push tag:
variables:
IMG_DEV: ${_IMAGE_DEV_TAG}
IMG_RUN: ${_IMAGE_RUN_TAG}
IMG_SLIM: ${_IMAGE_SLIM_TAG}
38 changes: 36 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,18 @@ inputs:

dev-image-name:
description: "Image name of dev image"
default: ghcr.io/${{ github.repository }}

dev-image-tag:
description: "Image tag of dev image"

slim-image-name:
description: "Image name of slim run image"
default: ghcr.io/${{ github.repository }}

slim-image-tag:
description: "Image tag of slim run image"

build-context:
description: "Build context of Docker build process"
default: ${{ github.workspace }}
Expand Down Expand Up @@ -112,6 +120,14 @@ inputs:
description: "Enable industrial_ci"
default: false

enable-slim:
description: "Enable an extra slimmed run image via slim (only if run stage is targeted)"
default: true

slim-build-args:
description: "Arguments to `slim build` (except for `--target` and `--tag`)"
default: '--sensor-ipc-mode proxy --continue-after=10 --show-clogs --http-probe=false'

enable-singlearch-push:
description: "Enable push of single arch images with [-amd64|-arm64] postfix"
default: false
Expand Down Expand Up @@ -184,6 +200,12 @@ runs:
with:
string: ${{ inputs.dev-image-name }}

- name: Enforce lower-case slim image name
id: slim-image-name
uses: ASzc/change-string-case-action@v6
with:
string: ${{ inputs.slim-image-name }}

- name: Build images
id: build-images
shell: bash
Expand All @@ -198,6 +220,10 @@ runs:
IMAGE_TAG: ${{ inputs.image-tag }}
DEV_IMAGE_NAME: ${{ steps.dev-image-name.outputs.lowercase }}
DEV_IMAGE_TAG: ${{ inputs.dev-image-tag }}
SLIM_IMAGE_NAME: ${{ steps.slim-image-name.outputs.lowercase }}
SLIM_IMAGE_TAG: ${{ inputs.slim-image-tag }}
ENABLE_SLIM: ${{ inputs.enable-slim }}
SLIM_BUILD_ARGS: ${{ inputs.slim-build-args }}
RMW_IMPLEMENTATION: ${{ inputs.rmw-implementation }}
ROS_DISTRO: ${{ inputs.ros-distro }}
GIT_HTTPS_SERVER: ${{ inputs.git-https-server }}
Expand Down Expand Up @@ -253,8 +279,12 @@ runs:
COMMAND: ${{ inputs.command }}
IMAGE_NAME: ${{ steps.image-name.outputs.lowercase }}
IMAGE_TAG: ${{ inputs.image-tag }}
DEV_IMAGE_NAME: ${{ inputs.dev-image-name }}
DEV_IMAGE_NAME: ${{ steps.dev-image-name.outputs.lowercase }}
DEV_IMAGE_TAG: ${{ inputs.dev-image-tag }}
SLIM_IMAGE_NAME: ${{ steps.slim-image-name.outputs.lowercase }}
SLIM_IMAGE_TAG: ${{ inputs.slim-image-tag }}
ENABLE_SLIM: ${{ inputs.enable-slim }}
SLIM_BUILD_ARGS: ${{ inputs.slim-build-args }}
ENABLE_SINGLEARCH_PUSH: ${{ inputs.enable-singlearch-push }}
RMW_IMPLEMENTATION: ${{ inputs.rmw-implementation }}
ROS_DISTRO: ${{ inputs.ros-distro }}
Expand Down Expand Up @@ -289,8 +319,12 @@ runs:
COMMAND: ${{ inputs.command }}
IMAGE_NAME: ${{ steps.image-name.outputs.lowercase }}
IMAGE_TAG: latest
DEV_IMAGE_NAME: ${{ inputs.dev-image-name }}
DEV_IMAGE_NAME: ${{ steps.dev-image-name.outputs.lowercase }}
DEV_IMAGE_TAG: latest-dev
SLIM_IMAGE_NAME: ${{ steps.slim-image-name.outputs.lowercase }}
SLIM_IMAGE_TAG: latest-slim
ENABLE_SLIM: ${{ inputs.enable-slim }}
SLIM_BUILD_ARGS: ${{ inputs.slim-build-args }}
ENABLE_SINGLEARCH_PUSH: ${{ inputs.enable-singlearch-push }}
RMW_IMPLEMENTATION: ${{ inputs.rmw-implementation }}
ROS_DISTRO: ${{ inputs.ros-distro }}
Expand Down
28 changes: 28 additions & 0 deletions scripts/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ IMAGE_TAG="${IMAGE_TAG:-latest}"
[[ "${TARGET}" == *"run"* ]] && require_var "COMMAND"
DEV_IMAGE_NAME="${DEV_IMAGE_NAME:-${IMAGE_NAME}}"
DEV_IMAGE_TAG="${DEV_IMAGE_TAG:-${IMAGE_TAG}-dev}"
SLIM_IMAGE_NAME="${SLIM_IMAGE_NAME:-${IMAGE_NAME}}"
SLIM_IMAGE_TAG="${SLIM_IMAGE_TAG:-${IMAGE_TAG}-slim}"

IMAGE="${IMAGE_NAME}:${IMAGE_TAG}"
DEV_IMAGE="${DEV_IMAGE_NAME}:${DEV_IMAGE_TAG}"
SLIM_IMAGE="${SLIM_IMAGE_NAME}:${SLIM_IMAGE_TAG}"
ENABLE_SLIM="${ENABLE_SLIM:-true}"
SLIM_BUILD_ARGS="${SLIM_BUILD_ARGS:-'--sensor-ipc-mode proxy --continue-after=10 --show-clogs --http-probe=false'}"
ENABLE_SINGLEARCH_PUSH="${ENABLE_SINGLEARCH_PUSH:-false}"
RMW_IMPLEMENTATION="${RMW_IMPLEMENTATION:-}"
ROS_DISTRO="${ROS_DISTRO:-}"
Expand Down Expand Up @@ -64,6 +69,10 @@ fi
unset TARGET
unset PLATFORM

# prepare slim
curl -L -o ds.tar.gz https://github.com/slimtoolkit/slim/releases/download/1.40.11/dist_linux.tar.gz
tar -xvf ds.tar.gz

# loop over targets and platforms to build images
for PLATFORM in "${PLATFORMS[@]}"; do
for TARGET in "${TARGETS[@]}"; do
Expand All @@ -75,4 +84,23 @@ for PLATFORM in "${PLATFORMS[@]}"; do
IMAGE="${image}" build_image
close_log_group
done

# slim image
if [[ "${ENABLE_SLIM}" == "true" && "${TARGET}" == "run" ]]; then
open_log_group "Slim image (${PLATFORM})"
image="${IMAGE}"
slim_image="${SLIM_IMAGE}"
[[ -n "${_IMAGE_POSTFIX}" ]] && image="${image}${_IMAGE_POSTFIX}"
[[ -n "${_IMAGE_POSTFIX}" ]] && slim_image="${slim_image}${_IMAGE_POSTFIX}"
[[ "${_ENABLE_IMAGE_PUSH}" != "true" || "${ENABLE_SINGLEARCH_PUSH}" == "true" ]] && image="${image}-${PLATFORM}"
# TODO: not yet working; builds image with suffix, pushed without? [[ "${_ENABLE_IMAGE_PUSH}" != "true" || "${ENABLE_SINGLEARCH_PUSH}" == "true" ]] && slim_image="${slim_image}-${PLATFORM}"
lreiher marked this conversation as resolved.
Show resolved Hide resolved
if [[ "${_ENABLE_IMAGE_PUSH}" == "true" || "${ENABLE_SINGLEARCH_PUSH}" == "true" ]]; then
docker push "${slim_image}"
else
cd dist_linux*
./slim build --target "${image}" --tag "${slim_image}" ${SLIM_BUILD_ARGS}
cd -
fi
close_log_group
fi
done
Loading
Loading