-
Notifications
You must be signed in to change notification settings - Fork 1
/
service.sh
81 lines (71 loc) · 1.82 KB
/
service.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
#!/usr/bin/env bash
# This script will run under bus_route_challenge folder irrespective of where it was invoked from
cd $(dirname $0)
dev_build() {
# Do what you need to package your app, e.g. mvn package
mvn package
true
}
dev_run() {
# Do what you need to run your app in the foreground
# e.g. java -jar target/magic.jar $*
java -jar target/route-search-service-1.0-SNAPSHOT.jar $1
sleep 600
}
dev_smoke() {
if _run_smoke; then
echo "Tests Passed"
exit 0
else
echo "Tests Failed"
exit 1
fi
}
_run_smoke() {
baseUrl="http://localhost:8088"
echo "Running smoke tests on $baseUrl..." && \
(curl -fsS "$baseUrl/api/direct?dep_sid=3&arr_sid=4" | grep -E 'true|false') && \
(curl -fsS "$baseUrl/api/direct?dep_sid=0&arr_sid=1" | grep -E 'true|false')
}
docker_build() {
mvn clean
docker build -t goeuro:devtest --build-arg CACHEBUST=$(date +%s) .
}
docker_run() {
docker run --rm -it -p 8088:8088 goeuro:devtest
}
docker_smoke() {
containerId=$(docker run -d goeuro:devtest)
echo "Waiting 10 seconds for service to start..."
sleep 10
docker exec $containerId /src/service.sh dev_smoke
retval=$?
docker rm -f $containerId
exit $retval
}
usage() {
cat <<EOF
Usage:
$0 <command> <args>
Local machine commands:
dev_build : builds and packages your app
dev_run <file> : starts your app in the foreground
dev_smoke : runs our integration test suite on localhost
Docker commands:
docker_build : packages your app into a docker image
docker_run : runs your app using a docker image
docker_smoke : runs same smoke tests inside a docker container
EOF
}
action=$1
action=${action:-"usage"}
action=${action/help/usage}
shift
if type -t $action >/dev/null; then
echo "Invoking: $action"
$action $*
else
echo "Unknown action: $action"
usage
exit 1
fi