Last active
November 6, 2020 22:12
-
-
Save rkevin-arch/055a90a0b701ef3d3cc5ea6639a38923 to your computer and use it in GitHub Desktop.
Retagging docker images without pulling them. Kinda ugly hack, but it works. Requires curl and jq.
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 -e | |
OLDREPO=youruser/oldrepo | |
OLDTAG=oldtag | |
NEWREPO=youruser/newrepo | |
NEWTAG=newtag | |
USERPASS='youruser:yourpassword' | |
TOKEN=`curl -f "https://auth.docker.io/token?service=registry.docker.io&scope=repository:$NEWREPO:push,pull&scope=repository:$OLDREPO:pull" -u "$USERPASS" | jq -r .token` | |
OLDMANIFEST=`curl -f https://index.docker.io/v2/$OLDREPO/manifests/$OLDTAG -H 'Accept: application/vnd.docker.distribution.manifest.v2+json' -H "Authorization: Bearer $TOKEN"` | |
NEWMANIFEST=`echo "$OLDMANIFEST" | jq "setpath([\"name\"];\"$NEWREPO\")" | jq --indent 3 "setpath([\"tag\"];\"$NEWTAG\")"` | |
for layer in `echo "$OLDMANIFEST" | jq -r '.layers[].digest, .config.digest'`; do | |
echo "Uploading layer $layer" | |
curl -f -X POST "https://index.docker.io/v2/$NEWREPO/blobs/uploads/?mount=$layer&from=$OLDREPO" -H "Authorization: Bearer $TOKEN" | |
done | |
curl -D- -X PUT https://index.docker.io/v2/$NEWREPO/manifests/$NEWTAG -H "Content-Type: application/vnd.docker.distribution.manifest.v2+json" -d "$NEWMANIFEST" -H "Authorization: Bearer $TOKEN" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment