Browse code

Apply context changes to the client.

Signed-off-by: David Calavera <david.calavera@gmail.com>

David Calavera authored on 2016/02/04 08:41:26
Showing 17 changed files
... ...
@@ -14,6 +14,8 @@ import (
14 14
 	"runtime"
15 15
 	"strings"
16 16
 
17
+	"golang.org/x/net/context"
18
+
17 19
 	"github.com/docker/docker/api"
18 20
 	"github.com/docker/docker/builder/dockerignore"
19 21
 	Cli "github.com/docker/docker/cli"
... ...
@@ -77,8 +79,8 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
77 77
 	cmd.ParseFlags(args, true)
78 78
 
79 79
 	var (
80
-		context io.ReadCloser
81
-		err     error
80
+		ctx io.ReadCloser
81
+		err error
82 82
 	)
83 83
 
84 84
 	specifiedContext := cmd.Arg(0)
... ...
@@ -100,11 +102,11 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
100 100
 
101 101
 	switch {
102 102
 	case specifiedContext == "-":
103
-		context, relDockerfile, err = getContextFromReader(cli.in, *dockerfileName)
103
+		ctx, relDockerfile, err = getContextFromReader(cli.in, *dockerfileName)
104 104
 	case urlutil.IsGitURL(specifiedContext):
105 105
 		tempDir, relDockerfile, err = getContextFromGitURL(specifiedContext, *dockerfileName)
106 106
 	case urlutil.IsURL(specifiedContext):
107
-		context, relDockerfile, err = getContextFromURL(progBuff, specifiedContext, *dockerfileName)
107
+		ctx, relDockerfile, err = getContextFromURL(progBuff, specifiedContext, *dockerfileName)
108 108
 	default:
109 109
 		contextDir, relDockerfile, err = getContextFromLocalDir(specifiedContext, *dockerfileName)
110 110
 	}
... ...
@@ -121,7 +123,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
121 121
 		contextDir = tempDir
122 122
 	}
123 123
 
