Created
February 15, 2017 01:19
-
-
Save chubas/ca4132ce8fd6fb29f3d2ae076ab87ee5 to your computer and use it in GitHub Desktop.
Tag exists?
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
#! /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