Created
January 21, 2016 12:12
-
-
Save zuzkins/0429f7ea487bb236c7d6 to your computer and use it in GitHub Desktop.
Simple script which will pull all tagged images from given docker registry which have in repository name "library". It will remove the "library" part and push the images back to the 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 | |
CREDENTIALS="" | |
if [ ! -z "$DOCKER_USER" ] && [ ! -z "$DOCKER_PWD" ]; then | |
CREDENTIALS="$DOCKER_USER:$DOCKER_PWD@" | |
fi | |
if [ ! -z "$CREDENTIALS" ]; then | |
docker login -u "$DOCKER_USER" -p "$DOCKER_PWD" -e "test@email.my" "$DOCKER_REGISTRY" | |
fi | |
if [ -z "$DOCKER_REGISTRY" ]; then | |
echo "MISSING DOCKER_REGISTRY env variable." | |
exit 1 | |
fi | |
REGISTRY_URL="https://$CREDENTIALS$DOCKER_REGISTRY" | |
REPOS=$(curl -fs "${REGISTRY_URL}/v2/_catalog" | jq -r '.repositories|.[]') | |
for r in ${REPOS} | |
do | |
if [[ "$r" == library* ]]; then | |
IMAGE_TAGS=$(curl -fs "${REGISTRY_URL}/v2/$r/tags/list" | jq -r '.tags|.[]') | |
for tag in ${IMAGE_TAGS} | |
do | |
IMAGE="$DOCKER_REGISTRY/$r:$tag" | |
(docker pull ${IMAGE} && echo -e "OK Successfully pulled ${IMAGE}\n") | |
NEW_IMAGE="${IMAGE//library\/}" # remove the "library/" repository from the image name | |
(docker tag ${IMAGE} ${NEW_IMAGE}) | |
(docker push ${NEW_IMAGE} && echo -e "OK Successfully pushed ${NEW_IMAGE}\n") | |
done | |
else | |
echo "Repository [$r] is not a library repository, skipping" | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment