Skip to content

Instantly share code, notes, and snippets.

@sjeandeaux
Created June 13, 2017 07:02
Show Gist options
  • Save sjeandeaux/4f92542c602c6b2398f9ffc9105eadc8 to your computer and use it in GitHub Desktop.
Save sjeandeaux/4f92542c602c6b2398f9ffc9105eadc8 to your computer and use it in GitHub Desktop.
Transfer your images docker from registry v1 to registry v2
#!/bin/bash
# No verification but we need:
# - to be able to run docker command
# - we use jq (https://stedolan.github.io/jq/manual/)
# Transfer image to docker registry v1 to docker registry v2
# TODO manage parameters
# TODO manage insecure (actually curl -k)
# TODO manage pagination
# TODO manage namespace "library/"
# TODO manage failures
# TODO protocol (actually HTTPS)
# TODO to implement in go
v1_registry=${1-"localhost:5000"}
v2_registry=${2-"localhost:5001"}
v1_login_password=${3-":"}
v2_login_password=${4-":"}
nb=${5-200}
images=$(curl -sk "https://$v1_registry/v1/search?q=&n=$nb" | jq -r '.results | .[] | .name')
function processTag() {
echo "-----------------------------------------"
echo "'"$1"'"
echo "'"$2"'"
echo "'"$3"'"
echo "-----------------------------------------"
for i in $2
do
found=false
for j in $3
do
if [ "$j" == "$i" ]; then
found=true
fi
done
if [ "$found" == "false" ]; then
echo -e '\e[31m' $i '\e[0m'
transfer "$v1_registry/$1:$i" "$v2_registry/$1:$i"
fi
done
}
function remove-prefix-library() {
if [ "${1:0:8}" = "library/" ]; then
echo "${1:8}"
else
echo $1
fi
}
function transfer() {
docker pull $1 || true
docker tag $1 $2 || true
docker push $2 || true
docker rmi $1 || true
docker rmi $2 || true
}
function processImage() {
i=${1/252F/2F}
i=$(remove-prefix-library $i)
old_tags=$(curl -sk "https://$v1_login_password@$v1_registry/v1/repositories/$i/tags" | jq -r 'try(keys | .[])')
tags=$(curl -sk "https://$v2_login_password@$v2_registry/v2/$i/tags/list" | jq -r 'try(.tags | .[])')
processTag "$(remove-prefix-library $i)" "$old_tags" "$tags"
}
for i in $images
do
processImage "$i"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment