From 83d9b9e4d9bcc8a09ef55b7f6adbc7947d703bde Mon Sep 17 00:00:00 2001 From: Olli Janatuinen Date: Fri, 6 Jul 2018 00:18:49 +0300 Subject: [PATCH 1/2] Allow mount type npipe on Windows Signed-off-by: Olli Janatuinen --- daemon/cluster/executor/container/container.go | 2 ++ daemon/cluster/executor/container/validate.go | 7 ++++++- .../executor/container/validate_windows_test.go | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/daemon/cluster/executor/container/container.go b/daemon/cluster/executor/container/container.go index 77d21d2c1f..72f2e29cf3 100644 --- a/daemon/cluster/executor/container/container.go +++ b/daemon/cluster/executor/container/container.go @@ -285,6 +285,8 @@ func convertMount(m api.Mount) enginemount.Mount { mount.Type = enginemount.TypeVolume case api.MountTypeTmpfs: mount.Type = enginemount.TypeTmpfs + case api.MountTypeNamedPipe: + mount.Type = enginemount.TypeNamedPipe } if m.BindOptions != nil { diff --git a/daemon/cluster/executor/container/validate.go b/daemon/cluster/executor/container/validate.go index cbe1f53c38..b90eb98988 100644 --- a/daemon/cluster/executor/container/validate.go +++ b/daemon/cluster/executor/container/validate.go @@ -11,7 +11,8 @@ import ( func validateMounts(mounts []api.Mount) error { for _, mount := range mounts { // Target must always be absolute - if !filepath.IsAbs(mount.Target) { + // except if target is Windows named pipe + if !filepath.IsAbs(mount.Target) && mount.Type != api.MountTypeNamedPipe { return fmt.Errorf("invalid mount target, must be an absolute path: %s", mount.Target) } @@ -32,6 +33,10 @@ func validateMounts(mounts []api.Mount) error { if mount.Source != "" { return errors.New("invalid tmpfs source, source must be empty") } + case api.MountTypeNamedPipe: + if mount.Source == "" { + return errors.New("invalid npipe source, source must not be empty") + } default: return fmt.Errorf("invalid mount type: %s", mount.Type) } diff --git a/daemon/cluster/executor/container/validate_windows_test.go b/daemon/cluster/executor/container/validate_windows_test.go index 6ee4c96431..e0d5bc2e60 100644 --- a/daemon/cluster/executor/container/validate_windows_test.go +++ b/daemon/cluster/executor/container/validate_windows_test.go @@ -1,8 +1,24 @@ // +build windows package container // import "github.com/docker/docker/daemon/cluster/executor/container" +import ( + "strings" + "testing" + + "github.com/docker/swarmkit/api" +) const ( testAbsPath = `c:\foo` testAbsNonExistent = `c:\some-non-existing-host-path\` ) + +func TestControllerValidateMountNamedPipe(t *testing.T) { + if _, err := newTestControllerWithMount(api.Mount{ + Type: api.MountTypeNamedPipe, + Source: "", + Target: `\\.\pipe\foo`, + }); err == nil || !strings.Contains(err.Error(), "invalid npipe source, source must not be empty") { + t.Fatalf("expected error, got: %v", err) + } +} From 1144159a9f2b03a840a84d6ef28376f7c850f2dd Mon Sep 17 00:00:00 2001 From: Olli Janatuinen Date: Sun, 16 Sep 2018 19:49:23 +0300 Subject: [PATCH 2/2] Updated swagger config Signed-off-by: Olli Janatuinen --- api/swagger.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/api/swagger.yaml b/api/swagger.yaml index fd4f2f59ef..db3444d676 100644 --- a/api/swagger.yaml +++ b/api/swagger.yaml @@ -238,11 +238,13 @@ definitions: - `bind` Mounts a file or directory from the host into the container. Must exist prior to creating the container. - `volume` Creates a volume with the given name and options (or uses a pre-existing volume with the same name and options). These are **not** removed when the container is removed. - `tmpfs` Create a tmpfs with the given options. The mount source cannot be specified for tmpfs. + - `npipe` Mounts a named pipe from the host into the container. Must exist prior to creating the container. type: "string" enum: - "bind" - "volume" - "tmpfs" + - "npipe" ReadOnly: description: "Whether the mount should be read-only." type: "boolean"