Last active
December 12, 2018 00:00
-
-
Save ldx/b7482bb227aa5e824764586abfd60371 to your computer and use it in GitHub Desktop.
Create docker configuration file with authentication info
This file contains 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/bash | |
set -euo pipefail | |
if [[ "$DOCKER_USER" = "" ]]; then | |
echo "Please set \$DOCKER_USER" | |
exit 1 | |
fi | |
if [[ "$DOCKER_PASSWORD" = "" ]]; then | |
echo "Please set \$DOCKER_PASSWORD" | |
exit 1 | |
fi | |
if [[ -z "$CONFIG_PATH" ]]; then | |
if [[ "$HOME" = "" ]]; then | |
echo "Please set \$HOME" | |
exit 1 | |
fi | |
mkdir -p $HOME/.docker | |
CONFIG_PATH="$HOME/.docker/config.json" | |
if [[ -f "$CONFIG_PATH" ]]; then | |
mv "$CONFIG_PATH" "$CONFIG_PATH.$(date +%s)" | |
fi | |
fi | |
AUTH="$(echo -n $DOCKER_USER:$DOCKER_PASSWORD | base64)" | |
echo -en "{ | |
\"auths\": { | |
\"https://index.docker.io/v1/\": { | |
\"auth\": \"$AUTH\" | |
} | |
} | |
}" > "$CONFIG_PATH" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment