diff --git a/Scripts/ci-bundles/.gitignore b/Scripts/ci-bundles/.gitignore index 0f2e1a8de7d6869aa9119e56202bdfe97fac261e..8028a3a27b693a1ab17aa21fb1f5174585dc0dcd 100644 --- a/Scripts/ci-bundles/.gitignore +++ b/Scripts/ci-bundles/.gitignore @@ -3,5 +3,8 @@ rclone-cmb-ci # Mount point for `rclone`. rclone-mount/ +# Script to actually delete images. See `curl-delete.in` +curl-delete + # Intermediate file for DockerHub pruning. all-tags diff --git a/Scripts/ci-bundles/curl-delete.in b/Scripts/ci-bundles/curl-delete.in new file mode 100755 index 0000000000000000000000000000000000000000..ac9d76a24ef027572086e4b716d078458798773e --- /dev/null +++ b/Scripts/ci-bundles/curl-delete.in @@ -0,0 +1,19 @@ +#!/bin/sh + +set -e + +# To use this script: +# +# 1. Go to the DockerHub repository management interface +# 2. Enable the network tab of your browser's Developer Tools. +# 3. Perform the deletion of an eligible tag (run the +# `./rm-stale-dockerhub-tags.bash` script without arguments to discover +# one). +# 4. After submitting the form, right click on the `DELETE` query performed by +# the form, right click and select "Copy as cURL" (or similar). +# 5. Save this file as `curl-delete` and paste the command at the end. +# 6. Remove the `-H 'Content-Length: …' argument. +# 7. Append with `"$@"` to forward arguments to the `curl` command (to pass +# data). +# 8. There is an embedded JWT in the query that expires after an hour (at most) +# that will need refreshing and restarting these steps. diff --git a/Scripts/ci-bundles/dockerhub-keep-tags b/Scripts/ci-bundles/dockerhub-keep-tags index f300f5a6d876e95b768430299c124a435c5595b0..3e978854f0724a65f80cf706998f2cb2bafcb7d2 100644 --- a/Scripts/ci-bundles/dockerhub-keep-tags +++ b/Scripts/ci-bundles/dockerhub-keep-tags @@ -241,3 +241,4 @@ ci-superbuild-centos7-20220519 ci-superbuild-centos7-20240312 ci-superbuild-centos7-latest ci-superbuild-fedora32-girder +ci-superbuild-fedora36-girder diff --git a/Scripts/ci-bundles/rm-stale-dockerhub-tags.bash b/Scripts/ci-bundles/rm-stale-dockerhub-tags.bash index b61f88ccfaee27d300f641f41b65e431199632ff..b20aa3041976e6108290c0c5b391d01aff3e818e 100755 --- a/Scripts/ci-bundles/rm-stale-dockerhub-tags.bash +++ b/Scripts/ci-bundles/rm-stale-dockerhub-tags.bash @@ -44,9 +44,20 @@ echo "Keeping images with dates newer than '$two_weeks_ago'" undeleted_size=0 deleted_size=0 for unused_tag in $unused_tags; do + date_tag="$( echo "$unused_tag" | rev | cut -d- -f1 | rev )" + if [[ "$date_tag" =~ [^0-9]+ ]]; then + echo "Non-date tag appears unused: '$unused_tag'$size_text" + continue + fi + + if $size || $delete; then + inspect="$( skopeo inspect "docker://docker.io/$repo:$unused_tag" )" + else + inspect='{}' + fi size_text= if $size; then - image_size="$( skopeo inspect "docker://docker.io/$repo:$unused_tag" | + image_size="$( echo "$inspect" | jq .LayersData.[].Size | paste -sd+ | bc )" @@ -54,15 +65,14 @@ for unused_tag in $unused_tags; do size_text=" ($image_size bytes; $( echo "$image_size" | numfmt --to=iec ))" fi - date_tag="$( echo "$unused_tag" | rev | cut -d- -f1 | rev )" - if [[ "$date_tag" =~ [^0-9]+ ]]; then - echo "Non-date tag appears unused: '$unused_tag'$size_text" - continue - fi if [ "$date_tag" -lt "$two_weeks_ago" ]; then if $delete; then echo "Deleting unused tag '$unused_tag'$size_text" - skopeo --override-os linux delete "docker://docker.io/$repo:$unused_tag" + digest="$( echo "$inspect" | jq -r .Digest )" + data='{"digests":["'"$digest"'"],"delete_references":true}' + length="$( echo -n "$data" | wc -c )" + ./curl-delete --data "$data" -H "Content-Length: $length" + # skopeo --override-os linux delete "docker://docker.io/$repo:$unused_tag" else echo "Would delete unused tag '$unused_tag'$size_text" fi