Skip to content

Instantly share code, notes, and snippets.

@NorbertFenk
Last active July 2, 2019 17:25
Show Gist options
  • Save NorbertFenk/813648fb2ebcac0a7128c5acfed75f43 to your computer and use it in GitHub Desktop.
Save NorbertFenk/813648fb2ebcac0a7128c5acfed75f43 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# According to this documentation https://cloud.google.com/container-registry/docs/managing you can move images
# but the gcloud command with add tag option will handle only one tag at a time
# The "if while for" magic will handle multiple tags by retagging the same image.
# Supported input which is provided by the list-tags command:
# 0.2.63
# 0.2.60;0.2.61
# 0.2.59
TAGS=`gcloud container images list-tags --format='get(tags)' [SOURCE_HOSTNAME]/[SOURCE_PROJECT-ID]/[SOURCE_IMAGE]`
while IFS= read -r imageVersion || [[ -n "$imageVersion" ]]; do
if [[ $imageVersion == *";"* ]]; then
while IFS=';' read -ra ADDR; do
for i in "${ADDR[@]}"; do
yes | gcloud container images add-tag [SOURCE_HOSTNAME]/[SOURCE_PROJECT-ID]/[SOURCE_IMAGE]:$i [DESTINATION_HOSTNAME]/[DESTINATION_PROJECT-ID]/[DESTINATION_IMAGE]:$i
done
done <<< "$imageVersion"
fi
yes | gcloud container images add-tag [SOURCE_HOSTNAME]/[SOURCE_PROJECT-ID]/[SOURCE_IMAGE]:$imageVersion [DESTINATION_HOSTNAME]/[DESTINATION_PROJECT-ID]/[DESTINATION_IMAGE]:$imageVersion
done <<< "$TAGS"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment