-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·78 lines (62 loc) · 1.65 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
#!/usr/bin/env bash
# ./run.sh example2 ==> run single example
#
# ./run.sh ==> run all
# colors
RED='\033[0;31m'
GREEN='\033[0;32m'
NC='\033[0m'
pass() {
echo -e "$GREEN PASSED: $@ $NC"
}
fail() {
echo -e "$RED FAILED: $@ $NC"
}
trap 'kill $BG_PROBE_PID; exit' SIGINT
bg_probe_exit() {
# if we have tester service, we take its exit code
# this has no support in docker-compose, as --exit-code-from aborts on first container exit
# this function is executed in background
NAME=${1}_tester_1
echo "starting background probe for service $NAME"
while sleep 1 ; do
STATUS=$(docker inspect "$NAME" --format='{{.State.Status}}' 2>/dev/null)
if [ "$STATUS" == "exited" ] ; then
CODE=$(docker inspect "$NAME" --format='{{.State.ExitCode}}')
echo "$NAME in status $STATUS ($CODE)"
docker-compose kill
return $CODE
fi
[ -z "$STATUS" ] && echo "$NAME still building..." || echo "$NAME still in status $STATUS... waiting for it to exit"
done
}
up() {
clean
docker-compose up --build
}
clean() {
docker-compose down --volumes
}
run_example() {
echo "running $1"
pushd "$1"
if has_tester_service ; then
bg_probe_exit "$1" &
BG_PROBE_PID=$!
up && wait $BG_PROBE_PID || kill $BG_PROBE_PID
else
echo "$1 has no tester service"
up
fi
RES=$?
[ $RES -eq 0 ] && pass "$1" || fail "$1 (exit code: $RES)"
clean
popd
}
run_all() {
for X in ex* ; do run_example "$X" ; done
}
has_tester_service() {
docker-compose config --services | grep -q tester
}
[ -z "$1" ] && run_all || run_example $1