Skip to content

Instantly share code, notes, and snippets.

@charlesmims
Created March 27, 2017 18:39
Show Gist options
  • Save charlesmims/2ee7a76be255d79fe1e051403dd89cf6 to your computer and use it in GitHub Desktop.
Save charlesmims/2ee7a76be255d79fe1e051403dd89cf6 to your computer and use it in GitHub Desktop.
#!/bin/bash
# 2017-03-27 [email protected]
if [ $# -lt 1 ]
then
cat << HELP
dockertags -- list all tags for a Docker image
EXAMPLE:
- list all tags for charlesmims/alps
dockertags charlesmims/alps
HELP
exit 1
fi
if ! [ -x "$(command -v jq)" ]; then
echo 'apt-get install jq' >&2
exit 1
fi
if [ -z ${UNAME+x} ]; then
echo -n "Docker Username: "
read "UNAME"
fi
if [ -z ${UPASS+x} ]; then
echo -n "Docker Password: "
read -s "UPASS"
fi
getToken() {
local reponame=$1
local actions=$2
local headers
local response
if [ -n "$UNAME" ]; then
headers="Authorization: Basic $(echo -n "${UNAME}:${UPASS}" | base64)"
fi
response=$(curl -s -H "$headers" "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$reponame:$actions")
echo $response | jq '.token' | xargs echo
}
getTags() {
local reponame=$1
local token=$(getToken $reponame "pull")
curl -sH "Authorization: Bearer $token" "https://registry-1.docker.io/v2/$reponame/tags/list" | jq -c '.tags'
}
getTags $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment