-
Notifications
You must be signed in to change notification settings - Fork 0
/
test
executable file
·85 lines (68 loc) · 1.41 KB
/
test
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
#!/bin/sh
DIR="$(cd $(dirname $0) && pwd)"
BIN_DIR="$(cd $DIR/.. && pwd)"
# Import functions
. $BIN_DIR/helper/fn
usage() {
cat <<-EOF
Usage: $0 [options...]
Options:
-b Build image
-s <service> Docker compose service name
-h Show usage
EOF
exit 0
}
# Go to current directory
CURR_FOLDER="$(pwd)"
cd $CURR_FOLDER
BUILD=""
SERVICE="app"
OPT="test"
COMPOSE_TEMPLATE="${CURR_FOLDER}/docker-compose.template.yml"
COMPOSE_LOCAL="${CURR_FOLDER}/docker-compose.local.yml"
COMPOSE_TEST="${CURR_FOLDER}/docker-compose.test.yml"
_cleanup() {
docker compose \
-f $COMPOSE_TEMPLATE \
-f $COMPOSE_LOCAL \
-f $COMPOSE_TEST \
down \
--volumes \
--remove-orphans > /dev/null 2>&1
}
trap '_cleanup; abort "Tests failed for unexpected reasons"' HUP INT QUIT PIPE TERM SIGINT SIGTERM
while getopts "bs:h" o
do
case ${o} in
b) BUILD="--build" ;;
s) SERVICE=$OPTARG ;;
h) usage ;;
\?) usage ;;
esac
done
# ENV File
load_env $OPT
# Generate ENVs for frontend application
if test "${REQUIRE_GEN:-0}" = "1"; then
gen_env "${CURR_FOLDER}/resource/env.js"
fi
docker compose \
-f $COMPOSE_TEMPLATE \
-f $COMPOSE_LOCAL \
-f $COMPOSE_TEST \
up \
--force-recreate \
--always-recreate-deps \
--abort-on-container-exit \
--exit-code-from ${SERVICE} \
--remove-orphans \
--renew-anon-volumes \
$BUILD
if test $? -ne 0; then
_cleanup
abort "Test FAIL"
fi
_cleanup
ok "Test PASS"
exit 0