This repository has been archived by the owner on Jun 23, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·79 lines (70 loc) · 1.7 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
#!/bin/bash
usage() {
cat <<EOM
Usage:
$(basename $0) [-h] [-b] [-r] [-s] [-t]
-h Show this help text
-b Build dockers before run. Defaults to false.
-r Run the stack
-s Stop the stack
-t Start the test
EOM
exit 0
}
[ $# -eq 0 ] && usage
while getopts ":hbrst" optname; do
case "$optname" in
"h") usage;;
"b") build="true";;
"r") start="true";;
"s") teardown="true";;
"t") test="true";;
"?") echo "Unknown option $OPTARG" & exit 1;;
":") echo "No argument value for option $OPTARG" & exit 1;;
*) echo "Unknown error while processing options" & exit 2;;
esac
done
###
### Functions
###
build-docker () {
echo "-- Building docker image"
CGO_ENABLED=0 GOOS=linux go build -a -ldflags '-extldflags "-static"' .
if [[ "$?" != 0 ]]; then
echo "Error building binary"
exit 1
fi
docker build -t grace-test:local .
}
teardown-stack () { docker stack rm grace-test; }
run-stack () {
echo "-- Starting stack"
docker stack ls | grep -q grace-test
if [[ "$?" -eq 0 ]]; then
teardown-stack
echo "...waiting for network removal"; sleep 20s
fi
docker stack deploy --compose-file docker-compose.yml grace-test
echo "...waiting for stack initialisation"; sleep 10s
}
run-test() {
echo "-- Starting update test"
set -e
docker service update grace-test_grace --force &>/dev/null &
docker service logs grace-test_grace --follow
}
###
### Script execution
###
if [ -n "$build" ]; then
build-docker
fi
if [ -n "$start" ]; then
run-stack
fi
if [ -n "$teardown" ]; then
teardown-stack
fi
if [ -n "$test" ]; then
run-test
fi