Skip to content

Instantly share code, notes, and snippets.

@fkorotkov
Created February 26, 2018 19:57
Show Gist options
  • Save fkorotkov/6244b7ec42b8f9b7e41986438fd913e3 to your computer and use it in GitHub Desktop.
Save fkorotkov/6244b7ec42b8f9b7e41986438fd913e3 to your computer and use it in GitHub Desktop.
JSON key file to Google Container Registry's HTTP API
#!/usr/bin/env bash
GCP_PROJECT_ID=...
MY_IMAGE=...
USERNAME=_json_key
PASSWORD=$(cat keyfile.json)
TOKEN=$(echo "$USERNAME:$PASSWORD" | base64)
RESPONSE=$(curl --header "Authorization: Basic $TOKEN" "https://gcr.io/v2/token?service=gcr.io&scope=registry:$GCP_PROJECT_ID/$MY_IMAGE:*")
REGISTRY_TOKEN=$(echo $RESPONSE | jq -r '.token')
echo "Registry token: $REGISTRY_TOKEN"
curl --header "Authorization: Bearer $REGISTRY_TOKEN" "https://gcr.io/v2/$GCP_PROJECT_ID/$MY_IMAGE/manifests/latest"
echo
@lgylym
Copy link

lgylym commented Dec 10, 2019

works like a charm, thx

@GreenRover
Copy link

What is the format of the keyfile? Where can the content be found in .docker/config.json ?

@fkorotkov
Copy link
Author

@GreenRover it's a service account key in JSON format rather than P12. See docs here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment