Skip to content

Instantly share code, notes, and snippets.

@rblaine95
Last active July 20, 2018 11:58
Show Gist options
  • Save rblaine95/db64c411000f33d84e806cdc2af5a04a to your computer and use it in GitHub Desktop.
Save rblaine95/db64c411000f33d84e806cdc2af5a04a to your computer and use it in GitHub Desktop.
Pull all images+tags belonging to $repo on $old registry, tag the images with $new registry name, push all images to $new registry, and delete the images after
#!/bin/bash
$old=old.registry.net:5000
$new=new.registry.net:5000
$repo=""
# Batch pull, tag, push, delete
batch() {
for x in `wget -q http://$old/v2/_catalog -O - | sed -e 's/[][]//g' -e 's/\,/\n/g' -e 's/\"//g' -e 's/\}//g' | grep $repo | tr '\n' ' '`; do docker pull $old/$x -a; done
docker images | grep $old | awk -F' ' '{ print $1":"$2 }' | awk -F '/' '{ print "docker tag "$1"/"$2"/"$3" $new/"$2"/"$3 }' | xargs -L 1 xargs
docker images | grep $new | awk -F' ' '{ print $1":"$2 }' | awk -F '/' '{ print "docker push "$1"/"$2"/"$3 }' | xargs -L 1 xargs
docker images | grep $old | awk -F' ' '{ print "docker rmi -f " $3 }' | xargs -L 1 xargs
}
# Pull 1 image at a time, tag, push, delete
stream() {
for x in `wget -q http://$old/v2/_catalog -O - | sed -e 's/[][]//g' -e 's/\,/\n/g' -e 's/\"//g' -e 's/\}//g' | grep $repo | tr '\n' ' '`; do
docker pull $old/$x -a
docker images | grep $old/$x | awk -F' ' '{ print $1":"$2 }' | awk -F '/' '{ print "docker tag "$1"/"$2"/"$3" $new/"$2"/"$3 }' | xargs -L 1 xargs
docker images | grep $new/$x | awk -F' ' '{ print $1":"$2 }' | awk -F '/' '{ print "docker push "$1"/"$2"/"$3 }' | xargs -L 1 xargs
docker images | grep $x | awk -F' ' '{ print "docker rmi -f " $3 }' | xargs -L 1 xargs
done
}
main() {
echo "[========================]"
echo "Batch or Stream migration?"
echo "[========================]"
read -p "Enter: " bs
case $bs in
[bB]* )
batch;;
[sS]* )
stream;;
* ) exit 1;;
esac
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment