Last active 4 months ago

Script for cleanup ecr

botanikanet revised this gist 4 months ago. Go to revision

No changes

botanikanet revised this gist 8 months ago. Go to revision

1 file changed, 2 insertions

ecr_cleanup.txt(file created)

@@ -0,0 +1,2 @@
1 + aws ecr get-login-password | docker login --username AWS --password-stdin $(aws ecr describe-registry --query registryId --output text).dkr.ecr.eu-west-1.amazonaws.com
2 + for REPOSITORY in $(aws ecr describe-repositories | jq -r '.repositories[].repositoryName'); do echo "${REPOSITORY}"; aws ecr describe-images --repository-name ${REPOSITORY} | jq --arg pull_t $(date +%Y-%m-%dT00:00:00 -d '1 months ago') --arg push_t $(date +%Y-%m-%dT00:00:00 -d '3 months ago') '.imageDetails|sort_by(.imagePushedAt) [:-20] | .[] | select(.lastRecordedPullTime? | . <= $pull_t ) | select(.imagePushedAt | . <= $push_t ) | "imageDigest=\(.imageDigest)"' | tr '\n' ' ' | xargs -n 99 -r aws ecr batch-delete-image --no-cli-pager --repository-name ${REPOSITORY} --image-ids; done
Newer Older