Created
April 15, 2020 16:28
-
-
Save hdonnay/594de058da6933e3f8cd1edb4796ace4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set -euo pipefail | |
: "${name:=projectquay/clair}" | |
: "${prefix:=git-}" | |
dir=$(mktemp -d) | |
trap "rm -rf '${dir}'" EXIT | |
git log --format "tformat:${prefix}%h" --max-count=50 | | |
sort|uniq > "${dir}/git" | |
curl -s "https://quay.io/v2/${name}/tags/list" | | |
jq -r '."tags"[]' | | |
grep "^${prefix}" | | |
sort|uniq > "${dir}/repo" | |
comm -2 -3 "${dir}/repo" "${dir}/git" > "${dir}/rm" | |
test "$(wc -l < "${dir}/rm")" -eq 0 && exit 0 | |
printf 'removing these tags:\n' >&2 | |
sed 's/^/ /' < "${dir}/rm" >&2 | |
docker login -u "${QUAY_USER}" -p '${{ secrets.QUAY_TOKEN }}' quay.io | |
cat <<. > "${dir}/delete-tags" | |
silent | |
request = DELETE | |
header = "Authorization: Bearer $(jq -r'.auths."quay.io".auth'\ | |
< ~/.docker/config.json)" | |
. | |
cat <<. > "${dir}/resolve-tags" | |
silent | |
header="Accept: application/vnd.docker.distribution.manifest.v2+json" | |
. | |
while read tag; do | |
printf 'url = "https://quay.io/v2/%s/manifests/%s"\n' \ | |
"$name" "$tag" >> "${dir}/resolve-tags" | |
done < "${dir}/rm" | |
curl --config "${dir}/resolve-tags" | | |
jq -r ".config.digest // empty | | |
\"url = \\\"https://quay.io/v2/${name}/manifests/\(.)\\\"\"" \ | |
>> "${dir}/delete-tags" | |
curl --config "${dir}/delete-tags" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment