Skip to content

Commit 7faef7a

Browse files
committed
[DNM/dirtyvendor] support --mount type=bind,bind-norecursive,...
Signed-off-by: Akihiro Suda <[email protected]>
1 parent ab50c2f commit 7faef7a

8 files changed

Lines changed: 37 additions & 1 deletion

File tree

cli/command/container/create.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ func runCreate(dockerCli command.Cli, flags *pflag.FlagSet, opts *createOptions,
6565
reportError(dockerCli.Err(), "create", err.Error(), true)
6666
return cli.StatusError{StatusCode: 125}
6767
}
68+
if err = validateAPIVersion(containerConfig, dockerCli.Client().ClientVersion()); err != nil {
69+
reportError(dockerCli.Err(), "create", err.Error(), true)
70+
return cli.StatusError{StatusCode: 125}
71+
}
6872
response, err := createContainer(context.Background(), dockerCli, containerConfig, opts)
6973
if err != nil {
7074
return err

cli/command/container/opts.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/docker/docker/api/types/container"
1717
networktypes "github.com/docker/docker/api/types/network"
1818
"github.com/docker/docker/api/types/strslice"
19+
"github.com/docker/docker/api/types/versions"
1920
"github.com/docker/docker/pkg/signal"
2021
"github.com/docker/go-connections/nat"
2122
"github.com/pkg/errors"
@@ -866,3 +867,12 @@ func validateAttach(val string) (string, error) {
866867
}
867868
return val, errors.Errorf("valid streams are STDIN, STDOUT and STDERR")
868869
}
870+
871+
func validateAPIVersion(c *containerConfig, serverAPIVersion string) error {
872+
for _, m := range c.HostConfig.Mounts {
873+
if m.BindOptions != nil && m.BindOptions.NoRecursive && versions.LessThan(serverAPIVersion, "1.40") {
874+
return errors.Errorf("bind-norecursive requires API v1.40 or later")
875+
}
876+
}
877+
return nil
878+
}

cli/command/container/run.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,10 @@ func runRun(dockerCli command.Cli, flags *pflag.FlagSet, ropts *runOptions, copt
114114
reportError(dockerCli.Err(), "run", err.Error(), true)
115115
return cli.StatusError{StatusCode: 125}
116116
}
117+
if err = validateAPIVersion(containerConfig, dockerCli.Client().ClientVersion()); err != nil {
118+
reportError(dockerCli.Err(), "run", err.Error(), true)
119+
return cli.StatusError{StatusCode: 125}
120+
}
117121
return runContainer(dockerCli, ropts, copts, containerConfig)
118122
}
119123

cli/command/service/create.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ func runCreate(dockerCli command.Cli, flags *pflag.FlagSet, opts *serviceOptions
7979
return err
8080
}
8181

82+
if err = validateAPIVersion(service, dockerCli.Client().ClientVersion()); err != nil {
83+
return err
84+
}
85+
8286
specifiedSecrets := opts.secrets.Value()
8387
if len(specifiedSecrets) > 0 {
8488
// parse and validate secrets

cli/command/service/opts.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"github.com/docker/docker/api/types/container"
1414
"github.com/docker/docker/api/types/swarm"
1515
"github.com/docker/docker/client"
16+
"github.com/docker/docker/api/types/versions"
1617
"github.com/docker/swarmkit/api"
1718
"github.com/docker/swarmkit/api/defaults"
1819
shlex "github.com/flynn-archive/go-shlex"
@@ -909,3 +910,12 @@ const (
909910
flagConfigRemove = "config-rm"
910911
flagIsolation = "isolation"
911912
)
913+
914+
func validateAPIVersion(c swarm.ServiceSpec, serverAPIVersion string) error {
915+
for _, m := range c.TaskTemplate.ContainerSpec.Mounts {
916+
if m.BindOptions != nil && m.BindOptions.NoRecursive && versions.LessThan(serverAPIVersion, "1.40") {
917+
return errors.Errorf("bind-norecursive requires API v1.40 or later")
918+
}
919+
}
920+
return nil
921+
}

opts/mount.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ func (m *MountOpt) Set(value string) error {
7676
case "volume-nocopy":
7777
volumeOptions().NoCopy = true
7878
continue
79+
case "bind-norecursive":
80+
bindOptions().NoRecursive = true
81+
continue
7982
}
8083
}
8184

vendor/github.com/docker/docker/api/common.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/github.com/docker/docker/api/types/mount/mount.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)