-
-
Save zsiddiqi/b54dd0000ea3c76c9e575f78b4f4aa25 to your computer and use it in GitHub Desktop.
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 | |
set -x | |
S3_ROOT=/Users/gbougeard/REGISTRY/data | |
DIR_REPOSITORIES=docker/registry/v2/repositories | |
DIR_TAGS=_manifests/tags | |
DIR_REVISIONS=_manifests/revisions | |
DIR_BLOBS=docker/registry/v2/blobs | |
PATH_REPOSITORIES=${S3_ROOT}/${DIR_REPOSITORIES} | |
rm -rf ./total | |
for IMAGE in $(ls -1 ${PATH_REPOSITORIES}); do | |
PATH_TAGS=${S3_ROOT}/${DIR_REPOSITORIES}/${IMAGE}/${DIR_TAGS} | |
PATH_REVISIONS=${S3_ROOT}/${DIR_REPOSITORIES}/${IMAGE}/${DIR_REVISIONS} | |
PATH_BLOBS=${S3_ROOT}/${DIR_BLOBS} | |
rm -f ./${IMAGE}-hash2delete | |
touch ./${IMAGE}-hash2delete | |
for tag in $(ls -1 ${PATH_TAGS}); do | |
echo "Tag ${tag}" | |
image_hash=$(cat ${PATH_TAGS}/${tag}/current/link | sed 's|sha256:||') | |
echo "Current hash is ${image_hash}" | |
index_hashes=$(ls -1 ${PATH_TAGS}/${tag}/index/sha256 | grep -v ${image_hash}) | |
if [ -z "${index_hashes}" ];then echo "No hash to clean";continue;fi | |
echo "-----------------------" | |
nb_hash_to_delete=$(echo ${index_hashes} | wc -w) | |
echo "There are ${nb_hash_to_delete} hashes to delete" | |
for hash in ${index_hashes}; do | |
echo "Deleting index hash ${PATH_TAGS}/${tag}/index/sha256/${hash}" | |
#rm -rf ${PATH_TAGS}/${tag}/index/sha256/${hash} | |
echo "Deleting revision hash ${PATH_REVISIONS}/sha256/${hash}" | |
#rm -rf ${PATH_REVISIONS}/sha256/${hash} | |
jq -r '.config.digest' "${PATH_BLOBS}/sha256/${hash:0:2}/$hash/data" | sed 's|sha256:||' >> ./${IMAGE}-hash2delete | |
jq -r '.layers[].digest' "${PATH_BLOBS}/sha256/${hash:0:2}/$hash/data" | sed 's|sha256:||' >> ./${IMAGE}-hash2delete | |
done | |
echo "==============================" | |
done | |
sort ${IMAGE}-hash2delete | uniq > ${IMAGE}-hash2delete | |
rm -f ./${IMAGE}-path2delete | |
for hash in $(cat ${IMAGE}-hash2delete); do | |
echo "${PATH_BLOBS}/sha256/${hash:0:2}/$hash" >> ./${IMAGE}-path2delete | |
done | |
if [ ! -f ./${IMAGE}-path2delete ];then echo "Nothing to clean";continue;fi | |
echo "$(du -hc $(cat ./${IMAGE}-path2delete) | tail -n1 | cut -f1) ${IMAGE}" >> ./total | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment