Skip to content

Instantly share code, notes, and snippets.

@rpherrera
Last active April 6, 2017 11:47
Show Gist options
  • Save rpherrera/ea44f886ce65a55ebddb to your computer and use it in GitHub Desktop.
Save rpherrera/ea44f886ce65a55ebddb to your computer and use it in GitHub Desktop.
Wipeout all Docker Images found into an AWS account from ECR private registry, parsing results with jq.
#!/bin/bash -ex
# Warning: use with caution! Once ran, this script is going to wipeout all
# images that you own into your AWS ECR.
aws ecr describe-repositories | jq '.repositories[].repositoryName' | sed s/\"//g | while read repository_name; do
batch_delete_string=''
aws ecr list-images --repository-name "${repository_name}" | \
jq '.imageIds[].imageTag' | while read image_tag; do
batch_delete_string="imageTag=${image_tag} "
done
if [ ! -z "${batch_delete_string}" ]; then
aws ecr batch-delete-image \
--repository-name "${repository_name}" \
--image-ids "${batch_delete_string}"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment