From aa33b0a950986dae73eaf3f8d12b4bea5267976e Mon Sep 17 00:00:00 2001 From: Tom Wilkie Date: Mon, 19 Oct 2015 13:48:38 +0000 Subject: [PATCH] Make scope work with weave master. --- .gitignore | 1 - Makefile | 8 ++------ docker/Dockerfile | 1 - docker/entrypoint.sh | 34 +++++++++++++++++++++++----------- 4 files changed, 25 insertions(+), 19 deletions(-) diff --git a/.gitignore b/.gitignore index c1ca513666..873a81d29d 100644 --- a/.gitignore +++ b/.gitignore @@ -41,7 +41,6 @@ probe/scope-probe docker/scope-app docker/scope-probe docker/docker* -docker/weave docker/runsvinit experimental/bridge/bridge experimental/demoprobe/demoprobe diff --git a/Makefile b/Makefile index e196b4cd96..db4c022879 100644 --- a/Makefile +++ b/Makefile @@ -25,11 +25,7 @@ all: $(SCOPE_EXPORT) $(DOCKER_DISTRIB): curl -o $(DOCKER_DISTRIB) $(DOCKER_DISTRIB_URL) -docker/weave: - curl -L git.io/weave -o docker/weave - chmod u+x docker/weave - -$(SCOPE_EXPORT): $(APP_EXE) $(PROBE_EXE) $(DOCKER_DISTRIB) docker/weave $(RUNSVINIT) docker/Dockerfile docker/run-app docker/run-probe docker/entrypoint.sh +$(SCOPE_EXPORT): $(APP_EXE) $(PROBE_EXE) $(DOCKER_DISTRIB) $(RUNSVINIT) docker/Dockerfile docker/run-app docker/run-probe docker/entrypoint.sh @if [ -z '$(DOCKER_SQUASH)' ] ; then echo "Please install docker-squash by running 'make deps' (and make sure GOPATH/bin is in your PATH)." && exit 1 ; fi cp $(APP_EXE) $(PROBE_EXE) docker/ cp $(DOCKER_DISTRIB) docker/docker.tgz @@ -94,7 +90,7 @@ frontend: $(SCOPE_UI_BUILD_UPTODATE) clean: go clean ./... - rm -rf $(SCOPE_EXPORT) $(SCOPE_UI_BUILD_EXPORT) $(APP_EXE) $(PROBE_EXE) client/build/app.js docker/weave + rm -rf $(SCOPE_EXPORT) $(SCOPE_UI_BUILD_EXPORT) $(APP_EXE) $(PROBE_EXE) client/build/app.js deps: go get -u -f -tags netgo \ diff --git a/docker/Dockerfile b/docker/Dockerfile index c794b56cec..b2885ee2b5 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -6,7 +6,6 @@ RUN echo "http://dl-4.alpinelinux.org/alpine/edge/testing" >>/etc/apk/repositori apk add --update runit conntrack-tools iproute2 util-linux curl && \ rm -rf /var/cache/apk/* ADD ./docker.tgz / -ADD ./weave /usr/bin/ COPY ./scope-app ./scope-probe ./runsvinit ./entrypoint.sh /home/weave/ COPY ./run-app /etc/service/app/run COPY ./run-probe /etc/service/probe/run diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index 0181edb575..c17f2c24f7 100755 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -15,20 +15,21 @@ DOMAIN=weave.local IP_REGEXP="[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}" container_ip() { - if ! status=$(docker inspect --format='{{.State.Running}} {{.NetworkSettings.IPAddress}}' $1 2>/dev/null); then - echo "$2" >&2 + if ! status=$(docker inspect --format='{{.State.Running}} {{.HostConfig.NetworkMode}}' $1 2>/dev/null); then + echo "Container $1 not found" >&2 return 1 fi case "$status" in - "true ") - echo "$1 container has no IP address; is Docker networking enabled?" >&2 - return 1 + "true host") + CONTAINER_IP="127.0.0.1" + return 0 ;; - true*) - CONTAINER_IP="${status#true }" + "true default" | "true bridge") + CONTAINER_IP="$(docker inspect --format='{{.NetworkSettings.IPAddress}}' $1 2>/dev/null)" + return 0 ;; *) - echo "$3" >&2 + echo "Container $1 not running" >&2 return 1 ;; esac @@ -44,11 +45,22 @@ docker_bridge_ip() { echo ${DOCKER_BRIDGE_IP#inet } } +# Run `weave` in the weave exec container +weave() { + WEAVEXEC_IMAGE=$(docker inspect --format='{{.Config.Image}}' weave | sed 's/\/weave/\/weaveexec/') + docker run -t --rm --privileged --net=host \ + -v /var/run/docker.sock:/var/run/docker.sock \ + -v /proc:/hostproc \ + -e PROCFS=/hostproc \ + $WEAVEXEC_IMAGE --local "$@" +} + # Run `weave expose` if it's not already exposed. weave_expose() { - status=$(weave --local ps weave:expose | awk '{print $3}' 2>/dev/null) + status=$(weave ps weave:expose | awk '{print $3}' 2>/dev/null) if [ "$status" = "" ]; then - weave --local expose + echo "Exposing host to weave network." + weave expose fi } @@ -127,7 +139,7 @@ if is_running $WEAVE_CONTAINER_NAME; then exit 1 else for ip in $IP_ADDRS; do - weave --local dns-add $ip $CONTAINER -h $HOSTNAME.$DOMAIN + weave dns-add $ip $CONTAINER -h $HOSTNAME.$DOMAIN done fi fi