#!/bin/bash
# yum install -y jq
mkdir tmp
# 仓库的认证信息
auth_key="user:password"
# 仓库的地址
base_url="http://you-registry-url:5000/v2"
header="Accept:application/vnd.docker.distribution.manifest.v2+json"
curl --header ${header} -u${auth_key} ${base_url}/_catalog| jq ".repositories" > tmp/repositories.json
# 保留的仓库路径
cat tmp/repositories.json |egrep -v "base\/|oa\/|\[|\]"|sed "s/,//g;s/\"//g" > tmp/repositories.txt
cat tmp/repositories.txt |while read line
do
curl --header ${header} -u${auth_key} ${base_url}/$line/tags/list|jq ".tags" > tmp/tags.json
cat tmp/tags.json |egrep -v "202208|base\/|oa\/|\[|\]"|sed "s/,//g;s/\"//g" > tmp/tags.txt
cat tmp/tags.txt |while read tag
do
digest_hash=$(curl --header ${header} -u${auth_key} -I -XGET ${base_url}/$line/manifests/$tag|grep Digest|awk '{print $NF}')
curl -u${auth_key} -I -XDELETE ${base_url}/$line/manifests/${digest_hash%$'\r'} -k
done
done
docker exec -it registry registry garbage-collect /etc/docker/registry/config.yml | grep "blob eligible for deletion:" | awk -F ":" '{print $3}'
registry仓库清理脚本
于 2022-08-12 11:35:13 首次发布