Skip to content

Commit 44ac808

Browse files
committed
Update vendoring of docker/docker
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
1 parent d95fd2f commit 44ac808

File tree

51 files changed

+492
-1207
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+492
-1207
lines changed

cli/command/config/create.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/docker/cli/opts"
1111
"github.com/docker/docker/api/types/swarm"
1212
"github.com/docker/docker/pkg/system"
13-
runconfigopts "github.com/docker/docker/runconfig/opts"
1413
"github.com/pkg/errors"
1514
"github.com/spf13/cobra"
1615
"golang.org/x/net/context"
@@ -65,7 +64,7 @@ func runConfigCreate(dockerCli command.Cli, options createOptions) error {
6564
spec := swarm.ConfigSpec{
6665
Annotations: swarm.Annotations{
6766
Name: options.name,
68-
Labels: runconfigopts.ConvertKVStringsToMap(options.labels.GetAll()),
67+
Labels: opts.ConvertKVStringsToMap(options.labels.GetAll()),
6968
},
7069
Data: configData,
7170
}

cli/command/container/opts.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import (
1717
networktypes "github.com/docker/docker/api/types/network"
1818
"github.com/docker/docker/api/types/strslice"
1919
"github.com/docker/docker/pkg/signal"
20-
runconfigopts "github.com/docker/docker/runconfig/opts"
2120
"github.com/docker/go-connections/nat"
2221
"github.com/pkg/errors"
2322
"github.com/spf13/pflag"
@@ -409,13 +408,13 @@ func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, err
409408
}
410409

411410
// collect all the environment variables for the container
412-
envVariables, err := runconfigopts.ReadKVStrings(copts.envFile.GetAll(), copts.env.GetAll())
411+
envVariables, err := opts.ReadKVStrings(copts.envFile.GetAll(), copts.env.GetAll())
413412
if err != nil {
414413
return nil, err
415414
}
416415

417416
// collect all the labels for the container
418-
labels, err := runconfigopts.ReadKVStrings(copts.labelsFile.GetAll(), copts.labels.GetAll())
417+
labels, err := opts.ReadKVStrings(copts.labelsFile.GetAll(), copts.labels.GetAll())
419418
if err != nil {
420419
return nil, err
421420
}
@@ -440,7 +439,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, err
440439
return nil, errors.Errorf("--userns: invalid USER mode")
441440
}
442441

443-
restartPolicy, err := runconfigopts.ParseRestartPolicy(copts.restartPolicy)
442+
restartPolicy, err := opts.ParseRestartPolicy(copts.restartPolicy)
444443
if err != nil {
445444
return nil, err
446445
}
@@ -553,7 +552,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, err
553552
MacAddress: copts.macAddress,
554553
Entrypoint: entrypoint,
555554
WorkingDir: copts.workingDir,
556-
Labels: runconfigopts.ConvertKVStringsToMap(labels),
555+
Labels: opts.ConvertKVStringsToMap(labels),
557556
Healthcheck: healthConfig,
558557
}
559558
if flags.Changed("stop-signal") {
@@ -666,7 +665,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, err
666665
}
667666

