Skip to content

Commit

Permalink
Merge pull request #2691 from olljanat/34795-npipe-mount-type
Browse files Browse the repository at this point in the history
Support for Windows named pipes mounts
  • Loading branch information
dperny committed Sep 12, 2018
2 parents e24c2a4 + 85277de commit a5a4101
Show file tree
Hide file tree
Showing 10 changed files with 402 additions and 325 deletions.
2 changes: 2 additions & 0 deletions agent/exec/dockerapi/container.go
Expand Up @@ -301,6 +301,8 @@ func convertMount(m api.Mount) enginemount.Mount {
mount.Type = enginemount.TypeBind
case api.MountTypeVolume:
mount.Type = enginemount.TypeVolume
case api.MountTypeNamedPipe:
mount.Type = enginemount.TypeNamedPipe
}

if m.BindOptions != nil {
Expand Down
4 changes: 4 additions & 0 deletions agent/exec/dockerapi/container_test.go
Expand Up @@ -29,6 +29,10 @@ func TestVolumesAndBinds(t *testing.T) {
enginemount.Mount{Type: enginemount.TypeVolume, Source: "banana", Target: "/kerfluffle", VolumeOptions: &enginemount.VolumeOptions{NoCopy: true}}},
{"Volume with no source", api.Mount{Type: api.MountTypeVolume, Target: "/kerfluffle"},
enginemount.Mount{Type: enginemount.TypeVolume, Target: "/kerfluffle"}},
{"Named pipe using Windows format", api.Mount{Type: api.MountTypeNamedPipe, Source: `\\.\pipe\foo`, Target: `\\.\pipe\foo`},
enginemount.Mount{Type: enginemount.TypeNamedPipe, Source: `\\.\pipe\foo`, Target: `\\.\pipe\foo`}},
{"Named pipe using Unix format", api.Mount{Type: api.MountTypeNamedPipe, Source: "//./pipe/foo", Target: "//./pipe/foo"},
enginemount.Mount{Type: enginemount.TypeNamedPipe, Source: "//./pipe/foo", Target: "//./pipe/foo"}},
}

for _, c := range cases {
Expand Down
7 changes: 7 additions & 0 deletions api/api.pb.txt
Expand Up @@ -2520,6 +2520,13 @@ file {
66001: "MountTypeTmpfs"
}
}
value {
name: "NPIPE"
number: 3
options {
66001: "MountTypeNamedPipe"
}
}
options {
62001: 0
62023: "MountType"
Expand Down
652 changes: 328 additions & 324 deletions api/types.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions api/types.proto
Expand Up @@ -202,6 +202,7 @@ message Mount {
BIND = 0 [(gogoproto.enumvalue_customname) = "MountTypeBind"]; // Bind mount host dir
VOLUME = 1 [(gogoproto.enumvalue_customname) = "MountTypeVolume"]; // Remote storage volumes
TMPFS = 2 [(gogoproto.enumvalue_customname) = "MountTypeTmpfs"]; // Mount a tmpfs
NPIPE = 3 [(gogoproto.enumvalue_customname) = "MountTypeNamedPipe"]; // Windows named pipes
}

// Type defines the nature of the mount.
Expand Down
5 changes: 5 additions & 0 deletions cmd/swarmctl/service/flagparser/flags.go
Expand Up @@ -55,6 +55,7 @@ func AddServiceFlags(flags *pflag.FlagSet) {
flags.StringSlice("bind", nil, "define a bind mount")
flags.StringSlice("volume", nil, "define a volume mount")
flags.StringSlice("tmpfs", nil, "define a tmpfs mount")
flags.StringSlice("npipe", nil, "define a npipe mount")

flags.String("log-driver", "", "specify a log driver")
flags.StringSlice("log-opt", nil, "log driver options, as key value pairs")
Expand Down Expand Up @@ -143,6 +144,10 @@ func Merge(cmd *cobra.Command, spec *api.ServiceSpec, c api.ControlClient) error
return err
}

if err := parseNpipe(flags, spec); err != nil {
return err
}

driver, err := common.ParseLogDriverFlags(flags)
if err != nil {
return err
Expand Down
37 changes: 37 additions & 0 deletions cmd/swarmctl/service/flagparser/npipe.go
@@ -0,0 +1,37 @@
package flagparser

import (
"fmt"
"strings"

"github.com/docker/swarmkit/api"
"github.com/spf13/pflag"
)

// parseNpipe only supports a very simple version of anonymous npipes for
// testing the most basic of data flows. Replace with a --mount flag, similar
// to what we have in docker service.
func parseNpipe(flags *pflag.FlagSet, spec *api.ServiceSpec) error {
if flags.Changed("npipe") {
npipes, err := flags.GetStringSlice("npipe")
if err != nil {
return err
}

container := spec.Task.GetContainer()

for _, npipe := range npipes {
parts := strings.SplitN(npipe, ":", 2)
if len(parts) != 2 {
return fmt.Errorf("npipe format %q not supported", npipe)
}
container.Mounts = append(container.Mounts, api.Mount{
Type: api.MountTypeNamedPipe,
Source: parts[0],
Target: parts[1],
})
}
}

return nil
}
@@ -1,7 +1,12 @@
// +build !windows

package defaults

// ControlAPISocket is the default path where clients can contact the swarmd control API.
var ControlAPISocket = "/var/run/swarmd.sock"

// EngineAddr is Docker default socket file on Linux
var EngineAddr = "unix:///var/run/docker.sock"

// StateDir is the default path to the swarmd state directory
var StateDir = "/var/lib/swarmd"
12 changes: 12 additions & 0 deletions cmd/swarmd/defaults/defaults_windows.go
@@ -0,0 +1,12 @@
// +build windows

package defaults

// ControlAPISocket is the default path where clients can contact the swarmd control API.
var ControlAPISocket = "//./pipe/swarmd"

// EngineAddr is Docker default named pipe on Windows
var EngineAddr = "npipe:////./pipe/docker_engine"

// StateDir is the default path to the swarmd state directory
var StateDir = `C:\ProgramData\swarmd`
2 changes: 1 addition & 1 deletion cmd/swarmd/main.go
Expand Up @@ -256,7 +256,7 @@ func init() {
mainCmd.Flags().StringP("log-level", "l", "info", "Log level (options \"debug\", \"info\", \"warn\", \"error\", \"fatal\", \"panic\")")
mainCmd.Flags().StringP("state-dir", "d", defaults.StateDir, "State directory")
mainCmd.Flags().StringP("join-token", "", "", "Specifies the secret token required to join the cluster")
mainCmd.Flags().String("engine-addr", "unix:///var/run/docker.sock", "Address of engine instance of agent.")
mainCmd.Flags().String("engine-addr", defaults.EngineAddr, "Address of engine instance of agent.")
mainCmd.Flags().String("hostname", "", "Override reported agent hostname")
mainCmd.Flags().String("advertise-remote-api", "", "Advertise address for remote API")
mainCmd.Flags().String("listen-remote-api", "0.0.0.0:4242", "Listen address for remote API")
Expand Down

0 comments on commit a5a4101

Please sign in to comment.