From 169eb195235b99ec5f223f503458670fb064470f Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Thu, 28 May 2015 12:54:21 +0100 Subject: [PATCH 1/3] allow proxy to intercept unversioned (i.e. 1.0) urls --- proxy/common.go | 4 ++-- proxy/proxy.go | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/proxy/common.go b/proxy/common.go index 1198ef1b..6f6480fb 100644 --- a/proxy/common.go +++ b/proxy/common.go @@ -15,7 +15,7 @@ import ( ) var ( - containerIDRegexp = regexp.MustCompile("^/v[0-9\\.]*/containers/([^/]*)/.*") + containerIDRegexp = regexp.MustCompile("^(/v[0-9\\.]*)?/containers/([^/]*)/.*") weaveWaitEntrypoint = []string{"/home/weavewait/weavewait"} ) @@ -54,7 +54,7 @@ func inspectContainerInPath(client *docker.Client, path string) (*docker.Contain Warning.Println(err) return nil, err } - containerID := subs[1] + containerID := subs[2] container, err := client.InspectContainer(containerID) if err != nil { diff --git a/proxy/proxy.go b/proxy/proxy.go index ee820a21..f781385b 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -12,9 +12,9 @@ import ( ) var ( - containerCreateRegexp = regexp.MustCompile("/v[0-9\\.]*/containers/create") - containerStartRegexp = regexp.MustCompile("^/v[0-9\\.]*/containers/[^/]*/(re)?start$") - execCreateRegexp = regexp.MustCompile("^/v[0-9\\.]*/containers/[^/]*/exec$") + containerCreateRegexp = regexp.MustCompile("^(/v[0-9\\.]*)?/containers/create$") + containerStartRegexp = regexp.MustCompile("^(/v[0-9\\.]*)?/containers/[^/]*/(re)?start$") + execCreateRegexp = regexp.MustCompile("^(/v[0-9\\.]*)?/containers/[^/]*/exec$") ) type Proxy struct { From c8b95a252748b84fe2328ea9daf76258bfebcf97 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Thu, 28 May 2015 16:12:48 +0100 Subject: [PATCH 2/3] fix bug in proxy handling of minimal request bodies --- proxy/create_container_interceptor.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/proxy/create_container_interceptor.go b/proxy/create_container_interceptor.go index 3aae2df4..3585fbd2 100644 --- a/proxy/create_container_interceptor.go +++ b/proxy/create_container_interceptor.go @@ -38,7 +38,13 @@ func (i *createContainerInterceptor) InterceptRequest(r *http.Request) error { if cidrs, ok := weaveCIDRsFromConfig(container.Config); ok || i.withIPAM { Info.Printf("Creating container with WEAVE_CIDR \"%s\"", strings.Join(cidrs, " ")) + if container.HostConfig == nil { + container.HostConfig = &docker.HostConfig{} + } container.HostConfig.VolumesFrom = append(container.HostConfig.VolumesFrom, "weaveproxy") + if container.Config == nil { + container.Config = &docker.Config{} + } if err := i.setWeaveWaitEntrypoint(container.Config); err != nil { return err } From 147c7f503ca3b88772bc5a4641ca5d6f25a48ec8 Mon Sep 17 00:00:00 2001 From: Paul Bellamy Date: Thu, 28 May 2015 16:13:42 +0100 Subject: [PATCH 3/3] add curl test for proxy v1.0 api support --- test/620_proxy_entrypoint_command_test.sh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/620_proxy_entrypoint_command_test.sh b/test/620_proxy_entrypoint_command_test.sh index e03b9a10..d216077d 100755 --- a/test/620_proxy_entrypoint_command_test.sh +++ b/test/620_proxy_entrypoint_command_test.sh @@ -32,4 +32,22 @@ weave_on $HOST1 launch-proxy --with-ipam assert_raises "proxy docker_on $HOST1 run check-ethwe-up" +create_container_json=$(cat <<-EOF +{ + "Hostname":"c1", + "AttachStdin":false, + "AttachStdout":true, + "AttachStderr":true, + "Tty":false, + "OpenStdin":false, + "StdinOnce":false, + "Image":"check-ethwe-up" +} +EOF +) + +# Test a minimal request to the unversioned (v1.0) docker api +CONTAINER_ID=$(curl -s -X POST --header "Content-Type: application/json" http://$HOST1:12375/containers/create -d "$create_container_json" | sed -e 's/.*"Id":"\([^"]*\)".*/\1/') +assert_raises "proxy docker_on $HOST1 start -ai $CONTAINER_ID" + end_suite