diff --git a/proxy/proxy.go b/proxy/proxy.go index d6fdaa13..63bf4fed 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -8,6 +8,7 @@ import ( "net" "net/http" "os" + "path/filepath" "regexp" "strings" "sync" @@ -283,15 +284,16 @@ func (proxy *Proxy) listen(protoAndAddr string) (net.Listener, string, error) { } case "unix": + localAddr := filepath.Join("/host", addr) // remove socket from last invocation - if err := os.Remove(addr); err != nil && !os.IsNotExist(err) { + if err := os.Remove(localAddr); err != nil && !os.IsNotExist(err) { return nil, "", err } - listener, err = net.Listen(proto, addr) + listener, err = net.Listen(proto, localAddr) if err != nil { return nil, "", err } - if err = copyOwnerAndPermissions(dockerSock, addr); err != nil { + if err = copyOwnerAndPermissions(dockerSock, localAddr); err != nil { return nil, "", err } diff --git a/test/650_proxy_env_test.sh b/test/650_proxy_env_test.sh index 593f3d6d..345f661e 100755 --- a/test/650_proxy_env_test.sh +++ b/test/650_proxy_env_test.sh @@ -28,4 +28,10 @@ weave_on $HOST1 stop weave_on $HOST1 launch-proxy -H tcp://0.0.0.0:12375 -H unix:///var/run/weave/weave.sock check +# Check we can use weave env/config with unix -Hs specified +weave_on $HOST1 stop +weave_on $HOST1 launch-proxy -H unix:///var/run/weave/weave.sock +assert_raises "run_on $HOST1 'eval \$(weave env) ; docker $CMD'" +assert_raises "run_on $HOST1 'docker \$(weave config) $CMD'" + end_suite diff --git a/test/690_proxy_autoconfig_test.sh b/test/690_proxy_config_test.sh similarity index 81% rename from test/690_proxy_autoconfig_test.sh rename to test/690_proxy_config_test.sh index ce6e18b2..6293a3f5 100755 --- a/test/690_proxy_autoconfig_test.sh +++ b/test/690_proxy_config_test.sh @@ -2,7 +2,7 @@ . ./config.sh -start_suite "Boot the proxy should only listen on client's interface" +start_suite "Various launch-proxy configurations" # Booting it over unix socket listens on unix socket run_on $HOST1 COVERAGE=$COVERAGE sudo -E weave launch-proxy @@ -22,6 +22,11 @@ assert_raises "run_on $HOST1 sudo docker -H unix:///var/run/weave/weave.sock ps" assert_raises "proxy docker_on $HOST1 ps" weave_on $HOST1 stop-proxy +# Booting it with -H outside /var/run/weave, still works +socket="$(mktemp -d)/weave.sock" +weave_on $HOST1 launch-proxy -H unix://$socket +assert_raises "run_on $HOST1 sudo docker -H unix:///$socket ps" 0 +weave_on $HOST1 stop-proxy # Booting it over tls errors assert_raises "DOCKER_CLIENT_ARGS='--tls' weave_on $HOST1 launch-proxy" 1 diff --git a/test/gce.sh b/test/gce.sh index b1cc7cca..ae22739a 100755 --- a/test/gce.sh +++ b/test/gce.sh @@ -140,7 +140,7 @@ function hosts { hosts="$hostname $hosts" args="--add-host=$hostname:$(internal_ip $json $name) $args" done - echo export SSH=ssh + echo export SSH=\"ssh -l vagrant\" echo export HOSTS=\"$hosts\" echo export ADD_HOST_ARGS=\"$args\" rm $json diff --git a/weave b/weave index 460936d6..987c9c2e 100755 --- a/weave +++ b/weave @@ -96,6 +96,7 @@ usage() { exec_remote() { docker $DOCKER_CLIENT_ARGS run --rm --privileged --net=host \ -v /var/run/docker.sock:/var/run/docker.sock \ + -v /var/run:/host/var/run \ -v /proc:/hostproc \ -e PROCFS=/hostproc \ -e DOCKERHUB_USER="$DOCKERHUB_USER" \ @@ -1261,17 +1262,36 @@ tls_arg() { PROXY_ARGS="$PROXY_ARGS $1 /home/weave/tls/$3.pem" } +# TODO: Handle relative paths for args +# TODO: Handle args with spaces +host_arg() { + PROXY_HOST="$1" + if [ "$PROXY_HOST" != "${PROXY_HOST#unix://}" ]; then + host=$(dirname ${PROXY_HOST#unix://}) + if [ "$host" = "${host#/}" ]; then + echo "When launching the proxy, unix sockets must be specified as an absolute path." >&2 + exit 1 + fi + if [ "$host" = "/var/run" ]; then + host=/var/run/weave + PROXY_VAR_RUN_SYMLINKS="$PROXY_VAR_RUN_SYMLINKS $(basename ${PROXY_HOST#unix://})" + fi + PROXY_VOLUMES="$PROXY_VOLUMES -v $host:/host$host" + PROXY_ARGS="$PROXY_ARGS -H unix://$host/$(basename ${PROXY_HOST#unix://})" + else + PROXY_ARGS="$PROXY_ARGS -H $1" + fi +} + proxy_parse_args() { while [ $# -gt 0 ]; do case "$1" in -H) - PROXY_HOST="$2" - PROXY_ARGS="$PROXY_ARGS $1 $2" + host_arg "$2" shift ;; -H=*) - PROXY_HOST="${1#*=}" - PROXY_ARGS="$PROXY_ARGS $1" + host_arg "${1#*=}" ;; -no-detect-tls|--no-detect-tls) PROXY_TLS_DETECTION_DISABLED=1 @@ -1332,7 +1352,7 @@ proxy_args() { PROXY_HOST="tcp://0.0.0.0:12375" ;; esac - PROXY_ARGS="$PROXY_ARGS -H $PROXY_HOST" + host_arg "$PROXY_HOST" fi } @@ -1537,7 +1557,6 @@ launch_proxy() { PROXY_CONTAINER=$(docker run --privileged -d --name=$PROXY_CONTAINER_NAME --net=host \ $PROXY_VOLUMES \ -v /var/run/docker.sock:/var/run/docker.sock \ - -v /var/run/weave:/var/run/weave \ -v /proc:/hostproc \ -e PROCFS=/hostproc \ -e WEAVE_CIDR=none \ @@ -1547,6 +1566,9 @@ launch_proxy() { --entrypoint=/home/weave/weaveproxy \ $WEAVEPROXY_DOCKER_ARGS $EXEC_IMAGE $COVERAGE_ARGS $PROXY_ARGS) wait_for_status $PROXY_CONTAINER_NAME http_call_unix $PROXY_CONTAINER_NAME status.sock + for sock in $PROXY_VAR_RUN_SYMLINKS; do + ln -sf -T "/var/run/weave/$sock" "/host/var/run/$sock" + done } stop_proxy() {