-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.sh
executable file
·78 lines (66 loc) · 2.17 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
78
#!/bin/sh
### BEGIN ###
# Author: idevz
# Since: 2018/03/12
# Description: Run a Golang service with Weibo-Mesh.
# ./run.sh run hello world demo
# ./run.sh x clean the container and network
# ./run.sh -h show this help
### END ###
set -ex
BASE_DIR=$(dirname $(cd $(dirname "$0") && pwd -P)/$(basename "$0"))
GO_SERVER_IMAGE=weibocom/weibo-mesh-demo-server:0.0.4
GO_CLIENT_IMAGE=weibocom/weibo-mesh-demo-client:0.0.4
ZK_IMAGE=zookeeper
GO_SERVER_CONTAINER_NAME=gserver
GO_CLIENT_CONTAINER_NAME=gclient
ZK_CONTAINER_NAME=weibo-mesh-zk
do_weibo_mesh_hello_world() {
if [ -z "$(docker network ls --format {{.Name}} | grep -e '^weibo-mesh$')" ]; then
docker network create --subnet=172.18.0.0/16 weibo-mesh
fi
sleep 1
docker run -d --rm --name ${ZK_CONTAINER_NAME} \
--net weibo-mesh \
--ip 172.18.0.09 \
${ZK_IMAGE}
sleep 2
docker run -d --rm --name ${GO_SERVER_CONTAINER_NAME} \
-v ${BASE_DIR}/server:/run/server \
-v ${BASE_DIR}/weibo-mesh:/run/weibo-mesh \
-v ${BASE_DIR}/weibo-mesh/server:/run/weibo-mesh/server \
-w /run/weibo-mesh/server \
--net weibo-mesh \
--ip 172.18.0.10 \
--link ${ZK_CONTAINER_NAME}:zookeeper \
${GO_SERVER_IMAGE} /run/weibo-mesh/server_run.sh
sleep 1
docker run -d --rm --name ${GO_CLIENT_CONTAINER_NAME} \
-v ${BASE_DIR}/client:/run/client \
-v ${BASE_DIR}/weibo-mesh:/run/weibo-mesh \
-v ${BASE_DIR}/weibo-mesh/client:/run/weibo-mesh/client \
-w /run/weibo-mesh/client \
--net weibo-mesh \
--ip 172.18.0.20 \
-p 80:9999 \
--link=${GO_SERVER_CONTAINER_NAME} \
--link ${ZK_CONTAINER_NAME}:zookeeper \
${GO_CLIENT_IMAGE} /run/weibo-mesh/client_run.sh
}
dc_clean() {
docker stop ${GO_CLIENT_CONTAINER_NAME} ${GO_SERVER_CONTAINER_NAME} ${ZK_CONTAINER_NAME}
docker network rm weibo-mesh
}
if [ $# != 0 ]; then
if [ $1 == "x" ]; then
dc_clean
elif [ $1 == "-h" ]; then
echo "
./run.sh run hello world demo
./run.sh x clean the container and network
./run.sh -h show this help
"
fi
else
do_weibo_mesh_hello_world
fi