Skip to content

Instantly share code, notes, and snippets.

@chubas
Created February 15, 2017 01:19
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 chubas/ca4132ce8fd6fb29f3d2ae076ab87ee5 to your computer and use it in GitHub Desktop.
Save chubas/ca4132ce8fd6fb29f3d2ae076ab87ee5 to your computer and use it in GitHub Desktop.
Tag exists?
#! /usr/bin/env bash
# USAGE:
# Replace your dockerhub credentials on DOCKER_HUB_USERNAME and DOCKER_HUB_PASSWORD
# Invoke from the directory you want to check against
#
# e.g. [/home/skycatch/core]$ ../tools/tag-exists.sh
# > Tag exists: core/8d5b62
#
# Requires `jq` to be installed (brew install jq)
DOCKER_HUB_USERNAME=mydockerhub@user.com
DOCKER_HUB_PASSWORD=xxxxxpasswordxxxxx
DOCKER_TAG=$(git rev-parse --short HEAD)
DOCKER_REPO=$(basename $(pwd))
TOKEN=$( curl -sSLd "username=${DOCKER_HUB_USERNAME}&password=${DOCKER_HUB_PASSWORD}" https://hub.docker.com/v2/users/login | jq -r ".token" )
if (curl -sH "Authorization: JWT $TOKEN" "https://hub.docker.com/v2/repositories/skycatch/${DOCKER_REPO}/tags/?page_size=100" | jq -r '.results|.[]|.name' | grep ${DOCKER_TAG} )
then
echo "Tag exists: ${DOCKER_REPO}/${DOCKER_TAG}"
else
echo "Tag DOES NOT exist: ${DOCKER_REPO}/${DOCKER_TAG}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment