forked from bird-wp07/local-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·115 lines (90 loc) · 2.68 KB
/
run.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/usr/bin/env zsh
DOCKERFILE_PATH="./docker/dss.Dockerfile"
IMAGE_NAME="wp07-dss"
_die() {
echo "$1" >&2
exit 1
}
dss_run() {
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
cat <<<"Spawn DSS containers
Usage: $ZSH_ARGZERO ${0:gs/_/ } [-d] [PORT]
Spawns a DSS container exposed at port PORT (default: 8080). Optionally, use -d
to run the container as a background process."
exit
fi
if [[ "$1" == "-d" ]]; then
detach="-d"
shift
fi
if [[ "$1" != "" ]]; then
if [[ ! "$1" =~ ^[1-9][0-9]*$ ]]; then
_die "Invalid port: '$1'"
fi
port=$1
else
port=8080
fi
docker build -t $IMAGE_NAME -f $DOCKERFILE_PATH .
docker container run $detach -p $port:8080 --rm -t --name "$IMAGE_NAME-$port" $IMAGE_NAME
}
dss_stop() {
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
cat <<<"Stop DSS containers
Usage: $ZSH_ARGZERO ${0:gs/_/ } [PORT]
Stops a DSS container exposed at port PORT. If no port is provided, all DSS
containers are stopped."
exit
fi
if [[ "$1" =~ ^[1-9][0-9]*$ ]]; then
if [[ ! "$1" =~ ^[1-9][0-9]*$ ]]; then
_die "Invalid port: '$1'"
fi
name="$IMAGE_NAME-$1"
else
name="$IMAGE_NAME-"
fi
docker container ls \
--filter "name=$name" \
-q | xargs docker container stop 2>/dev/null || true
}
dss_ls() {
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
cat <<<"List all running DSS containers
Usage: $ZSH_ARGZERO ${0:gs/_/ } [-q]
Produces a listing of all running DSS containers. Using -q will return only the
containers' ids."
exit
fi
[[ "$1" == "-q" ]] && quiet="-q"
docker container ls --filter "name=$IMAGE_NAME-" $quiet
}
dss() {
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
cat <<<"Control DSS containers.
Usage: $ZSH_ARGZERO ${0:gs/_/ /} COMMAND ...
Available commands:"
print -l ${(ok)functions} | grep -E "^$0_" | sed -E "s/^$0_//g" | while read cmd; do
help="$($ZSH_ARGZERO $0_$cmd --help | head -1)"
echo " ${(r:10:)cmd:gs/_/ /}$help"
done
echo "\nSee COMMAND --help for more information"
exit
fi
dss_"$@"
}
if [[ "$1" == "-h" ]] || [[ "$1" == "--help" ]]; then
cat <<<"Usage: $ZSH_ARGZERO COMMAND ...
Available commands:"
print -l ${(ok)functions} | grep -vE "_" | while read cmd; do
{
echo -n "$cmd\t\t"
$0 "$cmd" --help | head -1
} | sed -E 's/.*/ &/'
done
echo "\nSee COMMAND --help for more information"
exit
fi
cd "${0:A:h}"
"$@"
# TODO: Get rid of super command boilerplate via decorators.