668667
func parseLoggingOpts(loggingDriver string, loggingOpts []string) (map[string]string, error) {
669-
loggingOptsMap := runconfigopts.ConvertKVStringsToMap(loggingOpts)
668+
loggingOptsMap := opts.ConvertKVStringsToMap(loggingOpts)
670669
if loggingDriver == "none" && len(loggingOpts) > 0 {
671670
return map[string]string{}, errors.Errorf("invalid logging opts for driver %s", loggingDriver)
672671
}

cli/command/container/run.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io"
66
"net/http/httputil"
77
"os"
8+
"regexp"
89
"runtime"
910
"strings"
1011
"syscall"
@@ -17,7 +18,6 @@ import (
1718
"github.com/docker/docker/pkg/promise"
1819
"github.com/docker/docker/pkg/signal"
1920
"github.com/docker/docker/pkg/term"
20-
"github.com/docker/libnetwork/resolvconf/dns"
2121
"github.com/pkg/errors"
2222
"github.com/spf13/cobra"
2323
"github.com/spf13/pflag"
@@ -77,13 +77,25 @@ func warnOnOomKillDisable(hostConfig container.HostConfig, stderr io.Writer) {
7777
// they are trying to set a DNS to a localhost address
7878
func warnOnLocalhostDNS(hostConfig container.HostConfig, stderr io.Writer) {
7979
for _, dnsIP := range hostConfig.DNS {
80-
if dns.IsLocalhost(dnsIP) {
80+
if isLocalhost(dnsIP) {
8181
fmt.Fprintf(stderr, "WARNING: Localhost DNS setting (--dns=%s) may fail in containers.\n", dnsIP)
8282
return
8383
}
8484
}
8585
}
8686

87+
// IPLocalhost is a regex pattern for IPv4 or IPv6 loopback range.
88+
const ipLocalhost = `((127\.([0-9]{1,3}\.){2}[0-9]{1,3})|(::1)$)`
89+
90+
var localhostIPRegexp = regexp.MustCompile(ipLocalhost)
91+
92+
// IsLocalhost returns true if ip matches the localhost IP regular expression.
93+
// Used for determining if nameserver settings are being passed which are
94+
// localhost addresses
95+
func isLocalhost(ip string) bool {
96+
return localhostIPRegexp.MatchString(ip)
97+
}
98+
8799
func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions, copts *containerOptions) error {
88100
containerConfig, err := parse(flags, copts)
89101
// just in case the parse does not exit

cli/command/container/update.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"github.com/docker/cli/cli/command"
99
"github.com/docker/cli/opts"
1010
containertypes "github.com/docker/docker/api/types/container"
11-
runconfigopts "github.com/docker/docker/runconfig/opts"
1211
"github.com/pkg/errors"
1312
"github.com/spf13/cobra"
1413
"golang.org/x/net/context"
@@ -82,7 +81,7 @@ func runUpdate(dockerCli *command.DockerCli, options *updateOptions) error {
8281

8382
var restartPolicy containertypes.RestartPolicy
8483
if options.restartPolicy != "" {
85-
restartPolicy, err = runconfigopts.ParseRestartPolicy(options.restartPolicy)
84+
restartPolicy, err = opts.ParseRestartPolicy(options.restartPolicy)
8685
if err != nil {
8786
return err
8887
}

cli/command/image/build.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"github.com/docker/docker/pkg/progress"
2626
"github.com/docker/docker/pkg/streamformatter"
2727
"github.com/docker/docker/pkg/urlutil"
28-
runconfigopts "github.com/docker/docker/runconfig/opts"
2928
units "github.com/docker/go-units"
3029
"github.com/pkg/errors"
3130
"github.com/spf13/cobra"
@@ -291,9 +290,9 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
291290
Dockerfile: relDockerfile,
292291
ShmSize: options.shmSize.Value(),
293292
Ulimits: options.ulimits.GetList(),
294-
BuildArgs: runconfigopts.ConvertKVStringsToMapWithNil(options.buildArgs.GetAll()),
293+
BuildArgs: opts.ConvertKVStringsToMapWithNil(options.buildArgs.GetAll()),
295294
AuthConfigs: authConfigs,
296-
Labels: runconfigopts.ConvertKVStringsToMap(options.labels.GetAll()),
295+
Labels: opts.ConvertKVStringsToMap(options.labels.GetAll()),
297296
CacheFrom: options.cacheFrom,
298297
SecurityOpt: options.securityOpt,
299298
NetworkMode: options.networkMode,

cli/command/image/build/context.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
package build
22

33
import (
4+
"archive/tar"
45
"bufio"
6+
"bytes"
57
"fmt"
68
"io"
79
"io/ioutil"
10+
"net/http"
811
"os"
912
"os/exec"
1013
"path/filepath"
1114
"runtime"
1215
"strings"
13-
14-
"archive/tar"
15-
"bytes"
1616
"time"
1717

18+
"github.com/docker/docker/builder/remotecontext/git"
1819
"github.com/docker/docker/pkg/archive"
1920
"github.com/docker/docker/pkg/fileutils"
20-
"github.com/docker/docker/pkg/gitutils"
21-
"github.com/docker/docker/pkg/httputils"
2221
"github.com/docker/docker/pkg/ioutils"
2322
"github.com/docker/docker/pkg/progress"
2423
"github.com/docker/docker/pkg/streamformatter"
@@ -143,7 +142,7 @@ func GetContextFromGitURL(gitURL, dockerfileName string) (string, string, error)
143142
if _, err := exec.LookPath("git"); err != nil {
144143
return "", "", errors.Wrapf(err, "unable to find 'git'")
145144
}
146-
absContextDir, err := gitutils.Clone(gitURL)
145+
absContextDir, err := git.Clone(gitURL)
147146
if err != nil {
148147
return "", "", errors.Wrapf(err, "unable to 'git clone' to temporary context directory")
149148
}
@@ -161,7 +160,7 @@ func GetContextFromGitURL(gitURL, dockerfileName string) (string, string, error)
161160
// Returns the tar archive used for the context and a path of the
162161
// dockerfile inside the tar.
163162
func GetContextFromURL(out io.Writer, remoteURL, dockerfileName string) (io.ReadCloser, string, error) {
164-
response, err := httputils.Download(remoteURL)
163+
response, err := getWithStatusError(remoteURL)
165164
if err != nil {
166165
return nil, "", errors.Errorf("unable to download remote context %s: %v", remoteURL, err)
167166
}
@@ -173,6 +172,24 @@ func GetContextFromURL(out io.Writer, remoteURL, dockerfileName string) (io.Read
173172
return GetContextFromReader(ioutils.NewReadCloserWrapper(progReader, func() error { return response.Body.Close() }), dockerfileName)
174173
}
175174

175+
// getWithStatusError does an http.Get() and returns an error if the
176+
// status code is 4xx or 5xx.
177+
func getWithStatusError(url string) (resp *http.Response, err error) {
178+
if resp, err = http.Get(url); err != nil {
179+
return nil, err
180+
}
181+
if resp.StatusCode < 400 {
182+
return resp, nil
183+
}
184+
msg := fmt.Sprintf("failed to GET %s with status %s", url, resp.Status)
185+
body, err := ioutil.ReadAll(resp.Body)
186+
resp.Body.Close()
187+
if err != nil {
188+
return nil, errors.Wrapf(err, msg+": error reading body")
189+
}
190+
return nil, errors.Errorf(msg+": %s", bytes.TrimSpace(body))
191+
}
192+
176193
// GetContextFromLocalDir uses the given local directory as context for a
177194
// `docker build`. Returns the absolute path to the local context directory,
178195
// the relative path of the dockerfile in that context directory, and a non-nil

cli/command/network/create.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/docker/cli/opts"
1111
"github.com/docker/docker/api/types"
1212
"github.com/docker/docker/api/types/network"
13-
runconfigopts "github.com/docker/docker/runconfig/opts"
1413
"github.com/pkg/errors"
1514
"github.com/spf13/cobra"
1615
"golang.org/x/net/context"
@@ -107,7 +106,7 @@ func runCreate(dockerCli *command.DockerCli, options createOptions) error {
107106
Ingress: options.ingress,
108107
Scope: options.scope,
109108
ConfigOnly: options.configOnly,
110-
Labels: runconfigopts.ConvertKVStringsToMap(options.labels.GetAll()),
109+
Labels: opts.ConvertKVStringsToMap(options.labels.GetAll()),
111110
}
112111

113112
if from := options.configFrom; from != "" {

cli/command/node/update.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import (
77
"github.com/docker/cli/cli/command"
88
"github.com/docker/cli/opts"
99
"github.com/docker/docker/api/types/swarm"
10-
runconfigopts "github.com/docker/docker/runconfig/opts"
1110
"github.com/pkg/errors"
1211
"github.com/spf13/cobra"
1312
"github.com/spf13/pflag"
@@ -95,7 +94,7 @@ func mergeNodeUpdate(flags *pflag.FlagSet) func(*swarm.Node) error {
9594
}
9695
if flags.Changed(flagLabelAdd) {
9796
labels := flags.Lookup(flagLabelAdd).Value.(*opts.ListOpts).GetAll()
98-
for k, v := range runconfigopts.ConvertKVStringsToMap(labels) {
97+
for k, v := range opts.ConvertKVStringsToMap(labels) {
9998
spec.Annotations.Labels[k] = v
10099
}
101100
}

cli/command/secret/create.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"github.com/docker/cli/opts"
1111
"github.com/docker/docker/api/types/swarm"
1212
"github.com/docker/docker/pkg/system"
13-
runconfigopts "github.com/docker/docker/runconfig/opts"
1413
"github.com/pkg/errors"
1514
"github.com/spf13/cobra"
1615
"golang.org/x/net/context"
@@ -65,7 +64,7 @@ func runSecretCreate(dockerCli command.Cli, options createOptions) error {
6564
spec := swarm.SecretSpec{
6665
Annotations: swarm.Annotations{
6766
Name: options.name,
68-
Labels: runconfigopts.ConvertKVStringsToMap(options.labels.GetAll()),
67+
Labels: opts.ConvertKVStringsToMap(options.labels.GetAll()),
6968
},
7069
Data: secretData,
7170
}

0 commit comments

Comments
 (0)