Created
March 7, 2021 16:27
-
-
Save Bharathkumarraju/5d579f28e995ae1b8fd7669f9fc930ec to your computer and use it in GitHub Desktop.
delete docker images improved
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
#!/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