Created
June 1, 2020 03:50
-
-
Save arthurk/ab9ced56ce78bb8309599ccc62fa2576 to your computer and use it in GitHub Desktop.
fetch list images from GCR via service account
This file contains hidden or 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
#!/usr/bin/env bash | |
set -euo pipefail | |
###################### | |
# Script that fetches a list of all images from GCR | |
# uses 3 different users in GCR | |
###################### | |
keyfile="gcr-svc-acc-keyfile.json" | |
projectName="example-project" | |
imageName="alpine" | |
token=$(oauth2l fetch --credentials $keyfile --scope cloud-platform.read-only --cache="") | |
jwt=$(curl -sSL "https://gcr.io/v2/token?service=gcr.io&scope=repository:$projectName/$imageName:pull" -u _token:$token | jq --raw-output '.token') | |
curl -sSL -H "Authorization: Bearer $jwt" "https://gcr.io/v2/$projectName/$imageName/tags/list" | |
# use oauth2 access token instead of JWT from docker registry | |
token=$(oauth2l fetch --credentials $keyfile --scope cloud-platform.read-only --cache="") | |
curl -sSL -u "oauth2accesstoken:$token" "https://gcr.io/v2/$projectName/$imageName/tags/list" | |
# use service account key instead of oauth2 access key | |
curl -sSL -u "_json_key:$(cat $keyfile)" "https://gcr.io/v2/$projectName/$imageName/tags/list" |
Thank you for this!
thanks a lot, truly live saver, i transformed it in python here https://gist.github.com/steve-heslouin/1dbc0734dc2075853f259c356fb15286
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Saved me hours. Thanks!!