-
Notifications
You must be signed in to change notification settings - Fork 8
/
manager.sh
72 lines (55 loc) · 1.36 KB
/
manager.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
#!/bin/bash
set -e
prj_dir=$(cd $(dirname $0); pwd -P)
image_version='1.0.3'
image_name="liaohuqiu/cube-box:$image_version"
env='prod'
app_name='cube-box'
container_name='cube-box'
function link_node_modules() {
if [ -d "$1/node_modules" ]; then
run_cmd "rm $1/node_modules"
fi
run_cmd "ln -sf /opt/node_npm_data/node_modules $1"
}
function build_image() {
docker build -t $image_name $prj_dir/docker
}
function run() {
local src_dir_in_host="$prj_dir/src"
link_node_modules $src_dir_in_host
local uid=`id -u`
local args=$(base_docker_args $env $container_name)
args="$args -v $src_dir_in_host:/opt/src"
args="$args -p 3000:3000"
args="$args -p 8545:8545"
args="$args -w /opt/src"
local cmd_args='tail -f /dev/null'
local cmd="docker run -d $args $image_name $cmd_args"
run_cmd "$cmd"
}
function stop() {
stop_container $container_name
}
function restart() {
stop
run
}
function attach() {
local cmd="docker exec $docker_run_fg_mode $container_name bash"
run_cmd "$cmd"
}
function help() {
cat <<-EOF
Valid options are:
build_image
run
stop
restart
attach
help show this help message and exit
EOF
}
source "$prj_dir/apuppy/bash-files/base.sh"
action=${1:-help}
$action "$@"