mirror of
https://github.com/linuxkit/linuxkit.git
synced 2025-07-19 01:06:27 +00:00
scripts: support credentials helpers on Linux
On Linux a key in `~/.docker/config.json` indicates if a credentials helper is in use (and which), if one is then the method is identical to the Darwin case so refactor to support that. Signed-off-by: Ian Campbell <ijc@docker.com>
This commit is contained in:
parent
eac17cc85f
commit
e78b25062c
@ -26,26 +26,34 @@ case $(uname -s) in
|
||||
Darwin)
|
||||
# Prior to 2018-03-27 D4M used a .bin suffix on the keychain utility binary name. Support the old name for a while
|
||||
if [ -f /Applications/Docker.app/Contents/Resources/bin/docker-credential-osxkeychain.bin ]; then
|
||||
CRED=$(echo "https://index.docker.io/v1/" | /Applications/Docker.app/Contents/Resources/bin/docker-credential-osxkeychain.bin get)
|
||||
CREDHELPER="/Applications/Docker.app/Contents/Resources/bin/docker-credential-osxkeychain.bin"
|
||||
else
|
||||
CRED=$(echo "https://index.docker.io/v1/" | /Applications/Docker.app/Contents/Resources/bin/docker-credential-osxkeychain get)
|
||||
CREDHELPER="/Applications/Docker.app/Contents/Resources/bin/docker-credential-osxkeychain"
|
||||
fi
|
||||
USER=$(echo "$CRED" | jq -r '.Username')
|
||||
PASS=$(echo "$CRED" | jq -r '.Secret')
|
||||
MT_ARGS="--username $USER --password $PASS"
|
||||
;;
|
||||
Linux)
|
||||
CREDSTORE=$(cat ~/.docker/config.json | jq -r '.credsStore // empty')
|
||||
if [ -n "$CREDSTORE" ] ; then
|
||||
CREDHELPER="docker-credential-$CREDSTORE"
|
||||
else
|
||||
CRED=$(cat ~/.docker/config.json | jq -r '.auths."https://index.docker.io/v1/".auth' | base64 -d -)
|
||||
USER=$(echo $CRED | cut -d ':' -f 1)
|
||||
PASS=$(echo $CRED | cut -d ':' -f 2-)
|
||||
# manifest-tool can use docker credentials directly
|
||||
MT_ARGS=
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported platform"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
if [ -n "$CREDHELPER" ] ; then
|
||||
CRED=$(echo "https://index.docker.io/v1/" | "$CREDHELPER" get)
|
||||
USER=$(echo "$CRED" | jq -r '.Username')
|
||||
PASS=$(echo "$CRED" | jq -r '.Secret')
|
||||
MT_ARGS="--username $USER --password $PASS"
|
||||
fi
|
||||
|
||||
# Push manifest list
|
||||
OUT=$(manifest-tool $MT_ARGS push from-args \
|
||||
|
@ -29,26 +29,34 @@ case $(uname -s) in
|
||||
Darwin)
|
||||
# Prior to 2018-03-27 D4M used a .bin suffix on the keychain utility binary name. Support the old name for a while
|
||||
if [ -f /Applications/Docker.app/Contents/Resources/bin/docker-credential-osxkeychain.bin ]; then
|
||||
CRED=$(echo "https://index.docker.io/v1/" | /Applications/Docker.app/Contents/Resources/bin/docker-credential-osxkeychain.bin get)
|
||||
CREDHELPER="/Applications/Docker.app/Contents/Resources/bin/docker-credential-osxkeychain.bin"
|
||||
else
|
||||
CRED=$(echo "https://index.docker.io/v1/" | /Applications/Docker.app/Contents/Resources/bin/docker-credential-osxkeychain get)
|
||||
CREDHELPER="/Applications/Docker.app/Contents/Resources/bin/docker-credential-osxkeychain"
|
||||
fi
|
||||
USER=$(echo "$CRED" | jq -r '.Username')
|
||||
PASS=$(echo "$CRED" | jq -r '.Secret')
|
||||
MT_ARGS="--username $USER --password $PASS"
|
||||
;;
|
||||
Linux)
|
||||
CREDSTORE=$(cat ~/.docker/config.json | jq -r '.credsStore // empty')
|
||||
if [ -n "$CREDSTORE" ] ; then
|
||||
CREDHELPER="docker-credential-$CREDSTORE"
|
||||
else
|
||||
CRED=$(cat ~/.docker/config.json | jq -r '.auths."https://index.docker.io/v1/".auth' | base64 -d -)
|
||||
USER=$(echo $CRED | cut -d ':' -f 1)
|
||||
PASS=$(echo $CRED | cut -d ':' -f 2-)
|
||||
# manifest-tool can use docker credentials directly
|
||||
MT_ARGS=
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported platform"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
if [ -n "$CREDHELPER" ] ; then
|
||||
CRED=$(echo "https://index.docker.io/v1/" | "$CREDHELPER" get)
|
||||
USER=$(echo "$CRED" | jq -r '.Username')
|
||||
PASS=$(echo "$CRED" | jq -r '.Secret')
|
||||
MT_ARGS="--username $USER --password $PASS"
|
||||
fi
|
||||
|
||||
# Push manifest list
|
||||
OUT=$(manifest-tool $MT_ARGS push from-args \
|
||||
|
@ -48,26 +48,34 @@ case $(uname -s) in
|
||||
Darwin)
|
||||
# Prior to 2018-03-27 D4M used a .bin suffix on the keychain utility binary name. Support the old name for a while
|
||||
if [ -f /Applications/Docker.app/Contents/Resources/bin/docker-credential-osxkeychain.bin ]; then
|
||||
CRED=$(echo "https://index.docker.io/v1/" | /Applications/Docker.app/Contents/Resources/bin/docker-credential-osxkeychain.bin get)
|
||||
CREDHELPER="/Applications/Docker.app/Contents/Resources/bin/docker-credential-osxkeychain.bin"
|
||||
else
|
||||
CRED=$(echo "https://index.docker.io/v1/" | /Applications/Docker.app/Contents/Resources/bin/docker-credential-osxkeychain get)
|
||||
CREDHELPER="/Applications/Docker.app/Contents/Resources/bin/docker-credential-osxkeychain"
|
||||
fi
|
||||
USER=$(echo "$CRED" | jq -r '.Username')
|
||||
PASS=$(echo "$CRED" | jq -r '.Secret')
|
||||
MT_ARGS="--username $USER --password $PASS"
|
||||
;;
|
||||
Linux)
|
||||
CREDSTORE=$(cat ~/.docker/config.json | jq -r '.credsStore // empty')
|
||||
if [ -n "$CREDSTORE" ] ; then
|
||||
CREDHELPER="docker-credential-$CREDSTORE"
|
||||
else
|
||||
CRED=$(cat ~/.docker/config.json | jq -r '.auths."https://index.docker.io/v1/".auth' | base64 -d -)
|
||||
USER=$(echo $CRED | cut -d ':' -f 1)
|
||||
PASS=$(echo $CRED | cut -d ':' -f 2-)
|
||||
# manifest-tool can use docker credentials directly
|
||||
MT_ARGS=
|
||||
fi
|
||||
;;
|
||||
*)
|
||||
echo "Unsupported platform"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
if [ -n "$CREDHELPER" ] ; then
|
||||
CRED=$(echo "https://index.docker.io/v1/" | "$CREDHELPER" get)
|
||||
USER=$(echo "$CRED" | jq -r '.Username')
|
||||
PASS=$(echo "$CRED" | jq -r '.Secret')
|
||||
MT_ARGS="--username $USER --password $PASS"
|
||||
fi
|
||||
|
||||
# Push manifest list
|
||||
OUT=$(manifest-tool $MT_ARGS push from-spec --ignore-missing "$YAML")
|
||||
|
Loading…
Reference in New Issue
Block a user