forked from SolaceLabs/docker-qpid-proton
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_image.sh
executable file
·92 lines (80 loc) · 2.72 KB
/
docker_image.sh
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#!/usr/bin/env bash
# helper functions
script_init(){
PRG="$1"
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
# Need this for relative symlinks.
local SOURCE=$PRG
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
local DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
local SOURCE="$(readlink "$SOURCE")"
[[ $SOURCE != /* ]] && SOURCE="$DIR/$SOURCE" # if $SOURCE was a relative symlink, we need to resolve it relative to the path where the symlink file was located
done
# set global variable for path to executing script
PRG_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"
PRG=`basename $PRG`
}
help(){
echo "$PRG [options] <command> [<args...>]"
echo " build: builds the docker images"
echo " clean [<tag>...]: removes the docker images"
echo " publish [<tag>...]: publishes the docker images"
echo " help: displays this message"
echo "options:"
echo " -u <username>: specifies username for docker registry, default:'solace'"
}
run_command(){
local COMMAND=$1
shift
if [ "$DOCKER_USERNAME" ]; then
local REGISTRY_USER=$DOCKER_USERNAME
else
# the release USER uses the default release user 'solace' in the command scripts
local REGISTRY_USER="release"
fi
if [ "$COMMAND" == "build" ]; then
$SCRIPT_HOME/build.sh $REGISTRY_USER || echo "Failed build docker image command"
elif [ "$COMMAND" == "clean" ]; then
# determine tags from arguments
while [ "$1" ]; do
# add all tags from build.sh for argument 'all'
if [ "$1" == "all" ]; then
local TAGS="$TAGS centos ubuntu centos_build ubuntu_build"
else
local TAGS="$TAGS $1"
fi
shift
done
$SCRIPT_HOME/clean.sh $REGISTRY_USER $TAGS || echo "Failed clean docker image command"
elif [ "$COMMAND" == "publish" ]; then
# determine tags from arguments
while [ "$1" ]; do
local TAGS="$TAGS $1"
shift
done
$SCRIPT_HOME/publish.sh $REGISTRY_USER || echo "Failed publish docker image command"
elif [ "$COMMAND" == "help" ]; then
help
else
echo "Unrecognized command: $COMMAND"
echo "Usage:"
help
fi
}
# script Start
# setup location variables using absolute paths
script_init ${BASH_SOURCE[0]}
SCRIPT_HOME=$PRG_DIR/scripts
# import common resources
source $SCRIPT_HOME/helper.sh
# parse options
if [ "$1" == "-u" ]; then
shift
DOCKER_USERNAME=$1
shift
fi
# check for docker tool
check_docker
# parse and run command from arguments
run_command $@