function inst_id2port() { echo $((41000+${1}-1)) } function dnet_container_name() { echo dnet-$1-$2 } function start_consul() { stop_consul 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 sleep 2 } function stop_consul() { echo "consul started" docker stop pr_consul || true # You cannot destroy a container in Circle CI. So do not attempt destroy in circleci if [ -z "$CIRCLECI" ]; then docker rm -f pr_consul || true fi } function start_dnet() { inst=$1 shift suffix=$1 shift stop_dnet ${inst} ${suffix} name=$(dnet_container_name ${inst} ${suffix}) hport=$((41000+${inst}-1)) cport=2385 hopt="" isnum='^[0-9]+$' while [ -n "$1" ] do if [[ "$1" =~ ^[0-9]+$ ]] then hport=$1 cport=$1 hopt="-H tcp://0.0.0.0:${cport}" else neighip=$1 fi shift done bridge_ip=$(docker inspect --format '{{.NetworkSettings.Gateway}}' pr_consul) if [ -z "$neighip" ]; then labels="\"com.docker.network.driver.overlay.bind_interface=eth0\"" else labels="\"com.docker.network.driver.overlay.bind_interface=eth0\", \"com.docker.network.driver.overlay.neighbor_ip=${neighip}\"" fi mkdir -p /tmp/dnet/${name} tomlfile="/tmp/dnet/${name}/libnetwork.toml" cat > ${tomlfile} <