-
Notifications
You must be signed in to change notification settings - Fork 36
/
build_and_run.sh
executable file
·120 lines (109 loc) · 3.01 KB
/
build_and_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
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
#!/bin/bash
TENSORFLOW=tensorflow/tensorflow:1.5.0-py3
which nvidia-docker
if [ $? -eq 0 ] && ! [ -v NO_GPU ]; then
DOCKER_CMD=`/usr/bin/which nvidia-docker`
TENSORFLOW=tensorflow/tensorflow:1.5.0-gpu-py3
else
which wharfer
if [ $? -eq 0 ]; then
DOCKER_CMD=`/usr/bin/which wharfer`
else
DOCKER_CMD=`/usr/bin/which docker`
fi
fi
function help {
echo "Usage: $0 train|cv|backend|debug|update [--port PORT] [--name name] [--no-cache] [--ranker ranker] [ARGS..]"
exit 1
}
INPUT_DIR="./input"
WORKDATA_DIR="./data"
PORT=8090
RANKER="WQSP_Ranker"
NAME="wqsp_default"
CACHE=""
POSITIONAL=()
while [[ $# -gt 0 ]]
do
key="$1"
case $key in
-p|--port)
PORT="$2"
shift # shift argument
shift # shift value
;;
-h|--help)
help # exits
;;
-nc|--no-cache)
CACHE="--pull --no-cache"
shift # only have an argument
;;
-n|--name)
NAME="$2"
shift # shift argument
shift # shift value
;;
-r|--ranker)
RANKER="$2"
shift # shift argument
shift # shift value
;;
*) # unknown option
POSITIONAL+=("$1") # save it in an array for later
shift # shift argument
;;
esac
done
set -- "${POSITIONAL[@]}" # restore positional parameters
if [ "$1" != "backend" ] && [ "$1" != "train" ] && \
[ "$1" != "debug" ] && [ "$1" != "update" ] && [ "$1" != "cv" ]; then
help
fi
INPUT_VOLUME="$(pwd)/${INPUT_DIR}:/app/input"
WORKDATA_VOLUME="$(pwd)/${WORKDATA_DIR}:/app/data"
chmod o+wx ${WORKDATA_DIR}
MODELS_DIR="aqqu_learner_${NAME}_models"
# Create a model directory if it doesn't exist
mkdir -p ${MODELS_DIR}
chmod o+wx ${MODELS_DIR}
# Add .gitignore so the models don't end up in git, '>' overwrites if it exists but that's ok
echo '!.gitignore' > ${MODELS_DIR}/.gitignore
MODELS_VOLUME="$(pwd)/${MODELS_DIR}:/app/models"
function build {
echo "-----------------------------------------------------------------"
echo Executing $DOCKER_CMD build
$DOCKER_CMD build ${CACHE} -t "aqqu_$1" \
--build-arg TENSORFLOW=$TENSORFLOW \
-f "Dockerfile" .
}
if [ "$1" == "train" ] || [ "$1" == "cv" ]; then
echo "Learner"
build ${NAME}
echo "-----------------------------------------------------------------"
$DOCKER_CMD run --rm -it --init --name "aqqu_$1_${NAME}_inst" \
-v $INPUT_VOLUME \
-v $WORKDATA_VOLUME \
-v $MODELS_VOLUME \
"aqqu_${NAME}" query_translator.learner "$1" "${RANKER}" "${@:2}"
elif [ "$1" == "backend" ]; then
echo "Backend"
$DOCKER_CMD run --restart unless-stopped --init -d -p ${PORT}:8090 \
--name "aqqu_$1_${NAME}_inst" \
-v $INPUT_VOLUME \
-v $WORKDATA_VOLUME \
-v $MODELS_VOLUME \
"aqqu_${NAME}" translator_server "${RANKER}" "${@:2}"
elif [ "$1" == "debug" ]; then
echo "Debug"
build debug_${NAME}
$DOCKER_CMD run --rm -it -p $PORT:8090 --init --name "aqqu_$1_${NAME}_inst" \
-v $INPUT_VOLUME \
-v $WORKDATA_VOLUME \
-v $MODELS_VOLUME \
"aqqu_debug_${NAME}" translator_server "${RANKER}" "${@:2}"
elif [ "$1" == "update" ]; then
echo "-----------------------------------------------------------------"
echo "Update"
build ${NAME}
fi