Skip to content

Commit

Permalink
[DNM/dirtyvendor] support --mount type=bind,bind-norecursive,...
Browse files Browse the repository at this point in the history
Signed-off-by: Akihiro Suda <suda.akihiro@lab.ntt.co.jp>
  • Loading branch information
AkihiroSuda committed Oct 10, 2018
1 parent ab50c2f commit 4eb3d9a
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 4 deletions.
4 changes: 3 additions & 1 deletion cli/command/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ func (cli *DockerCli) initializeFromClient() {
ping, err := cli.client.Ping(context.Background())
if err != nil {
// Default to true if we fail to connect to daemon
cli.serverInfo = ServerInfo{HasExperimental: true}
cli.serverInfo = ServerInfo{HasExperimental: true, APIVersion: ping.APIVersion}

if ping.APIVersion != "" {
cli.client.NegotiateAPIVersionPing(ping)
Expand All @@ -210,6 +210,7 @@ func (cli *DockerCli) initializeFromClient() {
HasExperimental: ping.Experimental,
OSType: ping.OSType,
BuildkitVersion: ping.BuilderVersion,
APIVersion: ping.APIVersion,
}
cli.client.NegotiateAPIVersionPing(ping)
}
Expand Down Expand Up @@ -244,6 +245,7 @@ type ServerInfo struct {
HasExperimental bool
OSType string
BuildkitVersion types.BuilderVersion
APIVersion string
}

// ClientInfo stores details about the supported features of the client
Expand Down
4 changes: 2 additions & 2 deletions cli/command/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func TestInitializeFromClient(t *testing.T) {
pingFunc: func() (types.Ping, error) {
return types.Ping{Experimental: true, OSType: "linux", APIVersion: "v1.30"}, nil
},
expectedServer: ServerInfo{HasExperimental: true, OSType: "linux"},
expectedServer: ServerInfo{HasExperimental: true, OSType: "linux", APIVersion: "v1.30"},
negotiated: true,
},
{
Expand All @@ -102,7 +102,7 @@ func TestInitializeFromClient(t *testing.T) {
pingFunc: func() (types.Ping, error) {
return types.Ping{APIVersion: "v1.33"}, errors.New("failed")
},
expectedServer: ServerInfo{HasExperimental: true},
expectedServer: ServerInfo{HasExperimental: true, APIVersion: "v1.33"},
negotiated: true,
},
}
Expand Down
4 changes: 4 additions & 0 deletions cli/command/container/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ func runCreate(dockerCli command.Cli, flags *pflag.FlagSet, opts *createOptions,
reportError(dockerCli.Err(), "create", err.Error(), true)
return cli.StatusError{StatusCode: 125}
}
if err = validateAPIVersion(containerConfig, dockerCli.ServerInfo().APIVersion); err != nil {
reportError(dockerCli.Err(), "create", err.Error(), true)
return cli.StatusError{StatusCode: 125}
}
response, err := createContainer(context.Background(), dockerCli, containerConfig, opts)
if err != nil {
return err
Expand Down
10 changes: 10 additions & 0 deletions cli/command/container/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/docker/docker/api/types/container"
networktypes "github.com/docker/docker/api/types/network"
"github.com/docker/docker/api/types/strslice"
"github.com/docker/docker/api/types/versions"
"github.com/docker/docker/pkg/signal"
"github.com/docker/go-connections/nat"
"github.com/pkg/errors"
Expand Down Expand Up @@ -866,3 +867,12 @@ func validateAttach(val string) (string, error) {
}
return val, errors.Errorf("valid streams are STDIN, STDOUT and STDERR")
}

func validateAPIVersion(c *containerConfig, serverAPIVersion string) error {
for _, m := range c.HostConfig.Mounts {
if m.BindOptions != nil && m.BindOptions.NoRecursive && versions.LessThan(serverAPIVersion, "1.40") {
return errors.Errorf("bind-norecursive requires API v1.40 or later")
}
}
return nil
}
4 changes: 4 additions & 0 deletions cli/command/container/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,10 @@ func runRun(dockerCli command.Cli, flags *pflag.FlagSet, ropts *runOptions, copt
reportError(dockerCli.Err(), "run", err.Error(), true)
return cli.StatusError{StatusCode: 125}
}
if err = validateAPIVersion(containerConfig, dockerCli.ServerInfo().APIVersion); err != nil {
reportError(dockerCli.Err(), "run", err.Error(), true)
return cli.StatusError{StatusCode: 125}
}
return runContainer(dockerCli, ropts, copts, containerConfig)
}

Expand Down
3 changes: 3 additions & 0 deletions opts/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ func (m *MountOpt) Set(value string) error {
case "volume-nocopy":
volumeOptions().NoCopy = true
continue
case "bind-norecursive":
bindOptions().NoRecursive = true
continue
}
}

Expand Down
2 changes: 1 addition & 1 deletion vendor/github.com/docker/docker/api/common.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/docker/docker/api/types/mount/mount.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4eb3d9a

Please sign in to comment.