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" "runtime"
"strings" "strings"
"golang.org/x/net/context"
"github.com/docker/docker/api" "github.com/docker/docker/api"
"github.com/docker/docker/builder/dockerignore" "github.com/docker/docker/builder/dockerignore"
Cli "github.com/docker/docker/cli" Cli "github.com/docker/docker/cli"
@ -77,8 +79,8 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
cmd.ParseFlags(args, true) cmd.ParseFlags(args, true)
var ( var (
context io.ReadCloser ctx io.ReadCloser
err error err error
) )
specifiedContext := cmd.Arg(0) specifiedContext := cmd.Arg(0)
@ -100,11 +102,11 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
switch { switch {
case specifiedContext == "-": case specifiedContext == "-":
context, relDockerfile, err = getContextFromReader(cli.in, *dockerfileName) ctx, relDockerfile, err = getContextFromReader(cli.in, *dockerfileName)
case urlutil.IsGitURL(specifiedContext): case urlutil.IsGitURL(specifiedContext):
tempDir, relDockerfile, err = getContextFromGitURL(specifiedContext, *dockerfileName) tempDir, relDockerfile, err = getContextFromGitURL(specifiedContext, *dockerfileName)
case urlutil.IsURL(specifiedContext): case urlutil.IsURL(specifiedContext):
context, relDockerfile, err = getContextFromURL(progBuff, specifiedContext, *dockerfileName) ctx, relDockerfile, err = getContextFromURL(progBuff, specifiedContext, *dockerfileName)
default: default:
contextDir, relDockerfile, err = getContextFromLocalDir(specifiedContext, *dockerfileName) contextDir, relDockerfile, err = getContextFromLocalDir(specifiedContext, *dockerfileName)
} }
@ -121,7 +123,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
contextDir = tempDir contextDir = tempDir
} }
if context == nil { if ctx == nil {
// And canonicalize dockerfile name to a platform-independent one // And canonicalize dockerfile name to a platform-independent one
relDockerfile, err = archive.CanonicalTarNameForPath(relDockerfile) relDockerfile, err = archive.CanonicalTarNameForPath(relDockerfile)
if err != nil { if err != nil {
@ -159,7 +161,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
includes = append(includes, ".dockerignore", relDockerfile) includes = append(includes, ".dockerignore", relDockerfile)
} }
context, err = archive.TarWithOptions(contextDir, &archive.TarOptions{ ctx, err = archive.TarWithOptions(contextDir, &archive.TarOptions{
Compression: archive.Uncompressed, Compression: archive.Uncompressed,
ExcludePatterns: excludes, ExcludePatterns: excludes,
IncludeFiles: includes, IncludeFiles: includes,
@ -173,13 +175,13 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
if isTrusted() { if isTrusted() {
// Wrap the tar archive to replace the Dockerfile entry with the rewritten // Wrap the tar archive to replace the Dockerfile entry with the rewritten
// Dockerfile which uses trusted pulls. // Dockerfile which uses trusted pulls.
context = replaceDockerfileTarWrapper(context, relDockerfile, cli.trustedReference, &resolvedTags) ctx = replaceDockerfileTarWrapper(ctx, relDockerfile, cli.trustedReference, &resolvedTags)
} }
// Setup an upload progress bar // Setup an upload progress bar
progressOutput := streamformatter.NewStreamFormatter().NewProgressOutput(progBuff, true) 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 var memory int64
if *flMemoryString != "" { if *flMemoryString != "" {
@ -235,7 +237,7 @@ func (cli *DockerCli) CmdBuild(args ...string) error {
AuthConfigs: cli.configFile.AuthConfigs, AuthConfigs: cli.configFile.AuthConfigs,
} }
response, err := cli.client.ImageBuild(options) response, err := cli.client.ImageBuild(context.Background(), options)
if err != nil { if err != nil {
return err return err
} }

View file

@ -15,6 +15,7 @@ import (
"github.com/docker/docker/opts" "github.com/docker/docker/opts"
"github.com/docker/docker/pkg/term" "github.com/docker/docker/pkg/term"
"github.com/docker/engine-api/client" "github.com/docker/engine-api/client"
"github.com/docker/go-connections/sockets"
"github.com/docker/go-connections/tlsconfig" "github.com/docker/go-connections/tlsconfig"
) )
@ -142,12 +143,12 @@ func NewDockerCli(in io.ReadCloser, out, err io.Writer, clientFlags *cli.ClientF
verStr = tmpStr verStr = tmpStr
} }
clientTransport, err := newClientTransport(clientFlags.Common.TLSOptions) httpClient, err := newHTTPClient(host, clientFlags.Common.TLSOptions)
if err != nil { if err != nil {
return err return err
} }
client, err := client.NewClient(host, verStr, clientTransport, customHeaders) client, err := client.NewClient(host, verStr, httpClient, customHeaders)
if err != nil { if err != nil {
return err return err
} }
@ -180,16 +181,27 @@ func getServerHost(hosts []string, tlsOptions *tlsconfig.Options) (host string,
return return
} }
func newClientTransport(tlsOptions *tlsconfig.Options) (*http.Transport, error) { func newHTTPClient(host string, tlsOptions *tlsconfig.Options) (*http.Client, error) {
if tlsOptions == nil { if tlsOptions == nil {
return &http.Transport{}, nil // let the api client configure the default transport.
return nil, nil
} }
config, err := tlsconfig.Client(*tlsOptions) config, err := tlsconfig.Client(*tlsOptions)
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &http.Transport{ tr := &http.Transport{
TLSClientConfig: config, 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 }, nil
} }

View file

@ -7,6 +7,8 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"golang.org/x/net/context"
Cli "github.com/docker/docker/cli" Cli "github.com/docker/docker/cli"
"github.com/docker/docker/pkg/archive" "github.com/docker/docker/pkg/archive"
flag "github.com/docker/docker/pkg/mflag" 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 { if err != nil {
return err return err
} }
@ -292,5 +294,5 @@ func (cli *DockerCli) copyToContainer(srcPath, dstContainer, dstPath string, cpP
AllowOverwriteDirWithFile: false, AllowOverwriteDirWithFile: false,
} }
return cli.client.CopyToContainer(options) return cli.client.CopyToContainer(context.Background(), options)
} }

View file

@ -5,6 +5,8 @@ import (
"io" "io"
"os" "os"
"golang.org/x/net/context"
Cli "github.com/docker/docker/cli" Cli "github.com/docker/docker/cli"
"github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/jsonmessage"
"github.com/docker/docker/reference" "github.com/docker/docker/reference"
@ -52,7 +54,7 @@ func (cli *DockerCli) pullImageCustomOut(image string, out io.Writer) error {
RegistryAuth: encodedAuth, RegistryAuth: encodedAuth,
} }
responseBody, err := cli.client.ImageCreate(options) responseBody, err := cli.client.ImageCreate(context.Background(), options)
if err != nil { if err != nil {
return err return err
} }

View file

@ -8,6 +8,8 @@ import (
"strings" "strings"
"time" "time"
"golang.org/x/net/context"
Cli "github.com/docker/docker/cli" Cli "github.com/docker/docker/cli"
"github.com/docker/docker/opts" "github.com/docker/docker/opts"
"github.com/docker/docker/pkg/jsonlog" "github.com/docker/docker/pkg/jsonlog"
@ -48,7 +50,7 @@ func (cli *DockerCli) CmdEvents(args ...string) error {
Filters: eventFilterArgs, Filters: eventFilterArgs,
} }
responseBody, err := cli.client.Events(options) responseBody, err := cli.client.Events(context.Background(), options)
if err != nil { if err != nil {
return err return err
} }

View file

@ -4,6 +4,8 @@ import (
"errors" "errors"
"io" "io"
"golang.org/x/net/context"
Cli "github.com/docker/docker/cli" Cli "github.com/docker/docker/cli"
flag "github.com/docker/docker/pkg/mflag" 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.") 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 { if err != nil {
return err return err
} }

View file

@ -5,6 +5,8 @@ import (
"io" "io"
"os" "os"
"golang.org/x/net/context"
Cli "github.com/docker/docker/cli" Cli "github.com/docker/docker/cli"
"github.com/docker/docker/opts" "github.com/docker/docker/opts"
"github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/jsonmessage"
@ -70,7 +72,7 @@ func (cli *DockerCli) CmdImport(args ...string) error {
Changes: changes, Changes: changes,
} }
responseBody, err := cli.client.ImageImport(options) responseBody, err := cli.client.ImageImport(context.Background(), options)
if err != nil { if err != nil {
return err return err
} }

View file

@ -4,6 +4,8 @@ import (
"io" "io"
"os" "os"
"golang.org/x/net/context"
Cli "github.com/docker/docker/cli" Cli "github.com/docker/docker/cli"
"github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/jsonmessage"
flag "github.com/docker/docker/pkg/mflag" flag "github.com/docker/docker/pkg/mflag"
@ -30,7 +32,7 @@ func (cli *DockerCli) CmdLoad(args ...string) error {
input = file input = file
} }
response, err := cli.client.ImageLoad(input) response, err := cli.client.ImageLoad(context.Background(), input, true)
if err != nil { if err != nil {
return err return err
} }

View file

@ -4,6 +4,8 @@ import (
"fmt" "fmt"
"io" "io"
"golang.org/x/net/context"
Cli "github.com/docker/docker/cli" Cli "github.com/docker/docker/cli"
flag "github.com/docker/docker/pkg/mflag" flag "github.com/docker/docker/pkg/mflag"
"github.com/docker/docker/pkg/stdcopy" "github.com/docker/docker/pkg/stdcopy"
@ -48,7 +50,7 @@ func (cli *DockerCli) CmdLogs(args ...string) error {
Follow: *follow, Follow: *follow,
Tail: *tail, Tail: *tail,
} }
responseBody, err := cli.client.ContainerLogs(options) responseBody, err := cli.client.ContainerLogs(context.Background(), options)
if err != nil { if err != nil {
return err return err
} }

View file

@ -4,6 +4,8 @@ import (
"errors" "errors"
"fmt" "fmt"
"golang.org/x/net/context"
Cli "github.com/docker/docker/cli" Cli "github.com/docker/docker/cli"
"github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/jsonmessage"
flag "github.com/docker/docker/pkg/mflag" flag "github.com/docker/docker/pkg/mflag"
@ -77,7 +79,7 @@ func (cli *DockerCli) imagePullPrivileged(authConfig types.AuthConfig, imageID,
RegistryAuth: encodedAuth, RegistryAuth: encodedAuth,
} }
responseBody, err := cli.client.ImagePull(options, requestPrivilege) responseBody, err := cli.client.ImagePull(context.Background(), options, requestPrivilege)
if err != nil { if err != nil {
return err return err
} }

View file

@ -4,6 +4,8 @@ import (
"errors" "errors"
"io" "io"
"golang.org/x/net/context"
Cli "github.com/docker/docker/cli" Cli "github.com/docker/docker/cli"
"github.com/docker/docker/pkg/jsonmessage" "github.com/docker/docker/pkg/jsonmessage"
flag "github.com/docker/docker/pkg/mflag" flag "github.com/docker/docker/pkg/mflag"
@ -70,5 +72,5 @@ func (cli *DockerCli) imagePushPrivileged(authConfig types.AuthConfig, imageID,
RegistryAuth: encodedAuth, RegistryAuth: encodedAuth,
} }
return cli.client.ImagePush(options, requestPrivilege) return cli.client.ImagePush(context.Background(), options, requestPrivilege)
} }

