From ce1699706e98201db73209ee495051359b1d0703 Mon Sep 17 00:00:00 2001 From: stickies-v Date: Wed, 31 May 2023 11:34:15 +0100 Subject: [PATCH 1/2] ci: add label to docker images This allows us or the user to perform batch operations on all images produced by the ci, e.g. to prune all dangling images, without affecting non-ci images. --- ci/test/02_run_container.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ci/test/02_run_container.sh b/ci/test/02_run_container.sh index a7c1e22a6db..c842b15f2e7 100755 --- a/ci/test/02_run_container.sh +++ b/ci/test/02_run_container.sh @@ -5,6 +5,7 @@ # file COPYING or http://www.opensource.org/licenses/mit-license.php. export LC_ALL=C.UTF-8 +export CI_IMAGE_LABEL="bitcoin-ci-test" set -ex @@ -19,6 +20,7 @@ if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then --file "${BASE_READ_ONLY_DIR}/ci/test_imagefile" \ --build-arg "CI_IMAGE_NAME_TAG=${CI_IMAGE_NAME_TAG}" \ --build-arg "FILE_ENV=${FILE_ENV}" \ + --label="${CI_IMAGE_LABEL}" \ --tag="${CONTAINER_NAME}" \ "${BASE_READ_ONLY_DIR}" docker volume create "${CONTAINER_NAME}_ccache" || true From e44c574650827f18e12ac0ba378c0a19d23a07b4 Mon Sep 17 00:00:00 2001 From: stickies-v Date: Wed, 31 May 2023 11:35:45 +0100 Subject: [PATCH 2/2] ci: always prune all dangling bitcoin-ci-test images Since all bitcoin-ci-test images are now labeled, we can always prune all dangling images, regardless of whether we are in RESTART_CI_DOCKER_BEFORE_RUN. To be safe, still prune all images if RESTART_CI_DOCKER_BEFORE_RUN in case the filtering doesn't work, or if images were created on an earlier version that did not assign labels. --- ci/test/02_run_container.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ci/test/02_run_container.sh b/ci/test/02_run_container.sh index c842b15f2e7..a74226b0898 100755 --- a/ci/test/02_run_container.sh +++ b/ci/test/02_run_container.sh @@ -32,9 +32,14 @@ if [ -z "$DANGER_RUN_CI_ON_HOST" ]; then if [ -n "${RESTART_CI_DOCKER_BEFORE_RUN}" ] ; then echo "Restart docker before run to stop and clear all containers started with --rm" podman container rm --force --all # Similar to "systemctl restart docker" + + # Still prune everything in case the filtered pruning doesn't work, or if labels were not set + # on a previous run. Belt and suspenders approach, should be fine to remove in the future. echo "Prune all dangling images" docker image prune --force fi + echo "Prune all dangling $CI_IMAGE_LABEL images" + docker image prune --force --filter "label=$CI_IMAGE_LABEL" # shellcheck disable=SC2086 CI_CONTAINER_ID=$(docker run --cap-add LINUX_IMMUTABLE $CI_CONTAINER_CAP --rm --interactive --detach --tty \