Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Bharathkumarraju/5d579f28e995ae1b8fd7669f9fc930ec to your computer and use it in GitHub Desktop.
Save Bharathkumarraju/5d579f28e995ae1b8fd7669f9fc930ec to your computer and use it in GitHub Desktop.
delete docker images improved
#!/usr/bin/env bash
####################################################################################################################################
# Delete docker specific tagged images
# 1. Retain last n images
#
####################################################################################################################################
export TOKEN="YmhhcmF0aGt1bWFycmFqdStyYWp1OjAySDQ5Wlsalgsdgjdsjgldshgoergxzvlzkxvljoigfejsglskzxmvklfdsajpgrjgd"
function retain_last_n() {
app=$1
number_of_images=$2
for i in `curl -s -X GET "https://quay.io/api/v1/repository/bharathkumarraju/${app}/tag/" -H 'Authorization: Basic ${TOKEN}' | jq -r .tags | grep -i "name" | awk -F: '{print $2}' | tr -d "\"\," | awk 'NR > ${number_of_images}'`
do
curl -s -X DELETE "https://quay.io/api/v1/repository/bharathkumarraju/${app}/tag/${i}" -H 'Authorization: Basic ${TOKEN}'
done
}
retain_last_n helloworldapp 5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment