Created
March 7, 2021 16:26
-
-
Save Bharathkumarraju/728109ca8dbc89207ce016319a365649 to your computer and use it in GitHub Desktop.
delete docker images
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 5 images of helloworldapp | |
# 2. Retain last 3 images of bharathterraform | |
# 3. Retain last 2 images of flask_app | |
# | |
#################################################################################################################################### | |
export TOKEN="YmhhcmF0aGt1bWFycmFqdStyYWp1OjAySDQ5WFaskldfnsdkfdsmfsdgfnklsnglsdkgsakdgefgerreprogke" | |
function retain_last_five() { | |
for i in `curl -s -X GET "https://quay.io/api/v1/repository/bharathkumarraju/helloworldapp/tag/" -H 'Authorization: Basic ${TOKEN}' | jq -r .tags | grep -i "name" | awk -F: '{print $2}' | tr -d "\"\," | awk 'NR > 5'` | |
do | |
curl -s -X DELETE "https://quay.io/api/v1/repository/bharathkumarraju/helloworldapp/tag/${i}" -H 'Authorization: Basic ${TOKEN}' | |
done | |
} | |
function retain_last_three() { | |
for i in `curl -s -X GET "https://quay.io/api/v1/repository/bharathkumarraju/bharathterraform/tag/" -H 'Authorization: Basic ${TOKEN}' | jq -r .tags | grep -i "name" | awk -F: '{print $2}' | tr -d "\"\," | awk 'NR > 3'` | |
do | |
curl -s -X DELETE "https://quay.io/api/v1/repository/bharathkumarraju/bharathterraform/tag/${i}" -H 'Authorization: Basic ${TOKEN}' | |
done | |
} | |
function retain_last_two() { | |
for i in `curl -s -X GET "https://quay.io/api/v1/repository/bharathkumarraju/flask_app/tag/" -H 'Authorization: Basic ${TOKEN}' | jq -r .tags | grep -i "name" | awk -F: '{print $2}' | tr -d "\"\," | awk 'NR > 2'` | |
do | |
curl -s -X DELETE "https://quay.io/api/v1/repository/bharathkumarraju/flask_app/tag/${i}" -H 'Authorization: Basic ${TOKEN}' | |
done | |
} | |
retain_last_five | |
retain_last_three | |
retain_last_two |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment