From 792d7eb3adabc22b609286507e93ffc4897de2ea Mon Sep 17 00:00:00 2001 From: Fabian Ruff Date: Thu, 12 Feb 2015 23:21:00 +0100 Subject: [PATCH 1/4] add boot2docker ip to NO_PROXY list The docker client respects the HTTP_PROXY environment variable for api calls since version 1.5. This kind of breaks the boot2docker scenario because docker is running on a local VM which most most certainly won't be reachable by the proxy. This commit changes `boot2docker shellinit` to append the DOCKER_HOST to the NO_PROXY variable. --- cmds.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/cmds.go b/cmds.go index fbe78ef..b294e9c 100644 --- a/cmds.go +++ b/cmds.go @@ -228,6 +228,34 @@ func exports(socket, certPath string) map[string]string { out["DOCKER_TLS_VERIFY"] = "1" } + //if a http_proxy is set, we need to make sure the boot2docker ip + //is added to the NO_PROXY environment variable + if os.Getenv("http_proxy") != "" || os.Getenv("HTTP_PROXY") != "" { + //get the ip from the docket/DOCKER_HOST + re := regexp.MustCompile("tcp://([^:]+):") + if matches := re.FindStringSubmatch(socket); len(matches) == 2 { + ip := matches[1] + + //first check for an existing lower case no_proxy var + no_proxy_var := "no_proxy" + no_proxy_value := os.Getenv("no_proxy") + //otherweise try allcaps HTTP_PROXY + if no_proxy_value == "" { + no_proxy_var = "NO_PROXY" + no_proxy_value = os.Getenv("NO_PROXY") + } + + switch { + case no_proxy_value == "": + out[no_proxy_var] = ip + case strings.Contains(no_proxy_value, ip): + out[no_proxy_var] = no_proxy_value + default: + out[no_proxy_var] = fmt.Sprintf("%s,%s", no_proxy_value, ip) + } + } + } + return out } From 3c74ca3a22b2a860041df72a3875c2293f324166 Mon Sep 17 00:00:00 2001 From: Fabian Ruff Date: Thu, 12 Mar 2015 21:40:13 +0100 Subject: [PATCH 2/4] fix typo --- cmds.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmds.go b/cmds.go index b294e9c..1063783 100644 --- a/cmds.go +++ b/cmds.go @@ -231,7 +231,7 @@ func exports(socket, certPath string) map[string]string { //if a http_proxy is set, we need to make sure the boot2docker ip //is added to the NO_PROXY environment variable if os.Getenv("http_proxy") != "" || os.Getenv("HTTP_PROXY") != "" { - //get the ip from the docket/DOCKER_HOST + //get the ip from socket/DOCKER_HOST re := regexp.MustCompile("tcp://([^:]+):") if matches := re.FindStringSubmatch(socket); len(matches) == 2 { ip := matches[1] From 81f11e1d78d3ecca9b4f2c2908ae4529fb099239 Mon Sep 17 00:00:00 2001 From: Fabian Ruff Date: Thu, 12 Mar 2015 21:42:58 +0100 Subject: [PATCH 3/4] shorten local variable names no_proxy_var -> name no_proxy_value -> val --- cmds.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/cmds.go b/cmds.go index 1063783..2a8e47b 100644 --- a/cmds.go +++ b/cmds.go @@ -237,21 +237,21 @@ func exports(socket, certPath string) map[string]string { ip := matches[1] //first check for an existing lower case no_proxy var - no_proxy_var := "no_proxy" - no_proxy_value := os.Getenv("no_proxy") //otherweise try allcaps HTTP_PROXY - if no_proxy_value == "" { - no_proxy_var = "NO_PROXY" - no_proxy_value = os.Getenv("NO_PROXY") + name := "no_proxy" + val := os.Getenv("no_proxy") + if val == "" { + name = "NO_PROXY" + val = os.Getenv("NO_PROXY") } switch { - case no_proxy_value == "": - out[no_proxy_var] = ip - case strings.Contains(no_proxy_value, ip): - out[no_proxy_var] = no_proxy_value + case val == "": + out[name] = ip + case strings.Contains(val, ip): + out[name] = val default: - out[no_proxy_var] = fmt.Sprintf("%s,%s", no_proxy_value, ip) + out[name] = fmt.Sprintf("%s,%s", val, ip) } } } From 59c644f36d70a853ae2da150618439fe02a1f752 Mon Sep 17 00:00:00 2001 From: Fabian Ruff Date: Thu, 12 Mar 2015 21:43:53 +0100 Subject: [PATCH 4/4] remove comments and empty lines --- cmds.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cmds.go b/cmds.go index 2a8e47b..6cbdff5 100644 --- a/cmds.go +++ b/cmds.go @@ -235,9 +235,6 @@ func exports(socket, certPath string) map[string]string { re := regexp.MustCompile("tcp://([^:]+):") if matches := re.FindStringSubmatch(socket); len(matches) == 2 { ip := matches[1] - - //first check for an existing lower case no_proxy var - //otherweise try allcaps HTTP_PROXY name := "no_proxy" val := os.Getenv("no_proxy") if val == "" { @@ -255,7 +252,6 @@ func exports(socket, certPath string) map[string]string { } } } - return out }