diff --git a/api/client/build.go b/api/client/build.go index 835f8bf84c..e6a4749d39 100644 --- a/api/client/build.go +++ b/api/client/build.go @@ -14,6 +14,8 @@ import ( "runtime" "strings" + "golang.org/x/net/context" + "github.com/docker/docker/api" "github.com/docker/docker/builder/dockerignore" Cli "github.com/docker/docker/cli" @@ -77,8 +79,8 @@ func (cli *DockerCli) CmdBuild(args ...string) error { cmd.ParseFlags(args, true) var ( - context io.ReadCloser - err error + ctx io.ReadCloser + err error ) specifiedContext := cmd.Arg(0) @@ -100,11 +102,11 @@ func (cli *DockerCli) CmdBuild(args ...string) error { switch { case specifiedContext == "-": - context, relDockerfile, err = getContextFromReader(cli.in, *dockerfileName) + ctx, relDockerfile, err = getContextFromReader(cli.in, *dockerfileName) case urlutil.IsGitURL(specifiedContext): tempDir, relDockerfile, err = getContextFromGitURL(specifiedContext, *dockerfileName) case urlutil.IsURL(specifiedContext): - context, relDockerfile, err = getContextFromURL(progBuff, specifiedContext, *dockerfileName) + ctx, relDockerfile, err = getContextFromURL(progBuff, specifiedContext, *dockerfileName) default: contextDir, relDockerfile, err = getContextFromLocalDir(specifiedContext, *dockerfileName) } @@ -121,7 +123,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error { contextDir = tempDir } - if context == nil { + if ctx == nil { // And canonicalize dockerfile name to a platform-independent one relDockerfile, err = archive.CanonicalTarNameForPath(relDockerfile) if err != nil { @@ -159,7 +161,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error { includes = append(includes, ".dockerignore", relDockerfile) } - context, err = archive.TarWithOptions(contextDir, &archive.TarOptions{ + ctx, err = archive.TarWithOptions(contextDir, &archive.TarOptions{ Compression: archive.Uncompressed, ExcludePatterns: excludes, IncludeFiles: includes, @@ -173,13 +175,13 @@ func (cli *DockerCli) CmdBuild(args ...string) error { if isTrusted() { // Wrap the tar archive to replace the Dockerfile entry with the rewritten // Dockerfile which uses trusted pulls. - context = replaceDockerfileTarWrapper(context, relDockerfile, cli.trustedReference, &resolvedTags) + ctx = replaceDockerfileTarWrapper(ctx, relDockerfile, cli.trustedReference, &resolvedTags) } // Setup an upload progress bar progressOutput := streamformatter.NewStreamFormatter().NewProgressOutput(progBuff, true) - var body io.Reader = progress.NewProgressReader(context, progressOutput, 0, "", "Sending build context to Docker daemon") + var body io.Reader = progress.NewProgressReader(ctx, progressOutput, 0, "", "Sending build context to Docker daemon") var memory int64 if *flMemoryString != "" { @@ -235,7 +237,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error { AuthConfigs: cli.configFile.AuthConfigs, } - response, err := cli.client.ImageBuild(options) + response, err := cli.client.ImageBuild(context.Background(), options) if err != nil { return err } diff --git a/api/client/cli.go b/api/client/cli.go index 35ca93bbc0..fd76fc9dbb 100644 --- a/api/client/cli.go +++ b/api/client/cli.go @@ -15,6 +15,7 @@ import ( "github.com/docker/docker/opts" "github.com/docker/docker/pkg/term" "github.com/docker/engine-api/client" + "github.com/docker/go-connections/sockets" "github.com/docker/go-connections/tlsconfig" ) @@ -142,12 +143,12 @@ func NewDockerCli(in io.ReadCloser, out, err io.Writer, clientFlags *cli.ClientF verStr = tmpStr } - clientTransport, err := newClientTransport(clientFlags.Common.TLSOptions) + httpClient, err := newHTTPClient(host, clientFlags.Common.TLSOptions) if err != nil { return err } - client, err := client.NewClient(host, verStr, clientTransport, customHeaders) + client, err := client.NewClient(host, verStr, httpClient, customHeaders) if err != nil { return err } @@ -180,16 +181,27 @@ func getServerHost(hosts []string, tlsOptions *tlsconfig.Options) (host string, return } -func newClientTransport(tlsOptions *tlsconfig.Options) (*http.Transport, error) { +func newHTTPClient(host string, tlsOptions *tlsconfig.Options) (*http.Client, error) { if tlsOptions == nil { - return &http.Transport{}, nil + // let the api client configure the default transport. + return nil, nil } config, err := tlsconfig.Client(*tlsOptions) if err != nil { return nil, err } - return &http.Transport{ + tr := &http.Transport{ TLSClientConfig: config, + } + proto, addr, _, err := client.ParseHost(host) + if err != nil { + return nil, err + } + + sockets.ConfigureTransport(tr, proto, addr) + + return &http.Client{ + Transport: tr, }, nil } diff --git a/api/client/cp.go b/api/client/cp.go index 43573d906b..8f297ae9c3 100644 --- a/api/client/cp.go +++ b/api/client/cp.go @@ -7,6 +7,8 @@ import ( "path/filepath" "strings" + "golang.org/x/net/context" + Cli "github.com/docker/docker/cli" "github.com/docker/docker/pkg/archive" flag "github.com/docker/docker/pkg/mflag" @@ -165,7 +167,7 @@ func (cli *DockerCli) copyFromContainer(srcContainer, srcPath, dstPath string, c } - content, stat, err := cli.client.CopyFromContainer(srcContainer, srcPath) + content, stat, err := cli.client.CopyFromContainer(context.Background(), srcContainer, srcPath) if err != nil { return err } @@ -292,5 +294,5 @@ func (cli *DockerCli) copyToContainer(srcPath, dstContainer, dstPath string, cpP AllowOverwriteDirWithFile: false, } - return cli.client.CopyToContainer(options) + return cli.client.CopyToContainer(context.Background(), options) } diff --git a/api/client/create.go b/api/client/create.go index 7bddf26cd2..d0417322e9 100644 --- a/api/client/create.go +++ b/api/client/create.go @@ -5,6 +5,8 @@ import ( "io" "os" + "golang.org/x/net/context" + Cli "github.com/docker/docker/cli" "github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/reference" @@ -52,7 +54,7 @@ func (cli *DockerCli) pullImageCustomOut(image string, out io.Writer) error { RegistryAuth: encodedAuth, } - responseBody, err := cli.client.ImageCreate(options) + responseBody, err := cli.client.ImageCreate(context.Background(), options) if err != nil { return err } diff --git a/api/client/events.go b/api/client/events.go index fb3e6903bd..54b88f054b 100644 --- a/api/client/events.go +++ b/api/client/events.go @@ -8,6 +8,8 @@ import ( "strings" "time" + "golang.org/x/net/context" + Cli "github.com/docker/docker/cli" "github.com/docker/docker/opts" "github.com/docker/docker/pkg/jsonlog" @@ -48,7 +50,7 @@ func (cli *DockerCli) CmdEvents(args ...string) error { Filters: eventFilterArgs, } - responseBody, err := cli.client.Events(options) + responseBody, err := cli.client.Events(context.Background(), options) if err != nil { return err } diff --git a/api/client/export.go b/api/client/export.go index 45ddc2052f..a1d3ebe749 100644 --- a/api/client/export.go +++ b/api/client/export.go @@ -4,6 +4,8 @@ import ( "errors" "io" + "golang.org/x/net/context" + Cli "github.com/docker/docker/cli" flag "github.com/docker/docker/pkg/mflag" ) @@ -24,7 +26,7 @@ func (cli *DockerCli) CmdExport(args ...string) error { return errors.New("Cowardly refusing to save to a terminal. Use the -o flag or redirect.") } - responseBody, err := cli.client.ContainerExport(cmd.Arg(0)) + responseBody, err := cli.client.ContainerExport(context.Background(), cmd.Arg(0)) if err != nil { return err } diff --git a/api/client/import.go b/api/client/import.go index 5b8122061c..c96e1e9768 100644 --- a/api/client/import.go +++ b/api/client/import.go @@ -5,6 +5,8 @@ import ( "io" "os" + "golang.org/x/net/context" + Cli "github.com/docker/docker/cli" "github.com/docker/docker/opts" "github.com/docker/docker/pkg/jsonmessage" @@ -70,7 +72,7 @@ func (cli *DockerCli) CmdImport(args ...string) error { Changes: changes, } - responseBody, err := cli.client.ImageImport(options) + responseBody, err := cli.client.ImageImport(context.Background(), options) if err != nil { return err } diff --git a/api/client/load.go b/api/client/load.go index 82cf34d8f2..1df0c08605 100644 --- a/api/client/load.go +++ b/api/client/load.go @@ -4,6 +4,8 @@ import ( "io" "os" + "golang.org/x/net/context" + Cli "github.com/docker/docker/cli" "github.com/docker/docker/pkg/jsonmessage" flag "github.com/docker/docker/pkg/mflag" @@ -30,7 +32,7 @@ func (cli *DockerCli) CmdLoad(args ...string) error { input = file } - response, err := cli.client.ImageLoad(input) + response, err := cli.client.ImageLoad(context.Background(), input, true) if err != nil { return err } diff --git a/api/client/logs.go b/api/client/logs.go index 92b75e0505..76fb4b52ea 100644 --- a/api/client/logs.go +++ b/api/client/logs.go @@ -4,6 +4,8 @@ import ( "fmt" "io" + "golang.org/x/net/context" + Cli "github.com/docker/docker/cli" flag "github.com/docker/docker/pkg/mflag" "github.com/docker/docker/pkg/stdcopy" @@ -48,7 +50,7 @@ func (cli *DockerCli) CmdLogs(args ...string) error { Follow: *follow, Tail: *tail, } - responseBody, err := cli.client.ContainerLogs(options) + responseBody, err := cli.client.ContainerLogs(context.Background(), options) if err != nil { return err } diff --git a/api/client/pull.go b/api/client/pull.go index 61ff02cd81..cd15caaa4f 100644 --- a/api/client/pull.go +++ b/api/client/pull.go @@ -4,6 +4,8 @@ import ( "errors" "fmt" + "golang.org/x/net/context" + Cli "github.com/docker/docker/cli" "github.com/docker/docker/pkg/jsonmessage" flag "github.com/docker/docker/pkg/mflag" @@ -77,7 +79,7 @@ func (cli *DockerCli) imagePullPrivileged(authConfig types.AuthConfig, imageID, RegistryAuth: encodedAuth, } - responseBody, err := cli.client.ImagePull(options, requestPrivilege) + responseBody, err := cli.client.ImagePull(context.Background(), options, requestPrivilege) if err != nil { return err } diff --git a/api/client/push.go b/api/client/push.go index 01e7d9397f..f06a9892ef 100644 --- a/api/client/push.go +++ b/api/client/push.go @@ -4,6 +4,8 @@ import ( "errors" "io" + "golang.org/x/net/context" + Cli "github.com/docker/docker/cli" "github.com/docker/docker/pkg/jsonmessage" flag "github.com/docker/docker/pkg/mflag" @@ -70,5 +72,5 @@ func (cli *DockerCli) imagePushPrivileged(authConfig types.AuthConfig, imageID, RegistryAuth: encodedAuth, } - return cli.client.ImagePush(options, requestPrivilege) + return cli.client.ImagePush(context.Background(), options, requestPrivilege) } diff --git a/api/client/run.go b/api/client/run.go index 845780f0f8..223964d595 100644 --- a/api/client/run.go +++ b/api/client/run.go @@ -7,6 +7,8 @@ import ( "runtime" "strings" + "golang.org/x/net/context" + "github.com/Sirupsen/logrus" Cli "github.com/docker/docker/cli" derr "github.com/docker/docker/errors" @@ -269,7 +271,7 @@ func (cli *DockerCli) CmdRun(args ...string) error { // Autoremove: wait for the container to finish, retrieve // the exit code and remove the container - if status, err = cli.client.ContainerWait(createResponse.ID); err != nil { + if status, err = cli.client.ContainerWait(context.Background(), createResponse.ID); err != nil { return runStartContainerErr(err) } if _, status, err = getExitCode(cli, createResponse.ID); err != nil { @@ -279,7 +281,7 @@ func (cli *DockerCli) CmdRun(args ...string) error { // No Autoremove: Simply retrieve the exit code if !config.Tty { // In non-TTY mode, we can't detach, so we must wait for container exit - if status, err = cli.client.ContainerWait(createResponse.ID); err != nil { + if status, err = cli.client.ContainerWait(context.Background(), createResponse.ID); err != nil { return err } } else { diff --git a/api/client/save.go b/api/client/save.go index 5c16180e3d..4aabf1bd5d 100644 --- a/api/client/save.go +++ b/api/client/save.go @@ -4,6 +4,8 @@ import ( "errors" "io" + "golang.org/x/net/context" + Cli "github.com/docker/docker/cli" flag "github.com/docker/docker/pkg/mflag" ) @@ -24,7 +26,7 @@ func (cli *DockerCli) CmdSave(args ...string) error { return errors.New("Cowardly refusing to save to a terminal. Use the -o flag or redirect.") } - responseBody, err := cli.client.ImageSave(cmd.Args()) + responseBody, err := cli.client.ImageSave(context.Background(), cmd.Args()) if err != nil { return err } diff --git a/api/client/stats.go b/api/client/stats.go index 46f4c04b9f..0bfbe43f9d 100644 --- a/api/client/stats.go +++ b/api/client/stats.go @@ -10,6 +10,8 @@ import ( "text/tabwriter" "time" + "golang.org/x/net/context" + Cli "github.com/docker/docker/cli" "github.com/docker/engine-api/types" "github.com/docker/engine-api/types/events" @@ -37,7 +39,7 @@ type stats struct { } func (s *containerStats) Collect(cli *DockerCli, streamStats bool) { - responseBody, err := cli.client.ContainerStats(s.Name, streamStats) + responseBody, err := cli.client.ContainerStats(context.Background(), s.Name, streamStats) if err != nil { s.mu.Lock() s.err = err @@ -195,7 +197,7 @@ func (cli *DockerCli) CmdStats(args ...string) error { options := types.EventsOptions{ Filters: f, } - resBody, err := cli.client.Events(options) + resBody, err := cli.client.Events(context.Background(), options) if err != nil { c <- watch{err: err} return diff --git a/api/client/wait.go b/api/client/wait.go index 0e9f0b3962..609cd3be42 100644 --- a/api/client/wait.go +++ b/api/client/wait.go @@ -4,6 +4,8 @@ import ( "fmt" "strings" + "golang.org/x/net/context" + Cli "github.com/docker/docker/cli" flag "github.com/docker/docker/pkg/mflag" ) @@ -21,7 +23,7 @@ func (cli *DockerCli) CmdWait(args ...string) error { var errs []string for _, name := range cmd.Args() { - status, err := cli.client.ContainerWait(name) + status, err := cli.client.ContainerWait(context.Background(), name) if err != nil { errs = append(errs, err.Error()) } else { diff --git a/integration-cli/docker_utils.go b/integration-cli/docker_utils.go index 04bb5b4079..f4b6841e7f 100644 --- a/integration-cli/docker_utils.go +++ b/integration-cli/docker_utils.go @@ -194,7 +194,7 @@ func (d *Daemon) getClientConfig() (*clientConfig, error) { transport = &http.Transport{} } - sockets.ConfigureTCPTransport(transport, proto, addr) + sockets.ConfigureTransport(transport, proto, addr) return &clientConfig{ transport: transport, diff --git a/pkg/plugins/client.go b/pkg/plugins/client.go index ba7772dfbb..72c7331c78 100644 --- a/pkg/plugins/client.go +++ b/pkg/plugins/client.go @@ -30,7 +30,7 @@ func NewClient(addr string, tlsConfig tlsconfig.Options) (*Client, error) { tr.TLSClientConfig = c protoAndAddr := strings.Split(addr, "://") - sockets.ConfigureTCPTransport(tr, protoAndAddr[0], protoAndAddr[1]) + sockets.ConfigureTransport(tr, protoAndAddr[0], protoAndAddr[1]) scheme := protoAndAddr[0] if scheme != "https" {