From 0ed427c82c959906331f5b3038ffd61ec08db654 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Tue, 20 May 2025 13:34:50 +0200 Subject: [PATCH] stashed work --- build_sdk_container_image | 10 +++++----- ci-automation/packages.sh | 5 ++--- ci-automation/release.sh | 2 +- ci-automation/test.sh | 2 +- run_sdk_container | 2 +- sdk_lib/sdk_container_common.sh | 16 ++++++++++++++-- 6 files changed, 24 insertions(+), 13 deletions(-) diff --git a/build_sdk_container_image b/build_sdk_container_image index d1e4fce88d..55c8fe0433 100755 --- a/build_sdk_container_image +++ b/build_sdk_container_image @@ -118,7 +118,7 @@ if [ "${image_present}" = "${import_tarball}" ] ; then else yell "Importing SDK tarball" if [ -n "$cleanup" ] ; then - echo "$docker image rm -f '${import_tarball}'" >> "$cleanup" + prepend_cleanup "${cleanup}" "${docker} image rm -f '${import_tarball}'" fi $docker import "${tarball}" "${import_tarball}" fi @@ -135,7 +135,7 @@ if [ "$image_present" = "${import_image}" ] ; then else yell "Building plain SDK import image" if [ -n "$cleanup" ] ; then - echo "$docker image rm -f '${import_image}'" >> "$cleanup" + prepend_cleanup "${cleanup}" "${docker} image rm -f '${import_image}'" fi $docker build -t "$import_image" \ --build-arg VERSION="${docker_vernum}" \ @@ -168,7 +168,7 @@ else toolchains_container="flatcar-sdk-toolchains-build-${docker_vernum}" if [ -n "$cleanup" ] ; then - echo "$docker container rm -f '${toolchains_container}'" >> "$cleanup" + prepend_cleanup "${cleanup}" "${docker} container rm -f '${toolchains_container}'" fi ./run_sdk_container -C "${import_image}" -n "${toolchains_container}" \ sudo ./build_toolchains --seed_tarball="./${tarball}" @@ -194,7 +194,7 @@ else # Spin up temporary toolchains package binhost if [ -n "$cleanup" ] ; then - echo "$docker container rm -f '${binhost_container}'" >> "$cleanup" + prepend_cleanup "${cleanup}" "${docker} container rm -f '${binhost_container}'" fi $docker run --rm -d -p "${binhost}":80 \ --name ${binhost_container} \ @@ -206,7 +206,7 @@ else yell "Initialising the SDK container and building board packages" if [ -n "$cleanup" ] ; then - echo "$docker image rm -f '${sdk_build_image}'" >> "$cleanup" + prepend_cleanup "${cleanup}" "${docker} image rm -f '${sdk_build_image}'" fi $docker build -t "${sdk_build_image}" \ --build-arg VERSION="${docker_vernum}" \ diff --git a/ci-automation/packages.sh b/ci-automation/packages.sh index add6fc3c61..f07e75414b 100644 --- a/ci-automation/packages.sh +++ b/ci-automation/packages.sh @@ -62,6 +62,7 @@ function packages_build() { function _packages_build_impl() { local arch="$1" + source sdk_lib/sdk_container_common.sh source ci-automation/ci_automation_common.sh source ci-automation/gpg_setup.sh @@ -75,7 +76,7 @@ function _packages_build_impl() { docker_image_from_registry_or_buildcache "${sdk_name}" "${docker_sdk_vernum}" local sdk_image="$(docker_image_fullname "${sdk_name}" "${docker_sdk_vernum}")" - echo "docker image rm -f '${sdk_image}'" >> ./ci-cleanup.sh + prepend_cleanup ./ci-cleanup.sh "docker image rm -f '${sdk_image}'" # Set name of the packages container for later rename / export local vernum="${FLATCAR_VERSION}" @@ -83,8 +84,6 @@ function _packages_build_impl() { local packages_container="flatcar-packages-${arch}-${docker_vernum}" local torcx_pkg_url="https://${BUILDCACHE_SERVER}/images/${arch}/${vernum}/torcx" - source sdk_lib/sdk_container_common.sh - if is_official "${vernum}"; then # A channel returned by get_git_channel should not ever be # "developer" here, because it's an official build done from diff --git a/ci-automation/release.sh b/ci-automation/release.sh index 930fd9d904..dfeb5a73d5 100644 --- a/ci-automation/release.sh +++ b/ci-automation/release.sh @@ -203,7 +203,7 @@ function _release_build_impl() { local mantle_ref mantle_ref=$(cat sdk_container/.repo/manifests/mantle-container) # A job on each worker prunes old mantle images (docker image prune), no need to do it here - echo "docker rm -f '${container_name}'" >> ./ci-cleanup.sh + prepend_cleanup ./ci-cleanup.sh "docker rm -f '${container_name}'" touch sdk_container/.env # This file should already contain the required credentials as env vars docker run --pull always --rm --name="${container_name}" --net host \ diff --git a/ci-automation/test.sh b/ci-automation/test.sh index c3b14fe2f3..2f53743909 100644 --- a/ci-automation/test.sh +++ b/ci-automation/test.sh @@ -186,7 +186,7 @@ function _test_run_impl() { local print_give_up=true local failed_tests=() # A job on each worker prunes old mantle images (docker image prune) - echo "docker rm -f '${container_name}'" >> ./ci-cleanup.sh + prepend_cleanup ./ci-cleanup.sh "docker rm -f '${container_name}'" local image_escaped printf -v image_escaped '%q' "${image}" diff --git a/run_sdk_container b/run_sdk_container index b34b7958c1..7280f76349 100755 --- a/run_sdk_container +++ b/run_sdk_container @@ -100,7 +100,7 @@ hostname="${name:0:63}" hostname="${hostname//./_}" if [ -n "$cleanup" ] ; then - echo "$docker container rm -f '${name}'" >> "$cleanup" + prepend_cleanup "${cleanup}" "${docker} container rm -f '${name}'" fi if [ -z "$stat" ] ; then diff --git a/sdk_lib/sdk_container_common.sh b/sdk_lib/sdk_container_common.sh index 55fdcc5b7e..42f68d558c 100644 --- a/sdk_lib/sdk_container_common.sh +++ b/sdk_lib/sdk_container_common.sh @@ -262,8 +262,6 @@ EOF export BOTO_PATH export GOOGLE_APPLICATION_CREDENTIALS } - - # -- # Generate volume mount command line options for docker @@ -294,3 +292,17 @@ function gnupg_ssh_gcloud_mount_opts() { fi fi } +# -- + +function prepend_cleanup() { + local cleanup_file=${1}; shift + local command=${1}; shift + + local tmpfile old + + tmpfile=$(mktemp "${cleanup_file}-XXXXXX") + old=$(cat "${cleanup_file}" 2>/dev/null || :) + printf '%s\n%s\n' "${command}" "${old}" >"${tmpfile}" + mv -f "${tmpfile}" "${cleanup_file}" +} +# --