1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Apply context changes to the client.

Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
David Calavera 2016-02-03 18:41:26 -05:00
parent d8355ead9e
commit fe53be4e17
17 changed files with 72 additions and 32 deletions

View file

@ -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,7 +79,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
cmd.ParseFlags(args, true)
var (
context io.ReadCloser
ctx io.ReadCloser
err error
)
@ -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
}

View file

@ -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
}

View file

@ -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)
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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
}

View file

@ -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)
}

View file

@ -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 {

View file

@ -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
}

View file

@ -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

View file

@ -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 {

View file

@ -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,

View file

@ -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" {