Skip to content

Instantly share code, notes, and snippets.

@zxkane
Last active January 23, 2022 20:23
Show Gist options
  • Save zxkane/bd2bed189e65b63e56fb028019839744 to your computer and use it in GitHub Desktop.
Save zxkane/bd2bed189e65b63e56fb028019839744 to your computer and use it in GitHub Desktop.
Export all images with tags in gcr.io/google-containers

Dump images with tags from repository gcr.io/gcr-containers

Prerequisites

  • Install gcloud
  • Configure account auth via gcloud auth login
  • Install jq

Usage

./dump.sh | tee gcr-containers-images.txt
#!/bin/bash
set -e
main() {
local repository="google-containers"
dump_image_tags $repository
}
dump_image_tags() {
local repository=$1
images=$(get_image_list $repository)
for image in $images; do
if [ ! -z "$image" ]; then
tags=$(get_image_tags $image)
for tag in $tags; do
echo "$image:$tag"
done
fi
done
}
get_image_list() {
local repository=$1
gcloud container images list --repository "gcr.io/$repository" --quiet --format="csv[no-heading](Name)"
}
get_image_tags() {
local image=$1
gcloud container images list-tags "$image" --quiet --filter="tags:*" --format="json(tags)" | jq -r ".[]|flatten|.[]|."
}
main "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment