-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdockername
More file actions
executable file
·25 lines (22 loc) · 810 Bytes
/
dockername
File metadata and controls
executable file
·25 lines (22 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#!/bin/sh
set -u
set -e
DOCKERUSER=$(docker info 2>&1 | grep -e '^ Username: ' | sed -e 's/ Username: \(.*\)/\1/')
if [ "$DOCKERUSER" = "" ]; then
# Refer to
# https://stackoverflow.com/questions/29326721/is-there-a-way-to-get-the-docker-hub-username-of-the-current-user
DOCKERUSER=$(docker-credential-$(jq -r .credsStore ~/.docker/config.json) list | \
jq -r '. | to_entries[] | select(.key | contains("docker.io")) | last(.value)')
if [ "$DOCKERUSER" = "" ]; then
echo "Could not obtain Docker username. Run 'docker login' and try again."
exit 1
fi
fi
DIR=`dirname $0`
pushd $DIR >/dev/null 2>&1
DOCKERIMAGE=`git branch 2>/dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/' -e 's/-/:/g'`
popd >/dev/null 2>&1
if [ "$DOCKERIMAGE" = "" ]; then
echo Could not obtain Docker image name.
exit 1
fi