View file

@ -7,6 +7,8 @@ import (
"runtime" "runtime"
"strings" "strings"
"golang.org/x/net/context"
"github.com/Sirupsen/logrus" "github.com/Sirupsen/logrus"
Cli "github.com/docker/docker/cli" Cli "github.com/docker/docker/cli"
derr "github.com/docker/docker/errors" 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 // Autoremove: wait for the container to finish, retrieve
// the exit code and remove the container // 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) return runStartContainerErr(err)
} }
if _, status, err = getExitCode(cli, createResponse.ID); err != nil { 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 // No Autoremove: Simply retrieve the exit code
if !config.Tty { if !config.Tty {
// In non-TTY mode, we can't detach, so we must wait for container exit // 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 return err
} }
} else { } else {

View file

@ -4,6 +4,8 @@ import (
"errors" "errors"
"io" "io"
"golang.org/x/net/context"
Cli "github.com/docker/docker/cli" Cli "github.com/docker/docker/cli"
flag "github.com/docker/docker/pkg/mflag" 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.") 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 { if err != nil {
return err return err
} }

View file

@ -10,6 +10,8 @@ import (
"text/tabwriter" "text/tabwriter"
"time" "time"
"golang.org/x/net/context"
Cli "github.com/docker/docker/cli" Cli "github.com/docker/docker/cli"
"github.com/docker/engine-api/types" "github.com/docker/engine-api/types"
"github.com/docker/engine-api/types/events" "github.com/docker/engine-api/types/events"
@ -37,7 +39,7 @@ type stats struct {
} }
func (s *containerStats) Collect(cli *DockerCli, streamStats bool) { 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 { if err != nil {
s.mu.Lock() s.mu.Lock()
s.err = err s.err = err
@ -195,7 +197,7 @@ func (cli *DockerCli) CmdStats(args ...string) error {
options := types.EventsOptions{ options := types.EventsOptions{
Filters: f, Filters: f,
} }
resBody, err := cli.client.Events(options) resBody, err := cli.client.Events(context.Background(), options)
if err != nil { if err != nil {
c <- watch{err: err} c <- watch{err: err}
return return

View file

@ -4,6 +4,8 @@ import (
"fmt" "fmt"
"strings" "strings"
"golang.org/x/net/context"
Cli "github.com/docker/docker/cli" Cli "github.com/docker/docker/cli"
flag "github.com/docker/docker/pkg/mflag" flag "github.com/docker/docker/pkg/mflag"
) )
@ -21,7 +23,7 @@ func (cli *DockerCli) CmdWait(args ...string) error {
var errs []string var errs []string
for _, name := range cmd.Args() { for _, name := range cmd.Args() {
status, err := cli.client.ContainerWait(name) status, err := cli.client.ContainerWait(context.Background(), name)
if err != nil { if err != nil {
errs = append(errs, err.Error()) errs = append(errs, err.Error())
} else { } else {

View file

@ -194,7 +194,7 @@ func (d *Daemon) getClientConfig() (*clientConfig, error) {
transport = &http.Transport{} transport = &http.Transport{}
} }
sockets.ConfigureTCPTransport(transport, proto, addr) sockets.ConfigureTransport(transport, proto, addr)
return &clientConfig{ return &clientConfig{
transport: transport, transport: transport,

View file

@ -30,7 +30,7 @@ func NewClient(addr string, tlsConfig tlsconfig.Options) (*Client, error) {
tr.TLSClientConfig = c tr.TLSClientConfig = c
protoAndAddr := strings.Split(addr, "://") protoAndAddr := strings.Split(addr, "://")
sockets.ConfigureTCPTransport(tr, protoAndAddr[0], protoAndAddr[1]) sockets.ConfigureTransport(tr, protoAndAddr[0], protoAndAddr[1])
scheme := protoAndAddr[0] scheme := protoAndAddr[0]
if scheme != "https" { if scheme != "https" {