Created
April 25, 2019 13:26
-
-
Save ilosamart/aede6c1f0aca4e62c065eeead43192b6 to your computer and use it in GitHub Desktop.
clean a docker registry
This file contains hidden or 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
#!/bin/bash | |
############################################################ | |
# Limpa 'docker registry' (últimas 2 imagens ficam) | |
############################################################ | |
# esse carinha depende do https://github.com/dominictarr/JSON.sh | |
REGISTRY_URL=${1:-http://localhost:8082} | |
REGISTRY_DATA_VOLUME=${2:-/var/www/docker-registry-data} | |
IMAGES_TO_KEEP=${3:-2} | |
for image in $(curl -X GET ${REGISTRY_URL}/v2/_catalog -s | JSON.sh | grep '"repositories",' | cut -d'"' -f4); do | |
echo $image | grep uai | |
if [ $? -eq 0 ]; then | |
for tag in $(ls -1 ${REGISTRY_DATA_VOLUME}/docker/registry/v2/repositories/${image}/_manifests/tags/ | sort -V | head -n -2); do | |
sha=$(cat ${REGISTRY_DATA_VOLUME}/docker/registry/v2/repositories/${image}/_manifests/tags/${tag}/current/link) | |
echo TCHAU $image $tag $sha | |
curl -sk -XDELETE ${REGISTRY_URL}/v2/${image}/manifests/${sha} | |
done | |
fi | |
done | |
docker exec -it registry registry garbage-collect -d /etc/docker/registry/config.yml > /var/log/uai-docker_cleanup.log | |
docker exec -it registry registry garbage-collect /etc/docker/registry/config.yml |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment