-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.sh
executable file
·77 lines (71 loc) · 1.55 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
#!/bin/sh
CONTAINER=service-app
APP=app
SERVICE=service
PARAMS=
CONFIG_PATH=
CONFIG_NAME=
DETACHED=false
usage() {
echo "Run Docker container"
echo ""
echo "./build.sh"
echo "\t-h --help"
echo "\t--container=$CONTAINER"
echo "\t--root=$ROOT"
echo "\t--app=$APP"
echo "\t--service=$SERVICE"
echo "\t--params=$PARAMS"
echo "\t--config-path=$CONFIG_PATH"
echo "\t--config-name=$CONFIG_NAME"
echo "\t--detached=$DETACHED"
echo ""
}
while [ "$1" != "" ]; do
PARAM=$(echo $1 | awk -F= '{print $1}')
VALUE=$(echo $1 | awk -F= '{print $2}')
case $PARAM in
-h | --help)
usage
exit 0
;;
-c | --container)
CONTAINER=$VALUE
;;
-r | --root)
ROOT=$VALUE
;;
-a | --app)
APP=$VALUE
;;
-s | --service)
SERVICE=$VALUE
;;
-p | --params)
PARAMS=$VALUE
;;
--config-path)
CONFIG_PATH=$VALUE
;;
--config-name)
CONFIG_NAME=$VALUE
;;
--detached)
DETACHED=$VALUE
;;
*)
echo "ERROR: unknown parameter \"$PARAM\""
usage
exit 1
;;
esac
shift
done
[ "$(docker ps | grep $CONTAINER)" ] && docker kill $CONTAINER
docker start $CONTAINER
RUN_ARGS=./$APP $PARAMS
[ ! -z "$CONFIG_PATH" ] && RUN_ARGS="$RUN_ARGS $CONFIG_PATH/"
[ ! -z "$CONFIG_NAME" ] && RUN_ARGS="$RUN_ARGS$CONFIG_NAME"
START_PARAMS="-it"
[ $DETACHED = true ] && START_PARAMS="-d"
docker exec -w /$SERVICE/$ROOT $START_PARAMS $CONTAINER /bin/sh -c "$RUN_ARGS"