From 4c78b3a5132802bd1cf71aed33ff96fbbfa33f70 Mon Sep 17 00:00:00 2001 From: Lennart Reiher Date: Thu, 24 Oct 2024 09:44:29 +0000 Subject: [PATCH] move slim in github ci to ci.sh script --- .gitlab-ci/docker-ros.yml | 4 ++-- action.yml | 20 +++++++------------- scripts/ci.sh | 31 ++++++++++++++++++++++++------- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/.gitlab-ci/docker-ros.yml b/.gitlab-ci/docker-ros.yml index cc55018..4f71a3e 100644 --- a/.gitlab-ci/docker-ros.yml +++ b/.gitlab-ci/docker-ros.yml @@ -25,7 +25,7 @@ variables: 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_ARGUMENTS: '--sensor-ipc-mode proxy --continue-after=10 --show-clogs --http-probe=false' # Arguments to `slim build` (except for `--target` and `--tag`) + 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) @@ -250,7 +250,7 @@ Test run-arm64: - docker login -u ${REGISTRY_USER} -p ${REGISTRY_PASSWORD} ${REGISTRY} - docker pull ${FAT_IMAGE} script: - - ./slim build --target ${FAT_IMAGE} --tag ${SLIM_IMAGE} ${SLIM_BUILD_ARGUMENTS} + - ./slim build --target ${FAT_IMAGE} --tag ${SLIM_IMAGE} ${SLIM_BUILD_ARGS} - docker push ${SLIM_IMAGE} Slim run-amd64: diff --git a/action.yml b/action.yml index 0f1cd58..4421e54 100644 --- a/action.yml +++ b/action.yml @@ -31,7 +31,6 @@ inputs: dev-image-tag: description: "Image tag of dev image" - default: latest-dev slim-image-name: description: "Image name of slim run image" @@ -39,7 +38,6 @@ inputs: slim-image-tag: description: "Image tag of slim run image" - default: latest-slim build-context: description: "Build context of Docker build process" @@ -126,7 +124,7 @@ inputs: description: "Enable an extra slimmed run image via slim (only if run stage is targeted)" default: true - slim-build-arguments: + 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' @@ -222,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 }} @@ -260,16 +262,6 @@ runs: DOCKER_IMAGE: ${{ steps.build-images.outputs.INDUSTRIAL_CI_IMAGE }} DOCKER_PULL: false - - name: Slim images - if: ${{ inputs.enable-slim == 'true' && contains(inputs.target, 'run') }} - shell: bash - working-directory: ${{ inputs.build-context }} - run: | - 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 - cd dist_linux* - ./slim build --target ${{ steps.image-name.outputs.lowercase }}:${{ inputs.image-tag }} --tag ${{ steps.slim-image-name.outputs.lowercase }}:${{ inputs.slim-image-tag }} ${{ inputs.slim-build-arguments }} - - name: Slugify ref name id: slugify-ref-name uses: gacts/github-slug@v1 @@ -292,6 +284,7 @@ runs: 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 }} @@ -331,6 +324,7 @@ runs: 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 }} diff --git a/scripts/ci.sh b/scripts/ci.sh index 52b869f..b9a7ef9 100755 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -23,6 +23,7 @@ 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:-}" @@ -68,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 @@ -79,11 +84,23 @@ for PLATFORM in "${PLATFORMS[@]}"; do IMAGE="${image}" build_image close_log_group done -done -# push slim images -if [[ "${ENABLE_SLIM}" == "true" && "${_ENABLE_IMAGE_PUSH}" == "true" && "${TARGET}" == *"run"* ]]; then - open_log_group "Push slim image" - docker push "${SLIM_IMAGE}" - close_log_group -fi + # 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}" + 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