124
-	if context == nil {
124
+	if ctx == nil {
125 125
 		// And canonicalize dockerfile name to a platform-independent one
126 126
 		relDockerfile, err = archive.CanonicalTarNameForPath(relDockerfile)
127 127
 		if err != nil {
... ...
@@ -159,7 +161,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
159 159
 			includes = append(includes, ".dockerignore", relDockerfile)
160 160
 		}
161 161
 
162
-		context, err = archive.TarWithOptions(contextDir, &archive.TarOptions{
162
+		ctx, err = archive.TarWithOptions(contextDir, &archive.TarOptions{
163 163
 			Compression:     archive.Uncompressed,
164 164
 			ExcludePatterns: excludes,
165 165
 			IncludeFiles:    includes,
... ...
@@ -173,13 +175,13 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
173 173
 	if isTrusted() {
174 174
 		// Wrap the tar archive to replace the Dockerfile entry with the rewritten
175 175
 		// Dockerfile which uses trusted pulls.
176
-		context = replaceDockerfileTarWrapper(context, relDockerfile, cli.trustedReference, &resolvedTags)
176
+		ctx = replaceDockerfileTarWrapper(ctx, relDockerfile, cli.trustedReference, &resolvedTags)
177 177
 	}
178 178
 
179 179
 	// Setup an upload progress bar
180 180
 	progressOutput := streamformatter.NewStreamFormatter().NewProgressOutput(progBuff, true)
181 181
 
182
-	var body io.Reader = progress.NewProgressReader(context, progressOutput, 0, "", "Sending build context to Docker daemon")
182
+	var body io.Reader = progress.NewProgressReader(ctx, progressOutput, 0, "", "Sending build context to Docker daemon")
183 183
 
184 184
 	var memory int64
185 185
 	if *flMemoryString != "" {
... ...
@@ -235,7 +237,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
235 235
 		AuthConfigs:    cli.configFile.AuthConfigs,
236 236
 	}
237 237
 
238
-	response, err := cli.client.ImageBuild(options)
238
+	response, err := cli.client.ImageBuild(context.Background(), options)
239 239
 	if err != nil {
240 240
 		return err
241 241
 	}
... ...
@@ -15,6 +15,7 @@ import (
15 15
 	"github.com/docker/docker/opts"
16 16
 	"github.com/docker/docker/pkg/term"
17 17
 	"github.com/docker/engine-api/client"
18
+	"github.com/docker/go-connections/sockets"
18 19
 	"github.com/docker/go-connections/tlsconfig"
19 20
 )
20 21
 
... ...
@@ -142,12 +143,12 @@ func NewDockerCli(in io.ReadCloser, out, err io.Writer, clientFlags *cli.ClientF
142 142
 			verStr = tmpStr
143 143
 		}
144 144
 
145
-		clientTransport, err := newClientTransport(clientFlags.Common.TLSOptions)
145
+		httpClient, err := newHTTPClient(host, clientFlags.Common.TLSOptions)
146 146
 		if err != nil {
147 147
 			return err
148 148
 		}
149 149
 
150
-		client, err := client.NewClient(host, verStr, clientTransport, customHeaders)
150
+		client, err := client.NewClient(host, verStr, httpClient, customHeaders)
151 151
 		if err != nil {
152 152
 			return err
153 153
 		}
... ...
@@ -180,16 +181,27 @@ func getServerHost(hosts []string, tlsOptions *tlsconfig.Options) (host string,
180 180
 	return
181 181
 }
182 182
 
183
-func newClientTransport(tlsOptions *tlsconfig.Options) (*http.Transport, error) {
183
+func newHTTPClient(host string, tlsOptions *tlsconfig.Options) (*http.Client, error) {
184 184
 	if tlsOptions == nil {
185
-		return &http.Transport{}, nil
185
+		// let the api client configure the default transport.
186
+		return nil, nil
186 187
 	}
187 188
 
188 189
 	config, err := tlsconfig.Client(*tlsOptions)
189 190
 	if err != nil {
190 191
 		return nil, err
191 192
 	}
192
-	return &http.Transport{
193
+	tr := &http.Transport{
193 194
 		TLSClientConfig: config,
195
+	}
196
+	proto, addr, _, err := client.ParseHost(host)
197
+	if err != nil {
198
+		return nil, err
199
+	}
200
+
201
+	sockets.ConfigureTransport(tr, proto, addr)
202
+
203
+	return &http.Client{
204
+		Transport: tr,
194 205
 	}, nil
195 206
 }
... ...
@@ -7,6 +7,8 @@ import (
7 7
 	"path/filepath"
8 8
 	"strings"
9 9
 
10
+	"golang.org/x/net/context"
11
+
10 12
 	Cli "github.com/docker/docker/cli"
11 13
 	"github.com/docker/docker/pkg/archive"
12 14
 	flag "github.com/docker/docker/pkg/mflag"
... ...
@@ -165,7 +167,7 @@ func (cli *DockerCli) copyFromContainer(srcContainer, srcPath, dstPath string, c
165 165
 
166 166
 	}
167 167
 
168
-	content, stat, err := cli.client.CopyFromContainer(srcContainer, srcPath)
168
+	content, stat, err := cli.client.CopyFromContainer(context.Background(), srcContainer, srcPath)
169 169
 	if err != nil {
170 170
 		return err
171 171
 	}
... ...
@@ -292,5 +294,5 @@ func (cli *DockerCli) copyToContainer(srcPath, dstContainer, dstPath string, cpP
292 292
 		AllowOverwriteDirWithFile: false,
293 293
 	}
294 294
 
295
-	return cli.client.CopyToContainer(options)
295
+	return cli.client.CopyToContainer(context.Background(), options)
296 296
 }
... ...
@@ -5,6 +5,8 @@ import (
5 5
 	"io"
6 6
 	"os"
7 7
 
8
+	"golang.org/x/net/context"
9
+
8 10
 	Cli "github.com/docker/docker/cli"
9 11
 	"github.com/docker/docker/pkg/jsonmessage"
10 12
 	"github.com/docker/docker/reference"
... ...
@@ -52,7 +54,7 @@ func (cli *DockerCli) pullImageCustomOut(image string, out io.Writer) error {
52 52
 		RegistryAuth: encodedAuth,
53 53
 	}
54 54
 
55
-	responseBody, err := cli.client.ImageCreate(options)
55
+	responseBody, err := cli.client.ImageCreate(context.Background(), options)
56 56
 	if err != nil {
57 57
 		return err
58 58
 	}
... ...
@@ -8,6 +8,8 @@ import (
8 8
 	"strings"
9 9
 	"time"
10 10
 
11
+	"golang.org/x/net/context"
12
+
11 13
 	Cli "github.com/docker/docker/cli"
12 14
 	"github.com/docker/docker/opts"
13 15
 	"github.com/docker/docker/pkg/jsonlog"
... ...
@@ -48,7 +50,7 @@ func (cli *DockerCli) CmdEvents(args ...string) error {
48 48
 		Filters: eventFilterArgs,
49 49
 	}
50 50
 
51
-	responseBody, err := cli.client.Events(options)
51
+	responseBody, err := cli.client.Events(context.Background(), options)
52 52
 	if err != nil {
53 53
 		return err
54 54
 	}
... ...
@@ -4,6 +4,8 @@ import (
4 4
 	"errors"
5 5
 	"io"
6 6
 
7
+	"golang.org/x/net/context"
8
+
7 9
 	Cli "github.com/docker/docker/cli"
8 10
 	flag "github.com/docker/docker/pkg/mflag"
9 11
 )
... ...
@@ -24,7 +26,7 @@ func (cli *DockerCli) CmdExport(args ...string) error {
24 24
 		return errors.New("Cowardly refusing to save to a terminal. Use the -o flag or redirect.")
25 25
 	}
26 26
 
27
-	responseBody, err := cli.client.ContainerExport(cmd.Arg(0))
27
+	responseBody, err := cli.client.ContainerExport(context.Background(), cmd.Arg(0))
28 28
 	if err != nil {
29 29
 		return err
30 30
 	}
... ...
@@ -5,6 +5,8 @@ import (
5 5
 	"io"
6 6
 	"os"
7 7
 
8
+	"golang.org/x/net/context"
9
+
8 10
 	Cli "github.com/docker/docker/cli"
9 11
 	"github.com/docker/docker/opts"
10 12
 	"github.com/docker/docker/pkg/jsonmessage"
... ...
@@ -70,7 +72,7 @@ func (cli *DockerCli) CmdImport(args ...string) error {
70 70
 		Changes:        changes,
71 71
 	}
72 72
 
73
-	responseBody, err := cli.client.ImageImport(options)
73
+	responseBody, err := cli.client.ImageImport(context.Background(), options)
74 74
 	if err != nil {
75 75
 		return err
76 76
 	}
... ...
@@ -4,6 +4,8 @@ import (
4 4
 	"io"
5 5
 	"os"
6 6
 
7
+	"golang.org/x/net/context"
8
+
7 9
 	Cli "github.com/docker/docker/cli"
8 10
 	"github.com/docker/docker/pkg/jsonmessage"
9 11
 	flag "github.com/docker/docker/pkg/mflag"
... ...
@@ -30,7 +32,7 @@ func (cli *DockerCli) CmdLoad(args ...string) error {
30 30
 		input = file
31 31
 	}
32 32
 
33
-	response, err := cli.client.ImageLoad(input)
33
+	response, err := cli.client.ImageLoad(context.Background(), input, true)
34 34
 	if err != nil {
35 35
 		return err
36 36
 	}
... ...
@@ -4,6 +4,8 @@ import (
4 4
 	"fmt"
5 5
 	"io"
6 6
 
7
+	"golang.org/x/net/context"
8
+
7 9
 	Cli "github.com/docker/docker/cli"
8 10
 	flag "github.com/docker/docker/pkg/mflag"
9 11
 	"github.com/docker/docker/pkg/stdcopy"
... ...
@@ -48,7 +50,7 @@ func (cli *DockerCli) CmdLogs(args ...string) error {
48 48
 		Follow:      *follow,
49 49
 		Tail:        *tail,
50 50
 	}
51
-	responseBody, err := cli.client.ContainerLogs(options)
51
+	responseBody, err := cli.client.ContainerLogs(context.Background(), options)
52 52
 	if err != nil {
53 53
 		return err
54 54
 	}
... ...
@@ -4,6 +4,8 @@ import (
4 4
 	"errors"
5 5
 	"fmt"
6 6
 
7
+	"golang.org/x/net/context"
8
+
7 9
 	Cli "github.com/docker/docker/cli"
8 10
 	"github.com/docker/docker/pkg/jsonmessage"
9 11
 	flag "github.com/docker/docker/pkg/mflag"
... ...
@@ -77,7 +79,7 @@ func (cli *DockerCli) imagePullPrivileged(authConfig types.AuthConfig, imageID,
77 77
 		RegistryAuth: encodedAuth,
78 78
 	}
79 79
 
80
-	responseBody, err := cli.client.ImagePull(options, requestPrivilege)
80
+	responseBody, err := cli.client.ImagePull(context.Background(), options, requestPrivilege)
81 81
 	if err != nil {
82 82
 		return err
83 83
 	}
... ...
@@ -4,6 +4,8 @@ import (
4 4
 	"errors"
5 5
 	"io"
6 6
 
7
+	"golang.org/x/net/context"
8
+
7 9
 	Cli "github.com/docker/docker/cli"
8 10
 	"github.com/docker/docker/pkg/jsonmessage"
9 11
 	flag "github.com/docker/docker/pkg/mflag"
... ...
@@ -70,5 +72,5 @@ func (cli *DockerCli) imagePushPrivileged(authConfig types.AuthConfig, imageID,
70 70
 		RegistryAuth: encodedAuth,
71 71
 	}
72 72
 
73
-	return cli.client.ImagePush(options, requestPrivilege)
73
+	return cli.client.ImagePush(context.Background(), options, requestPrivilege)
74 74
 }
... ...
@@ -7,6 +7,8 @@ import (
7 7
 	"runtime"
8 8
 	"strings"
9 9
 
10
+	"golang.org/x/net/context"
11
+
10 12
 	"github.com/Sirupsen/logrus"
11 13
 	Cli "github.com/docker/docker/cli"
12 14
 	derr "github.com/docker/docker/errors"
... ...
@@ -269,7 +271,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
269 269
 
270 270
 		// Autoremove: wait for the container to finish, retrieve
271 271
 		// the exit code and remove the container
272
-		if status, err = cli.client.ContainerWait(createResponse.ID); err != nil {
272
+		if status, err = cli.client.ContainerWait(context.Background(), createResponse.ID); err != nil {
273 273
 			return runStartContainerErr(err)
274 274
 		}
275 275
 		if _, status, err = getExitCode(cli, createResponse.ID); err != nil {
... ...
@@ -279,7 +281,7 @@ func (cli *DockerCli) CmdRun(args ...string) error {
279 279
 		// No Autoremove: Simply retrieve the exit code
280 280
 		if !config.Tty {
281 281
 			// In non-TTY mode, we can't detach, so we must wait for container exit
282
-			if status, err = cli.client.ContainerWait(createResponse.ID); err != nil {
282
+			if status, err = cli.client.ContainerWait(context.Background(), createResponse.ID); err != nil {
283 283
 				return err
284 284
 			}
285 285
 		} else {
... ...
@@ -4,6 +4,8 @@ import (
4 4
 	"errors"
5 5
 	"io"
6 6
 
7
+	"golang.org/x/net/context"
8
+
7 9
 	Cli "github.com/docker/docker/cli"
8 10
 	flag "github.com/docker/docker/pkg/mflag"
9 11
 )
... ...
@@ -24,7 +26,7 @@ func (cli *DockerCli) CmdSave(args ...string) error {
24 24
 		return errors.New("Cowardly refusing to save to a terminal. Use the -o flag or redirect.")
25 25
 	}
26 26
 
27
-	responseBody, err := cli.client.ImageSave(cmd.Args())
27
+	responseBody, err := cli.client.ImageSave(context.Background(), cmd.Args())
28 28
 	if err != nil {
29 29
 		return err
30 30
 	}
... ...
@@ -10,6 +10,8 @@ import (
10 10
 	"text/tabwriter"
11 11
 	"time"
12 12
 
13
+	"golang.org/x/net/context"
14
+
13 15
 	Cli "github.com/docker/docker/cli"
14 16
 	"github.com/docker/engine-api/types"
15 17
 	"github.com/docker/engine-api/types/events"
... ...
@@ -37,7 +39,7 @@ type stats struct {
37 37
 }
38 38
 
39 39
 func (s *containerStats) Collect(cli *DockerCli, streamStats bool) {
40
-	responseBody, err := cli.client.ContainerStats(s.Name, streamStats)
40
+	responseBody, err := cli.client.ContainerStats(context.Background(), s.Name, streamStats)
41 41
 	if err != nil {
42 42
 		s.mu.Lock()
43 43
 		s.err = err
... ...
@@ -195,7 +197,7 @@ func (cli *DockerCli) CmdStats(args ...string) error {
195 195
 			options := types.EventsOptions{
196 196
 				Filters: f,
197 197
 			}
198
-			resBody, err := cli.client.Events(options)
198
+			resBody, err := cli.client.Events(context.Background(), options)
199 199
 			if err != nil {
200 200
 				c <- watch{err: err}
201 201
 				return
... ...
@@ -4,6 +4,8 @@ import (
4 4
 	"fmt"
5 5
 	"strings"
6 6
 
7
+	"golang.org/x/net/context"
8
+
7 9
 	Cli "github.com/docker/docker/cli"
8 10
 	flag "github.com/docker/docker/pkg/mflag"
9 11
 )
... ...
@@ -21,7 +23,7 @@ func (cli *DockerCli) CmdWait(args ...string) error {
21 21
 
22 22
 	var errs []string
23 23
 	for _, name := range cmd.Args() {
24
-		status, err := cli.client.ContainerWait(name)
24
+		status, err := cli.client.ContainerWait(context.Background(), name)
25 25
 		if err != nil {
26 26
 			errs = append(errs, err.Error())
27 27
 		} else {
... ...
@@ -194,7 +194,7 @@ func (d *Daemon) getClientConfig() (*clientConfig, error) {
194 194
 		transport = &http.Transport{}
195 195
 	}
196 196
 
197
-	sockets.ConfigureTCPTransport(transport, proto, addr)
197
+	sockets.ConfigureTransport(transport, proto, addr)
198 198
 
199 199
 	return &clientConfig{
200 200
 		transport: transport,
... ...
@@ -30,7 +30,7 @@ func NewClient(addr string, tlsConfig tlsconfig.Options) (*Client, error) {
30 30
 	tr.TLSClientConfig = c
31 31
 
32 32
 	protoAndAddr := strings.Split(addr, "://")
33
-	sockets.ConfigureTCPTransport(tr, protoAndAddr[0], protoAndAddr[1])
33
+	sockets.ConfigureTransport(tr, protoAndAddr[0], protoAndAddr[1])
34 34
 
35 35
 	scheme := protoAndAddr[0]
36 36
 	if scheme != "https" {