-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlaunch.sh
executable file
·138 lines (104 loc) · 3.47 KB
/
launch.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/usr/bin/env bash
set -e
MDB_THRIFT_LOCAL=${MDB_THRIFT_LOCAL:-"false"}
MDB_THRIFT_VERSION=${MDB_THRIFT_VERSION:-"0.10.0"}
MDB_THRIFT_MODEL_VERSION=${MDB_THRIFT_MODEL_VERSION:-"master"}
MDB_WAIT_BACKEND=${MDB_WAIT_BACKEND:-"true"}
MDB_BACKEND_HOST=${MDB_BACKEND_HOST:-"localhost"}
MDB_DOCKER_NAME=${MDB_DOCKER_NAME:-"modeldb-frontend"}
MDB_DOCKER_NAME_TAG=${MDB_DOCKER_NAME_TAG:-"latest"}
MDB_DOCKER_OPTS=${MDB_DOCKER_OPTS:-"-it --net=host"}
function gen() {
curl -Lo ModelDB.thrift https://raw.githubusercontent.com/mitdbg/modeldb/${MDB_THRIFT_MODEL_VERSION}/thrift/ModelDB.thrift
mkdir -p thrift
if [[ "$MDB_THRIFT_LOCAL" == 'true' ]]; then
if [[ ! "$(thrift -version)" ]]; then
pushd ~/
wget -q http://archive.apache.org/dist/thrift/${MDB_THRIFT_VERSION}/thrift-${MDB_THRIFT_VERSION}.tar.gz
tar -xzf thrift-${MDB_THRIFT_VERSION}.tar.gz
cd thrift-${MDB_THRIFT_VERSION} && ./configure --without-python && make
ln -n ~/thrift-${MDB_THRIFT_VERSION}/compiler/cpp/thrift /usr/local/bin/thrift
popd
thrift -version
fi
thrift -r -out 'thrift' -gen js:node 'ModelDB.thrift'
else
docker run --rm -v $(pwd):/data thrift:${MDB_THRIFT_VERSION} \
thrift -r -v -out /data/thrift --gen js:node /data/ModelDB.thrift
fi
}
function start() {
npm install
node_param=""
npm_param=""
if [ -n "$MDB_BACKEND_HOST" ]; then
node_param="--host $MDB_BACKEND_HOST"
npm_param="-- $node_param"
fi
if [[ "$MDB_WAIT_BACKEND" == 'true' ]]; then
until node util/check_thrift.js $node_param > /dev/null 2>&1; do
>&2 echo "Backend is unavailable - sleeping"
sleep 1
done
>&2 echo "Backend is up - executing command"
fi
exec npm start $npm_param
}
function stop() {
npm stop
}
function docker-build() {
docker build -t modeldb-frontend:latest \
--label modeldb=frontend \
--build-arg MDB_THRIFT_LOCAL=$MDB_THRIFT_LOCAL \
--build-arg MDB_THRIFT_VERSION=$MDB_THRIFT_VERSION \
--build-arg MDB_THRIFT_MODEL_VERSION=$MDB_THRIFT_MODEL_VERSION .
}
function docker-start() {
[[ $(docker ps -a -f "name=$MDB_DOCKER_NAME" --format '{{.Names}}') == $MDB_DOCKER_NAME ]] && \
(echo "Container $MDB_DOCKER_NAME already exists"; exit 1)
MDB_DOCKER_OPTS="${MDB_DOCKER_OPTS} -e MDB_WAIT_BACKEND=${MDB_WAIT_BACKEND} -e MDB_BACKEND_HOST=${MDB_BACKEND_HOST} "
if [[ "${MDB_THRIFT_LOCAL}" == 'false' ]]; then
MDB_DOCKER_OPTS="${MDB_DOCKER_OPTS} -v $(pwd)/thrift "
fi
docker run $MDB_DOCKER_OPTS --name $MDB_DOCKER_NAME $MDB_DOCKER_NAME:$MDB_DOCKER_NAME_TAG
}
function docker-stop() {
[[ $(docker ps -f "name=$MDB_DOCKER_NAME" --format '{{.Names}}') == $MDB_DOCKER_NAME ]] && \
docker stop $MDB_DOCKER_NAME
}
function clean-all() {
[ -d thrift ] && rm -r ./thrift
[[ $(docker ps -a -f "name=$MDB_DOCKER_NAME" --format '{{.Names}}') == $MDB_DOCKER_NAME ]] && \
docker rm -f $MDB_DOCKER_NAME
IMAGES_TO_DEL=$(docker images -f label="modeldb=frontend" --format '{{.ID}}')
if [[ $IMAGES_TO_DEL ]]; then docker rmi $IMAGES_TO_DEL; fi
}
# Main options
case "$1" in
gen)
gen
;;
start)
start
;;
stop)
stop
exit $?
;;
docker-build)
docker-build
;;
docker-start)
docker-start
;;
docker-stop)
docker-start
;;
clean-all)
clean-all
;;
*)
echo "Usage: $0 {gen|start|docker-build|docker-start|stop|docker-stop|clean-all}"
exit 1
esac