Skip to content

Instantly share code, notes, and snippets.

@voor
Created October 1, 2021 16:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save voor/7b63796b891297f04de7ac1a6b7d601d to your computer and use it in GitHub Desktop.
Save voor/7b63796b891297f04de7ac1a6b7d601d to your computer and use it in GitHub Desktop.
Iterate through BundleLocks and relocate them with imgpkg
#!/usr/bin/env bash
set -eux -o pipefail
IMGPKG_REGISTRY_HOSTNAME_0="${IMGPKG_REGISTRY_HOSTNAME_0:-source.example.com}"
IMGPKG_REGISTRY_HOSTNAME_1="${IMGPKG_REGISTRY_HOSTNAME_1:-destination.example.com}"
echo "#!/usr/bin/env bash"
echo "# This generates a script that can be run during CI to copy all the packages over to a new location."
echo "set -eux -o pipefail"
# Packages are located in the addons folder, change accordingly.
grep --include=\*.{yaml,yml} -rwl 'addons' -e "kind: BundleLock" \
| xargs grep -e ' image: ' \
| sed -e "s/ image: ${IMGPKG_REGISTRY_HOSTNAME_0}//" -e 's/@sha256.*//' \
| awk -v TO_REPO="${IMGPKG_REGISTRY_HOSTNAME_1}" -F ":" '{print "imgpkg copy --lock", $1, "--to-repo", TO_REPO $2 }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment