Skip to content

Instantly share code, notes, and snippets.

@ldx
Last active December 12, 2018 00:00
Show Gist options
  • Save ldx/b7482bb227aa5e824764586abfd60371 to your computer and use it in GitHub Desktop.
Save ldx/b7482bb227aa5e824764586abfd60371 to your computer and use it in GitHub Desktop.
Create docker configuration file with authentication info
#!/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