Skip to content

Instantly share code, notes, and snippets.

@pikatenor
Created May 13, 2018 11:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pikatenor/cc5d1812e2d567905372e4b3d8e82826 to your computer and use it in GitHub Desktop.
Save pikatenor/cc5d1812e2d567905372e4b3d8e82826 to your computer and use it in GitHub Desktop.
private docker registry のイメージ消すやつ
#!/bin/bash
set -e
set -o pipefail
function usage {
cat <<EOF
Usage:
$(basename ${0}) [<options>] [registry]
Options:
-i [name] image name (required)
-t [tag] tag (default: latest)
-u [user] basic auth username
-p [pass] basic auth password
-h show this help
EOF
exit 1
}
image=false
tag=latest
user=false
password=false
schema="https://"
while getopts i:t:u:p:h OPT
do
case $OPT in
i) image=$OPTARG;;
t) tag=$OPTARG;;
u) user=$OPTARG;;
p) password=$OPTARG;;
h) usage;;
:|\?) usage;;
esac
done
shift $((OPTIND - 1))
if ! [ $image ]
then
echo 'image name is required.'
exit 1
fi
if ! [ $1 ]
then
echo 'registry is required.'
exit 1
fi
if [ $user ] && [ $password ]
then
registry="${schema}${user}:${password}@${1}"
else
registry="${schema}${1}"
fi
digest=$(
curl -sSL -I \
-H "Accept: application/vnd.docker.distribution.manifest.v2+json" \
"$registry/v2/$image/manifests/$tag" \
| awk '$1 == "Docker-Content-Digest:" { print $2 }' \
| tr -d $'\r'
)
curl -sSL -X DELETE "$registry/v2/$image/manifests/$digest"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment