Created
May 13, 2018 11:03
-
-
Save pikatenor/cc5d1812e2d567905372e4b3d8e82826 to your computer and use it in GitHub Desktop.
private docker registry のイメージ消すやつ
This file contains 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 -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