Created
December 1, 2016 01:57
-
-
Save ctaggart/be3e416be763185ee99e840684de0243 to your computer and use it in GitHub Desktop.
Google Container VM /usr/share/google/dockercfg_update.sh
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
#!/bin/sh | |
# Copyright 2015 The Chromium OS Authors. All rights reserved. | |
# Use of this source code is governed by a BSD-style license that can be | |
# found in the LICENSE file. | |
AUTH_DATA="$(curl -s -f -m 10 "http://metadata/computeMetadata/v1/instance/service-accounts/default/token" \ | |
-H "Metadata-Flavor: Google")" | |
R=$? | |
if [ ${R} -ne 0 ]; then | |
echo "curl for auth token exited with status ${R}" >&2 | |
exit ${R} | |
fi | |
AUTH="$(echo "${AUTH_DATA}" \ | |
| tr -d '{}' \ | |
| sed 's/,/\n/g' \ | |
| awk -F ':' '/access_token/ { print "_token:" $2 }' \ | |
| tr -d '"\n' \ | |
| base64 -w 0)" | |
if [ -z "${AUTH}" ]; then | |
echo "Auth token not found in AUTH_DATA ${AUTH_DATA}" >&2 | |
exit 1 | |
fi | |
cat > ~/.dockercfg <<EOF | |
{ | |
"https://container.cloud.google.com":{"email": "[email protected]","auth": "${AUTH}"}, | |
"https://gcr.io":{"email": "[email protected]","auth": "${AUTH}"}, | |
"https://b.gcr.io":{"email": "[email protected]","auth": "${AUTH}"}, | |
"https://us.gcr.io":{"email": "[email protected]","auth": "${AUTH}"}, | |
"https://eu.gcr.io":{"email": "[email protected]","auth": "${AUTH}"}, | |
"https://asia.gcr.io":{"email": "[email protected]","auth": "${AUTH}"}, | |
"https://beta.gcr.io":{"email": "[email protected]","auth": "${AUTH}"} | |
} | |
EOF |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment