From f0921efd09a3c3ebce462a9a6dd529f03bdaf387 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Wed, 10 Jun 2015 12:43:31 +0100 Subject: [PATCH] [proxy] use logs for getting proxy-env and proxy-config It's ugly, but beats arg-parsing, inspecting the container and piecing the address together from exposed ports. We could just use the host from DOCKER_HOST, but that will fail in the case of a host with multiple IPs, where the proxy only listens on one. --- proxy/proxy.go | 2 +- test/650_proxy_env_test.sh | 13 +++++++++++++ weave | 24 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 test/650_proxy_env_test.sh diff --git a/proxy/proxy.go b/proxy/proxy.go index 240e098b25..1751b48c65 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -108,7 +108,7 @@ func (proxy *Proxy) ListenAndServe() error { listener = tls.NewListener(listener, proxy.TLSConfig.Config) } - Info.Println("proxy listening") + Info.Println("proxy listening on", proxy.ListenAddr) return (&http.Server{Handler: proxy}).Serve(listener) } diff --git a/test/650_proxy_env_test.sh b/test/650_proxy_env_test.sh new file mode 100644 index 0000000000..20a65729a4 --- /dev/null +++ b/test/650_proxy_env_test.sh @@ -0,0 +1,13 @@ +#! /bin/bash + +. ./config.sh + +start_suite "Configure the docker daemon for the proxy" + +weave_on $HOST1 launch-proxy + +CMD="run -e WEAVE_CIDR=10.2.1.4/24 $BASE_IMAGE $CHECK_ETHWE_UP" +assert_raises "eval '$(weave_on $HOST1 proxy-env)' ; docker $CMD" +assert_raises "docker $(weave_on $HOST1 proxy-config) $CMD" + +end_suite diff --git a/weave b/weave index 68603848a9..cc93d9209c 100755 --- a/weave +++ b/weave @@ -16,6 +16,8 @@ IMAGE_VERSION=${VERSION:-$IMAGE_VERSION} DOCKERHUB_USER=weaveworks BASE_EXEC_IMAGE=$DOCKERHUB_USER/weaveexec EXEC_IMAGE=$BASE_EXEC_IMAGE:$IMAGE_VERSION +PROXY_HOST=${PROXY_HOST:-$(echo "${DOCKER_HOST#tcp://}" | cut -s -d: -f1)} +PROXY_HOST=${PROXY_HOST:-127.0.0.1} # Define some regular expressions for matching addresses. # The regexp here is far from precise, but good enough. @@ -41,6 +43,8 @@ usage() { echo "weave hide [ ...]" echo "weave ps [ ...]" echo "weave status" + echo "weave proxy-env" + echo "weave proxy-config" echo "weave version" echo "weave stop" echo "weave stop-dns" @@ -69,6 +73,7 @@ exec_remote() { -e WEAVE_PORT \ -e WEAVE_CONTAINER_NAME \ -e DOCKER_BRIDGE \ + -e PROXY_HOST="$PROXY_HOST" \ $WEAVEEXEC_DOCKER_ARGS $EXEC_IMAGE --local "$@" } @@ -171,6 +176,7 @@ MTU=65535 PORT=${WEAVE_PORT:-6783} HTTP_PORT=6784 DNS_HTTP_PORT=6785 +PROXY_PORT=12375 PROXY_CONTAINER_NAME=weaveproxy @@ -805,6 +811,18 @@ proxy_args() { done } +proxy_addr() { + if addr=$(docker logs weaveproxy | grep -oE "proxy listening on .*"); then + addr=${addr##* } + host=${addr%:*} + port=${addr#*:} + echo "${1}tcp://${host:-$PROXY_HOST}:${port:-$PROXY_PORT}" + return 0 + fi + echo "$PROXY_CONTAINER_NAME container is not present. Have you launched it?" >&2 + return 1 +} + ########################################################################################## [ $(id -u) = 0 ] || { @@ -953,6 +971,12 @@ case "$COMMAND" in wait_for_log $PROXY_CONTAINER_NAME "proxy listening" echo $PROXY_CONTAINER ;; + proxy-env) + proxy_addr "export DOCKER_HOST=" + ;; + proxy-config) + proxy_addr "-H=" + ;; connect) [ $# -gt 0 ] || usage if [ "$1" == "--replace" ]; then