Last active
October 14, 2024 15:52
-
-
Save caruccio/3b75b74bbe7249a1ce7eb0bb5b90aa64 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
if [ $# -lt 2 ]; then | |
echo Usage: $0 NEW-REGISTRY NEW-OWNER [push] | |
exit 1 | |
fi | |
new_registry="$1" | |
new_owner="$2" | |
push="$3" | |
docker images --format '{{.Repository}}:{{.Tag}}' \ | |
| grep -E '^(docker.io|quay.io|ghcr.io|k8s.gcr.io)/' \ | |
| grep -v ':<none>$' \ | |
| sort -u \ | |
| while read image; do | |
# registry/image:tag | |
image_name=${image#*/} | |
image_name=${image_name%:*} | |
image_tag=${image##*:} | |
if [[ $image =~ [^/]+/[^/]+/[^/]+:.* ]]; then | |
# registry/owner/image:tag | |
image_name=${image_name%/*}_${image_name#*/} | |
fi | |
new_image=$new_registry/$new_owner/$image_name:$image_tag | |
if [ "$push" == push ]; then | |
docker tag $image $new_image | |
docker push $new_image | |
else | |
echo docker tag $image $new_image | |
echo docker push $new_image | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment