This repository has been archived by the owner on Sep 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-run.sh
executable file
·132 lines (110 loc) · 3.96 KB
/
docker-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
121
122
123
124
125
126
127
128
129
130
#!/bin/bash -eu
#
# Copyright 2018 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#!/bin/bash
set -e
target_count=1
verbose=0
while getopts "hv?t:r:" opt; do
case "$opt" in
h|\?)
echo "Usage:"
echo " -h: Show help"
echo " -t <n>: Number of targets to start"
echo " -v: Output stdout of link containers"
exit 0
;;
t) target_count=$OPTARG
;;
v) verbose=1
;;
esac
done
shift $((OPTIND-1))
function build {
_working=`pwd`;
echo " - Building link-router"
cd link-router/ && ./build.sh > /dev/null && cd $_working
echo " - Building link-zetta-target"
cd link-zetta-target/ && ./build.sh > /dev/null && cd $_working
echo " - Building target-wrapper"
cd target-wrapper/ && ./build.sh > /dev/null && cd $_working
echo " - Building link-tenant-mgmt-api"
cd link-tenant-mgmt-api/ && ./build.sh > /dev/null && cd $_working
}
function cleanup {
echo "Cleaning Up"
for i in `seq 1 $target_count`;
do
docker rm -f zetta.target.$i > /dev/null
done
docker rm -f etcd link-router tenant-mgmt-api > /dev/null
}
trap cleanup EXIT
# Build all containers
echo "Building Containers"
build
echo ""
echo "Starting Services"
# Start Etcd
echo " - Etcd"
docker run -d -p 4001:4001 -p 7001:7001 -p 2379:2379 -p 2380:2380 --name etcd elcolio/etcd:latest -name etcd -advertise-client-urls http://etcd:4001,http://localhost:4001,http://etcd:2379 > /dev/null
sleep 2
# Setup Etcd Dirs
docker run --rm --link etcd -e ETCDCTL_PEERS="http://etcd:4001" peopleperhour/etcdctl set /zetta/version '{"version": "0"}' > /dev/null
docker run --rm --link etcd -e ETCDCTL_PEERS="http://etcd:4001" peopleperhour/etcdctl mkdir /services/zetta > /dev/null
target_env_file=.target.env
echo "" > $target_env_file
echo "ZETTA_STACK=docker-local" >> $target_env_file
echo "LINK_INSTANCE_TYPE=target" >> $target_env_file
echo "INFLUXDB_HOST=influxdb" >> $target_env_file
echo "ETCD_PEER_HOSTS=etcd:4001" >> $target_env_file
# Start Targets
target_links=""
for i in `seq 1 $target_count`;
do
port=`expr $i + 3000`;
target_links="--link zetta.target.$i $target_links"
echo " - Target $i of $target_count on port $port"
docker run -d --link etcd --name zetta.target.$i --env-file $target_env_file -e COREOS_PRIVATE_IPV4=zetta.target.$i -p $port:$port -e VERSION=0 -e MAPPED_PORT=$port zetta/zetta-target-server-wrapper > /dev/null
done
sleep 2;
# Start Routers
router_env_file=.router.env
echo "" > $router_env_file
echo "ZETTA_STACK=docker-local" >> $router_env_file
echo "LINK_INSTANCE_TYPE=router" >> $router_env_file
echo "INFLUXDB_HOST=influxdb" >> $router_env_file
echo "ETCD_PEER_HOSTS=etcd:4001" >> $router_env_file
echo " - Link Router"
docker run -d --name link-router --link etcd $target_links --env-file $router_env_file -e PORT=3000 -p 3000:3000 zetta/zetta-cloud-proxy > /dev/null
echo " - Tenant Management Api"
docker run -d --name tenant-mgmt-api --link etcd $target_links -e ETCD_PEER_HOSTS="etcd:4001" -p 2000:2000 zetta/link-tenant-mgmt-api > /dev/null
echo ""
echo ""
echo "Link Router Running at http://localhost:3000"
echo "Tenant Mgmt Api Running at http://localhost:2000"
if [ "$verbose" -eq 1 ]; then
docker logs -f link-router &
for i in `seq 1 $target_count`;
do
docker logs -f zetta.target.$i &
done
docker logs -f tenant-mgmt-api &
wait;
fi
while [ "1" -eq "1" ]; do
sleep 1;
done