This patch creates a new cli package that allows to combine both client and daemon commands (there is only one daemon command: docker daemon). The `-d` and `--daemon` top-level flags are deprecated and a special message is added to prompt the user to use `docker daemon`. Providing top-level daemon-specific flags for client commands result in an error message prompting the user to use `docker daemon`. This patch does not break any old but correct usages. This also makes `-d` and `--daemon` flags, as well as the `daemon` command illegal in client-only binaries. Signed-off-by: Tibor Vass <tibor@docker.com> Upstream-commit: 96ce3a194aab2807fdd638825b9ea7cb9ba55c36 Component: engine
64 lines
1.6 KiB
Go
64 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"net"
|
|
"os/exec"
|
|
"strings"
|
|
|
|
"github.com/go-check/check"
|
|
)
|
|
|
|
func (s *DockerSuite) TestCliProxyDisableProxyUnixSock(c *check.C) {
|
|
testRequires(c, SameHostDaemon) // test is valid when DOCKER_HOST=unix://..
|
|
|
|
cmd := exec.Command(dockerBinary, "info")
|
|
cmd.Env = appendBaseEnv([]string{"HTTP_PROXY=http://127.0.0.1:9999"})
|
|
|
|
if out, _, err := runCommandWithOutput(cmd); err != nil {
|
|
c.Fatal(err, out)
|
|
}
|
|
|
|
}
|
|
|
|
// Can't use localhost here since go has a special case to not use proxy if connecting to localhost
|
|
// See https://golang.org/pkg/net/http/#ProxyFromEnvironment
|
|
func (s *DockerDaemonSuite) TestCliProxyProxyTCPSock(c *check.C) {
|
|
testRequires(c, SameHostDaemon)
|
|
// get the IP to use to connect since we can't use localhost
|
|
addrs, err := net.InterfaceAddrs()
|
|
if err != nil {
|
|
c.Fatal(err)
|
|
}
|
|
var ip string
|
|
for _, addr := range addrs {
|
|
sAddr := addr.String()
|
|
if !strings.Contains(sAddr, "127.0.0.1") {
|
|
addrArr := strings.Split(sAddr, "/")
|
|
ip = addrArr[0]
|
|
break
|
|
}
|
|
}
|
|
|
|
if ip == "" {
|
|
c.Fatal("could not find ip to connect to")
|
|
}
|
|
|
|
s.d.GlobalFlags = []string{"-H", "tcp://" + ip + ":2375"}
|
|
if err := s.d.Start(); err != nil {
|
|
c.Fatal(err)
|
|
}
|
|
|
|
cmd := exec.Command(dockerBinary, "info")
|
|
cmd.Env = []string{"DOCKER_HOST=tcp://" + ip + ":2375", "HTTP_PROXY=127.0.0.1:9999"}
|
|
if out, _, err := runCommandWithOutput(cmd); err == nil {
|
|
c.Fatal(err, out)
|
|
}
|
|
|
|
// Test with no_proxy
|
|
cmd.Env = append(cmd.Env, "NO_PROXY="+ip)
|
|
if out, _, err := runCommandWithOutput(exec.Command(dockerBinary, "info")); err != nil {
|
|
c.Fatal(err, out)
|
|
}
|
|
|
|
}
|