Skip to content

Commit

Permalink
Update vendoring of docker/docker
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Demeester <[email protected]>
  • Loading branch information
vdemeester committed Jun 5, 2017
1 parent d95fd2f commit dc7dd9f
Show file tree
Hide file tree
Showing 46 changed files with 568 additions and 1,255 deletions.
6 changes: 3 additions & 3 deletions cli/command/container/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,13 @@ func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, err
}

// collect all the environment variables for the container
envVariables, err := runconfigopts.ReadKVStrings(copts.envFile.GetAll(), copts.env.GetAll())
envVariables, err := opts.ReadKVStrings(copts.envFile.GetAll(), copts.env.GetAll())
if err != nil {
return nil, err
}

// collect all the labels for the container
labels, err := runconfigopts.ReadKVStrings(copts.labelsFile.GetAll(), copts.labels.GetAll())
labels, err := opts.ReadKVStrings(copts.labelsFile.GetAll(), copts.labels.GetAll())
if err != nil {
return nil, err
}
Expand All @@ -440,7 +440,7 @@ func parse(flags *pflag.FlagSet, copts *containerOptions) (*containerConfig, err
return nil, errors.Errorf("--userns: invalid USER mode")
}

restartPolicy, err := runconfigopts.ParseRestartPolicy(copts.restartPolicy)
restartPolicy, err := opts.ParseRestartPolicy(copts.restartPolicy)
if err != nil {
return nil, err
}
Expand Down
16 changes: 14 additions & 2 deletions cli/command/container/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"net/http/httputil"
"os"
"regexp"
"runtime"
"strings"
"syscall"
Expand All @@ -17,7 +18,6 @@ import (
"github.com/docker/docker/pkg/promise"
"github.com/docker/docker/pkg/signal"
"github.com/docker/docker/pkg/term"
"github.com/docker/libnetwork/resolvconf/dns"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
Expand Down Expand Up @@ -77,13 +77,25 @@ func warnOnOomKillDisable(hostConfig container.HostConfig, stderr io.Writer) {
// they are trying to set a DNS to a localhost address
func warnOnLocalhostDNS(hostConfig container.HostConfig, stderr io.Writer) {
for _, dnsIP := range hostConfig.DNS {
if dns.IsLocalhost(dnsIP) {
if isLocalhost(dnsIP) {
fmt.Fprintf(stderr, "WARNING: Localhost DNS setting (--dns=%s) may fail in containers.\n", dnsIP)
return
}
}
}

// IPLocalhost is a regex pattern for IPv4 or IPv6 loopback range.
const ipLocalhost = `((127\.([0-9]{1,3}\.){2}[0-9]{1,3})|(::1)$)`

var localhostIPRegexp = regexp.MustCompile(ipLocalhost)

// IsLocalhost returns true if ip matches the localhost IP regular expression.
// Used for determining if nameserver settings are being passed which are
// localhost addresses
func isLocalhost(ip string) bool {
return localhostIPRegexp.MatchString(ip)
}

func runRun(dockerCli *command.DockerCli, flags *pflag.FlagSet, opts *runOptions, copts *containerOptions) error {
containerConfig, err := parse(flags, copts)
// just in case the parse does not exit
Expand Down
3 changes: 1 addition & 2 deletions cli/command/container/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/cli/opts"
containertypes "github.com/docker/docker/api/types/container"
runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/pkg/errors"
"github.com/spf13/cobra"
"golang.org/x/net/context"
Expand Down Expand Up @@ -82,7 +81,7 @@ func runUpdate(dockerCli *command.DockerCli, options *updateOptions) error {

var restartPolicy containertypes.RestartPolicy
if options.restartPolicy != "" {
restartPolicy, err = runconfigopts.ParseRestartPolicy(options.restartPolicy)
restartPolicy, err = opts.ParseRestartPolicy(options.restartPolicy)
if err != nil {
return err
}
Expand Down
5 changes: 2 additions & 3 deletions cli/command/image/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"github.com/docker/docker/pkg/progress"
"github.com/docker/docker/pkg/streamformatter"
"github.com/docker/docker/pkg/urlutil"
runconfigopts "github.com/docker/docker/runconfig/opts"
units "github.com/docker/go-units"
"github.com/pkg/errors"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -291,9 +290,9 @@ func runBuild(dockerCli *command.DockerCli, options buildOptions) error {
Dockerfile: relDockerfile,
ShmSize: options.shmSize.Value(),
Ulimits: options.ulimits.GetList(),
BuildArgs: runconfigopts.ConvertKVStringsToMapWithNil(options.buildArgs.GetAll()),
BuildArgs: opts.ConvertKVStringsToMapWithNil(options.buildArgs.GetAll()),
AuthConfigs: authConfigs,
Labels: runconfigopts.ConvertKVStringsToMap(options.labels.GetAll()),
Labels: opts.ConvertKVStringsToMap(options.labels.GetAll()),
CacheFrom: options.cacheFrom,
SecurityOpt: options.securityOpt,
NetworkMode: options.networkMode,
Expand Down
31 changes: 24 additions & 7 deletions cli/command/image/build/context.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package build

import (
"archive/tar"
"bufio"
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"

"archive/tar"
"bytes"
"time"

"github.com/docker/docker/builder/remotecontext/git"
"github.com/docker/docker/pkg/archive"
"github.com/docker/docker/pkg/fileutils"
"github.com/docker/docker/pkg/gitutils"
"github.com/docker/docker/pkg/httputils"
"github.com/docker/docker/pkg/ioutils"
"github.com/docker/docker/pkg/progress"
"github.com/docker/docker/pkg/streamformatter"
Expand Down Expand Up @@ -143,7 +142,7 @@ func GetContextFromGitURL(gitURL, dockerfileName string) (string, string, error)
if _, err := exec.LookPath("git"); err != nil {
return "", "", errors.Wrapf(err, "unable to find 'git'")
}
absContextDir, err := gitutils.Clone(gitURL)
absContextDir, err := git.Clone(gitURL)
if err != nil {
return "", "", errors.Wrapf(err, "unable to 'git clone' to temporary context directory")
}
Expand All @@ -161,7 +160,7 @@ func GetContextFromGitURL(gitURL, dockerfileName string) (string, string, error)
// Returns the tar archive used for the context and a path of the
// dockerfile inside the tar.
func GetContextFromURL(out io.Writer, remoteURL, dockerfileName string) (io.ReadCloser, string, error) {
response, err := httputils.Download(remoteURL)
response, err := getWithStatusError(remoteURL)
if err != nil {
return nil, "", errors.Errorf("unable to download remote context %s: %v", remoteURL, err)
}
Expand All @@ -173,6 +172,24 @@ func GetContextFromURL(out io.Writer, remoteURL, dockerfileName string) (io.Read
return GetContextFromReader(ioutils.NewReadCloserWrapper(progReader, func() error { return response.Body.Close() }), dockerfileName)
}

// getWithStatusError does an http.Get() and returns an error if the
// status code is 4xx or 5xx.
func getWithStatusError(url string) (resp *http.Response, err error) {
if resp, err = http.Get(url); err != nil {
return nil, err
}
if resp.StatusCode < 400 {
return resp, nil
}
msg := fmt.Sprintf("failed to GET %s with status %s", url, resp.Status)
body, err := ioutil.ReadAll(resp.Body)
resp.Body.Close()
if err != nil {
return nil, errors.Wrapf(err, msg+": error reading body")
}
return nil, errors.Errorf(msg+": %s", bytes.TrimSpace(body))
}

// GetContextFromLocalDir uses the given local directory as context for a
// `docker build`. Returns the absolute path to the local context directory,
// the relative path of the dockerfile in that context directory, and a non-nil
Expand Down
82 changes: 41 additions & 41 deletions cli/command/service/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -519,36 +519,36 @@ func newServiceOptions() *serviceOptions {
}
}

func (opts *serviceOptions) ToServiceMode() (swarm.ServiceMode, error) {
func (options *serviceOptions) ToServiceMode() (swarm.ServiceMode, error) {
serviceMode := swarm.ServiceMode{}
switch opts.mode {
switch options.mode {
case "global":
if opts.replicas.Value() != nil {
if options.replicas.Value() != nil {
return serviceMode, errors.Errorf("replicas can only be used with replicated mode")
}

serviceMode.Global = &swarm.GlobalService{}
case "replicated":
serviceMode.Replicated = &swarm.ReplicatedService{
Replicas: opts.replicas.Value(),
Replicas: options.replicas.Value(),
}
default:
return serviceMode, errors.Errorf("Unknown mode: %s, only replicated and global supported", opts.mode)
return serviceMode, errors.Errorf("Unknown mode: %s, only replicated and global supported", options.mode)
}
return serviceMode, nil
}

func (opts *serviceOptions) ToStopGracePeriod(flags *pflag.FlagSet) *time.Duration {
func (options *serviceOptions) ToStopGracePeriod(flags *pflag.FlagSet) *time.Duration {
if flags.Changed(flagStopGracePeriod) {
return opts.stopGrace.Value()
return options.stopGrace.Value()
}
return nil
}

func (opts *serviceOptions) ToService(ctx context.Context, apiClient client.NetworkAPIClient, flags *pflag.FlagSet) (swarm.ServiceSpec, error) {
func (options *serviceOptions) ToService(ctx context.Context, apiClient client.NetworkAPIClient, flags *pflag.FlagSet) (swarm.ServiceSpec, error) {
var service swarm.ServiceSpec

envVariables, err := runconfigopts.ReadKVStrings(opts.envFile.GetAll(), opts.env.GetAll())
envVariables, err := opts.ReadKVStrings(options.envFile.GetAll(), options.env.GetAll())
if err != nil {
return service, err
}
Expand All @@ -567,68 +567,68 @@ func (opts *serviceOptions) ToService(ctx context.Context, apiClient client.Netw
currentEnv = append(currentEnv, env)
}

healthConfig, err := opts.healthcheck.toHealthConfig()
healthConfig, err := options.healthcheck.toHealthConfig()
if err != nil {
return service, err
}

serviceMode, err := opts.ToServiceMode()
serviceMode, err := options.ToServiceMode()
if err != nil {
return service, err
}

networks, err := convertNetworks(ctx, apiClient, opts.networks)
networks, err := convertNetworks(ctx, apiClient, options.networks)
if err != nil {
return service, err
}

service = swarm.ServiceSpec{
Annotations: swarm.Annotations{
Name: opts.name,
Labels: runconfigopts.ConvertKVStringsToMap(opts.labels.GetAll()),
Name: options.name,
Labels: runconfigopts.ConvertKVStringsToMap(options.labels.GetAll()),
},
TaskTemplate: swarm.TaskSpec{
ContainerSpec: swarm.ContainerSpec{
Image: opts.image,
Args: opts.args,
Command: opts.entrypoint.Value(),
Image: options.image,
Args: options.args,
Command: options.entrypoint.Value(),
Env: currentEnv,
Hostname: opts.hostname,
Labels: runconfigopts.ConvertKVStringsToMap(opts.containerLabels.GetAll()),
Dir: opts.workdir,
User: opts.user,
Groups: opts.groups.GetAll(),
StopSignal: opts.stopSignal,
TTY: opts.tty,
ReadOnly: opts.readOnly,
Mounts: opts.mounts.Value(),
Hostname: options.hostname,
Labels: runconfigopts.ConvertKVStringsToMap(options.containerLabels.GetAll()),
Dir: options.workdir,
User: options.user,
Groups: options.groups.GetAll(),
StopSignal: options.stopSignal,
TTY: options.tty,
ReadOnly: options.readOnly,
Mounts: options.mounts.Value(),
DNSConfig: &swarm.DNSConfig{
Nameservers: opts.dns.GetAll(),
Search: opts.dnsSearch.GetAll(),
Options: opts.dnsOption.GetAll(),
Nameservers: options.dns.GetAll(),
Search: options.dnsSearch.GetAll(),
Options: options.dnsOption.GetAll(),
},
Hosts: convertExtraHostsToSwarmHosts(opts.hosts.GetAll()),
StopGracePeriod: opts.ToStopGracePeriod(flags),
Hosts: convertExtraHostsToSwarmHosts(options.hosts.GetAll()),
StopGracePeriod: options.ToStopGracePeriod(flags),
Healthcheck: healthConfig,
},
Networks: networks,
Resources: opts.resources.ToResourceRequirements(),
RestartPolicy: opts.restartPolicy.ToRestartPolicy(flags),
Resources: options.resources.ToResourceRequirements(),
RestartPolicy: options.restartPolicy.ToRestartPolicy(flags),
Placement: &swarm.Placement{
Constraints: opts.constraints.GetAll(),
Preferences: opts.placementPrefs.prefs,
Constraints: options.constraints.GetAll(),
Preferences: options.placementPrefs.prefs,
},
LogDriver: opts.logDriver.toLogDriver(),
LogDriver: options.logDriver.toLogDriver(),
},
Mode: serviceMode,
UpdateConfig: opts.update.updateConfig(flags),
RollbackConfig: opts.update.rollbackConfig(flags),
EndpointSpec: opts.endpoint.ToEndpointSpec(),
UpdateConfig: options.update.updateConfig(flags),
RollbackConfig: options.update.rollbackConfig(flags),
EndpointSpec: options.endpoint.ToEndpointSpec(),
}

if opts.credentialSpec.Value() != nil {
if options.credentialSpec.Value() != nil {
service.TaskTemplate.ContainerSpec.Privileges = &swarm.Privileges{
CredentialSpec: opts.credentialSpec.Value(),
CredentialSpec: options.credentialSpec.Value(),
}
}

Expand Down
3 changes: 1 addition & 2 deletions cli/compose/convert/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/docker/docker/api/types/swarm"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/client"
runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -404,7 +403,7 @@ func convertHealthcheck(healthcheck *composetypes.HealthCheckConfig) (*container
func convertRestartPolicy(restart string, source *composetypes.RestartPolicy) (*swarm.RestartPolicy, error) {
// TODO: log if restart is being ignored
if source == nil {
policy, err := runconfigopts.ParseRestartPolicy(restart)
policy, err := opts.ParseRestartPolicy(restart)
if err != nil {
return nil, err
}
Expand Down
5 changes: 2 additions & 3 deletions cli/compose/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/docker/cli/cli/compose/template"
"github.com/docker/cli/cli/compose/types"
"github.com/docker/cli/opts"
runconfigopts "github.com/docker/docker/runconfig/opts"
"github.com/docker/go-connections/nat"
units "github.com/docker/go-units"
shellwords "github.com/mattn/go-shellwords"
Expand Down Expand Up @@ -351,14 +350,14 @@ func resolveEnvironment(serviceConfig *types.ServiceConfig, workingDir string, l

for _, file := range serviceConfig.EnvFile {
filePath := absPath(workingDir, file)
fileVars, err := runconfigopts.ParseEnvFile(filePath)
fileVars, err := opts.ParseEnvFile(filePath)
if err != nil {
return err
}
envVars = append(envVars, fileVars...)
}
updateEnvironment(environment,
runconfigopts.ConvertKVStringsToMapWithNil(envVars), lookupEnv)
opts.ConvertKVStringsToMapWithNil(envVars), lookupEnv)
}

updateEnvironment(environment, serviceConfig.Environment, lookupEnv)
Expand Down
File renamed without changes.
Loading

0 comments on commit dc7dd9f

Please sign in to comment.