Skip to content

Instantly share code, notes, and snippets.

@rdpanek
Forked from kizbitz/dockerhub-v2-api-user.sh
Last active November 2, 2017 15:53
Show Gist options
  • Save rdpanek/757ffae33246d322634725529fdf79d7 to your computer and use it in GitHub Desktop.
Save rdpanek/757ffae33246d322634725529fdf79d7 to your computer and use it in GitHub Desktop.
Get the list of images and tags for a Docker Hub user account.
#!/bin/bash
# kubectl get deployments monitor -o json | jq '.spec.template.spec.containers[0].image'
# kubectl set image deployment/monitor monitor=rdpanek/monitor:develop-22ca149b
# set username and password
UNAME=""
UPASS=""
# -------
set -e
echo
# aquire token
TOKEN=$(curl -s -H "Content-Type: application/json" -X POST -d '{"username": "'${UNAME}'", "password": "'${UPASS}'"}' https://hub.docker.com/v2/users/login/ | jq -r .token)
# get tags for repo
IMAGE_TAGS=$(curl -s -H "Authorization: JWT ${TOKEN}" https://hub.docker.com/v2/repositories/rdpanek/monitor/tags/?page_size=100 | jq -r '.results|.[0]|.name')
IMAGE='"rdpanek/monitor:'${IMAGE_TAGS}'"'
echo $IMAGE
KUBE_DEPLOYMENTS=$(kubectl get deployments monitor -o json | jq '.spec.template.spec.containers[0].image')
echo $KUBE_DEPLOYMENTS
if [ ${IMAGE} == $KUBE_DEPLOYMENTS ] ; then
echo "existuje ${IMAGE}"
else
echo "neexistuje ${IMAGE}"
echo $(kubectl set image deployment/monitor monitor=rdpanek/monitor:${IMAGE_TAGS})
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment