Skip to content

Instantly share code, notes, and snippets.

@werty1st
Created October 7, 2020 15:26
Show Gist options
  • Save werty1st/dfa71fcadf55e2a94567b35889cde786 to your computer and use it in GitHub Desktop.
Save werty1st/dfa71fcadf55e2a94567b35889cde786 to your computer and use it in GitHub Desktop.
tag docker image without downloading it (private gitlab registry)
AUTHURL="https://gitlab.de"
REGISTRY_NAME="https://reg.gitlab.de"
CONTENT_TYPE="application/vnd.docker.distribution.manifest.v2+json"
REPOSITORY="myrepo/ts1"
TAG_OLD="test"
TAG_NEW="latest"
USERNAME="test-tag-latest"
PASSWORD="sdfsdfdsfsdfsdf"
# Fetch JWT token
TOKEN=$(curl --silent --user ${USERNAME}:${PASSWORD} \
-G ${AUTHURL}/jwt/auth \
-d service=container_registry \
-d scope="repository:${REPOSITORY}:push,pull,delete" \
| jq -r '.token')
# oder
#TOKEN=$CI_JOB_TOKEN #not tested but may work
BEARER="Authorization:Bearer $TOKEN"
MANIFEST=$(curl -H "$BEARER" -H "Accept: ${CONTENT_TYPE}" "${REGISTRY_NAME}/v2/${REPOSITORY}/manifests/${TAG_OLD}")
curl -X PUT -H "$BEARER" -H "Content-Type: ${CONTENT_TYPE}" -d "${MANIFEST}" "${REGISTRY_NAME}/v2/${REPOSITORY}/manifests/${TAG_NEW}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment