summaryrefslogtreecommitdiff
path: root/tcwg-cleanup-stale-containers.sh
diff options
context:
space:
mode:
authorMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2021-01-04 07:26:05 +0000
committerMaxim Kuvyrkov <maxim.kuvyrkov@linaro.org>2021-01-04 07:34:11 +0000
commit49acfb8a50661b74f64352914b48b259be6bef38 (patch)
tree5ece50430bdecc8b0d326e461494a85093bad580 /tcwg-cleanup-stale-containers.sh
parent7654f42e2d36c49b388abc653c5017170eea3ce1 (diff)
Docker image pull: Fix removing previously untagged images
... and update "pull" timestamps in tcwg-start-container.sh Change-Id: Ib5638a9fb22c341527443fd3ff2f8431f7aa1fe0
Diffstat (limited to 'tcwg-cleanup-stale-containers.sh')
-rwxr-xr-xtcwg-cleanup-stale-containers.sh9
1 files changed, 6 insertions, 3 deletions
diff --git a/tcwg-cleanup-stale-containers.sh b/tcwg-cleanup-stale-containers.sh
index cc89a01e..84f4a5ea 100755
--- a/tcwg-cleanup-stale-containers.sh
+++ b/tcwg-cleanup-stale-containers.sh
@@ -180,14 +180,17 @@ if $cleanup_images; then
stamp_dir=/home/shared/docker
# Untag and prune images that haven't been used for 3 days or more.
- for image in $(docker images --format "{{.Repository}}:{{.Tag}}"); do
+ for image_tuple in $(docker images --format "{{.ID}}:{{.Repository}}:{{.Tag}}"); do
+ image_id=$(echo "$image_tuple" | cut -d: -f 1)
+ image=$(echo "$image_tuple" | cut -d: -f 2,3)
image_stamp="$stamp_dir/$(echo "$image" | tr "/:" "_")"
remove_if_not_used_since=$(($(date +%s) - 3*24*60*60))
# Use negative comparison to handle non-existent stamp files.
if ! [ "$(stat -c %Z "$image_stamp.use")" \
-gt $remove_if_not_used_since ] 2>/dev/null; then
- # Untag the image.
- docker rmi -f "$image"
+ # Untag the image. Use $image_id to handle previously-untagged
+ # images and other cases when we have no repo or tag reference.
+ docker rmi -f "$image_id"
fi
done
# Prune untagged images.