aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfanquake <fanquake@gmail.com>2023-10-15 10:48:28 +0200
committerfanquake <fanquake@gmail.com>2023-10-15 10:48:37 +0200
commitcee39d06288f34258b96dabfc86b1fd0d7d96f53 (patch)
treeca98257bac408e299f975b021139f9c937762fc9
parent78b7e955185ab92de4e1b8b866a46d3113a5fdf5 (diff)
parente44c574650827f18e12ac0ba378c0a19d23a07b4 (diff)
Merge bitcoin/bitcoin#27793: ci: label docker images and prune dangling images selectively
e44c574650827f18e12ac0ba378c0a19d23a07b4 ci: always prune all dangling bitcoin-ci-test images (stickies-v) ce1699706e98201db73209ee495051359b1d0703 ci: add label to docker images (stickies-v) Pull request description: Follow-up from https://github.com/bitcoin/bitcoin/pull/27777#discussion_r1210209382. Labeling the docker images produced by the CI allows us/the user to apply batch operations to all images (including dangling ones) produced by the ci without affecting other, non-bitcoin-ci images. With labeling, we can safely always prune dangling bitcoin-ci-test images without checking for `RESTART_CI_DOCKER_BEFORE_RUN`, which we enable on our persistent runners. ACKs for top commit: fanquake: utACK e44c574650827f18e12ac0ba378c0a19d23a07b4 Tree-SHA512: 1009fb1be78fbc80b5341ba92eac2991e77d050e1ab6048d1d9a65af73413a6be7afc1e1c764eb3f347f363af31245b93fdb38f6ac016d775aad4a0f36e4c98f
-rwxr-xr-xci/test/02_run_container.sh7
1 files changed, 7 insertions, 0 deletions
diff --git a/ci/test/02_run_container.sh b/ci/test/02_run_container.sh
index a7c1e22a6d..a74226b089 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
@@ -30,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 \