2015-09-16 01:26:27 -04:00
|
|
|
function inst_id2port() {
|
|
|
|
echo $((41000+${1}-1))
|
|
|
|
}
|
|
|
|
|
2015-09-19 01:42:33 -04:00
|
|
|
function dnet_container_name() {
|
|
|
|
echo dnet-$1-$2
|
|
|
|
}
|
|
|
|
|
2015-09-08 22:26:54 -04:00
|
|
|
function start_consul() {
|
2015-09-09 19:40:08 -04:00
|
|
|
stop_consul
|
2015-09-16 01:26:27 -04:00
|
|
|
docker run -d \
|
|
|
|
--name=pr_consul \
|
|
|
|
-p 8500:8500 \
|
|
|
|
-p 8300-8302:8300-8302/tcp \
|
|
|
|
-p 8300-8302:8300-8302/udp \
|
|
|
|
-h consul \
|
|
|
|
progrium/consul -server -bootstrap
|
2015-09-08 22:26:54 -04:00
|
|
|
sleep 2
|
|
|
|
}
|
|
|
|
|
|
|
|
function stop_consul() {
|
2015-09-16 01:26:27 -04:00
|
|
|
echo "consul started"
|
2015-09-09 19:40:08 -04:00
|
|
|
docker stop pr_consul || true
|
2015-09-08 22:26:54 -04:00
|
|
|
# You cannot destroy a container in Circle CI. So do not attempt destroy in circleci
|
|
|
|
if [ -z "$CIRCLECI" ]; then
|
2015-09-09 19:40:08 -04:00
|
|
|
docker rm -f pr_consul || true
|
2015-09-08 22:26:54 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function start_dnet() {
|
2015-09-16 01:26:27 -04:00
|
|
|
stop_dnet $1 $2
|
2015-09-19 01:42:33 -04:00
|
|
|
name=$(dnet_container_name $1 $2)
|
|
|
|
if [ -z "$3" ]
|
2015-09-16 01:26:27 -04:00
|
|
|
then
|
|
|
|
hport=$((41000+${1}-1))
|
|
|
|
cport=2385
|
|
|
|
hopt=""
|
|
|
|
else
|
2015-09-19 01:42:33 -04:00
|
|
|
hport=$3
|
|
|
|
cport=$3
|
2015-09-16 01:26:27 -04:00
|
|
|
hopt="-H tcp://0.0.0.0:${cport}"
|
|
|
|
fi
|
2015-09-08 22:26:54 -04:00
|
|
|
|
2015-09-19 01:42:33 -04:00
|
|
|
bridge_ip=$(docker inspect --format '{{.NetworkSettings.Gateway}}' pr_consul)
|
2015-09-08 22:26:54 -04:00
|
|
|
mkdir -p /tmp/dnet/${name}
|
|
|
|
tomlfile="/tmp/dnet/${name}/libnetwork.toml"
|
|
|
|
cat > ${tomlfile} <<EOF
|
|
|
|
title = "LibNetwork Configuration file"
|
|
|
|
|
|
|
|
[daemon]
|
|
|
|
debug = false
|
|
|
|
labels = ["com.docker.network.driver.overlay.bind_interface=eth0"]
|
|
|
|
[datastore]
|
|
|
|
embedded = false
|
|
|
|
[datastore.client]
|
|
|
|
provider = "consul"
|
|
|
|
Address = "${bridge_ip}:8500"
|
|
|
|
EOF
|
2015-09-16 01:26:27 -04:00
|
|
|
docker run \
|
|
|
|
-d \
|
|
|
|
--name=${name} \
|
|
|
|
--privileged \
|
|
|
|
-p ${hport}:${cport} \
|
|
|
|
-v $(pwd)/:/go/src/github.com/docker/libnetwork \
|
|
|
|
-v /tmp:/tmp \
|
|
|
|
-w /go/src/github.com/docker/libnetwork \
|
|
|
|
golang:1.4 ./cmd/dnet/dnet -d -D ${hopt} -c ${tomlfile}
|
2015-09-08 22:26:54 -04:00
|
|
|
sleep 2
|
|
|
|
}
|
|
|
|
|
2015-09-16 01:26:27 -04:00
|
|
|
function skip_for_circleci() {
|
|
|
|
if [ -n "$CIRCLECI" ]; then
|
|
|
|
skip
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-09-08 22:26:54 -04:00
|
|
|
function stop_dnet() {
|
2015-09-19 01:42:33 -04:00
|
|
|
name=$(dnet_container_name $1 $2)
|
2015-09-09 19:40:08 -04:00
|
|
|
rm -rf /tmp/dnet/${name} || true
|
|
|
|
docker stop ${name} || true
|
2015-09-08 22:26:54 -04:00
|
|
|
# You cannot destroy a container in Circle CI. So do not attempt destroy in circleci
|
|
|
|
if [ -z "$CIRCLECI" ]; then
|
2015-09-09 19:40:08 -04:00
|
|
|
docker rm -f ${name} || true
|
2015-09-08 22:26:54 -04:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function dnet_cmd() {
|
2015-09-16 01:26:27 -04:00
|
|
|
hport=$1
|
2015-09-08 22:26:54 -04:00
|
|
|
shift
|
2015-09-16 01:26:27 -04:00
|
|
|
./cmd/dnet/dnet -H tcp://127.0.0.1:${hport} $*
|
2015-09-08 22:26:54 -04:00
|
|
|
}
|