Skip to content
This repository has been archived by the owner on Jun 20, 2024. It is now read-only.

add proxy-env and proxy-config which query weaveproxy for port #848

Merged
merged 1 commit into from
Jun 10, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
18 changes: 12 additions & 6 deletions site/proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,18 @@ interfaces. This can be adjusted with the `-H` argument, e.g.

host1$ weave launch-proxy -H tcp://127.0.0.1:9999

All docker commands can be run via the proxy, so it is safe to
globally adjust your `DOCKER_HOST` to point at the proxy, e.g.
All docker commands can be run via the proxy, so it is safe to adjust
your `DOCKER_HOST` to point at the proxy. Weave provides a convenient
command for this:

host1$ export DOCKER_HOST=tcp://localhost:12375
host1$ eval "$(weave proxy-env)"
host1$ docker ps
...

Alternatively, the proxy host can be set on a per-command basis with

host1$ docker $(weave proxy-config) ps

If you are working with a remote docker daemon, then `localhost` in
the above needs to be replaced with the docker daemon host, and any
firewalls inbetween need to be configured to permit access to
Expand Down Expand Up @@ -137,12 +142,12 @@ to point at the latter:
host1$ weave launch -iprange 10.2.3.0/24
host1$ weave launch-dns 10.2.4.1/24
host1$ weave launch-proxy --with-ipam --with-dns
host1$ export DOCKER_HOST=tcp://localhost:12375
host1$ eval "$(weave proxy-env)"

host2$ weave launch -iprange 10.2.3.0/24 host1
host2$ weave launch-dns 10.2.4.2/24
host2$ weave launch-proxy --with-ipam --with-dns
host2$ export DOCKER_HOST=tcp://localhost:12375
host1$ eval "$(weave proxy-env)"

NB: Note that the two weaveDNS instances must be given unique IPs, on
a subnet different from that used for IP allocation.
Expand Down Expand Up @@ -195,7 +200,8 @@ with

$ mkdir -pv ~/.docker
$ cp -v {ca,cert,key}.pem ~/.docker
$ export DOCKER_HOST=tcp://host1:12375 DOCKER_TLS_VERIFY=1
$ eval "$(weave proxy-env)"
$ export DOCKER_TLS_VERIFY=1
$ docker version
...

Expand Down
13 changes: 13 additions & 0 deletions test/650_proxy_env_test.sh
Original file line number Diff line number Diff line change
@@ -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"

This comment was marked as abuse.


end_suite
25 changes: 25 additions & 0 deletions weave
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -41,6 +43,8 @@ usage() {
echo "weave hide [<cidr> ...]"
echo "weave ps [<container_id> ...]"
echo "weave status"
echo "weave proxy-env"
echo "weave proxy-config"
echo "weave version"
echo "weave stop"
echo "weave stop-dns"
Expand Down Expand Up @@ -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 "$@"
}

Expand Down Expand Up @@ -171,6 +176,7 @@ MTU=65535
PORT=${WEAVE_PORT:-6783}
HTTP_PORT=6784
DNS_HTTP_PORT=6785
PROXY_PORT=12375
PROXY_CONTAINER_NAME=weaveproxy


Expand Down Expand Up @@ -805,6 +811,19 @@ proxy_args() {
done
}

proxy_addr() {
if addr=$(docker logs weaveproxy | head -n3 | grep -oE "proxy listening on .*"); then

This comment was marked as abuse.

This comment was marked as abuse.

This comment was marked as abuse.

addr=${addr##* }
host=${addr%:*}
[ "$host" = "0.0.0.0" ] && host=$PROXY_HOST
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 ] || {
Expand Down Expand Up @@ -953,6 +972,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="
;;

This comment was marked as abuse.

connect)
[ $# -gt 0 ] || usage
if [ "$1" == "--replace" ]; then
Expand Down