10BC0 Allow npipe volume type on stack file · docker/cli@8178403 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8178403

Browse files
committed
Allow npipe volume type on stack file
Signed-off-by: Olli Janatuinen <olli.janatuinen@gmail.com>
1 parent 2b221d8 commit 8178403

File tree

2 files changed

+40
-2
lines changed

2 files changed

+40
-2
lines changed

cli/compose/convert/volume.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,26 @@ func handleTmpfsToMount(volume composetypes.ServiceVolumeConfig) (mount.Mount, e
122122
return result, nil
123123
}
124124

125+
func handleNpipeToMount(volume composetypes.ServiceVolumeConfig) (mount.Mount, error) {
126+
result := createMountFromVolume(volume)
127+
128+
if volume.Source == "" {
129+
return mount.Mount{}, errors.New("invalid npipe source, source cannot be empty")
130+
}
131+
if volume.Volume != nil {
132+
return mount.Mount{}, errors.New("volume options are incompatible with type npipe")
133+
}
134+
if volume.Tmpfs != nil {
135+
return mount.Mount{}, errors.New("tmpfs options are incompatible with type npipe")
136+
}
137+
if volume.Bind != nil {
138+
result.BindOptions = &mount.BindOptions{
139+
Propagation: mount.Propagation(volume.Bind.Propagation),
140+
}
141+
}
142+
return result, nil
143+
}
144+
125145
func convertVolumeToMount(
126146
volume composetypes.ServiceVolumeConfig,
127147
stackVolumes volumes,
@@ -135,6 +155,8 @@ func convertVolumeToMount(
135155
return handleBindToMount(volume)
136156
case "tmpfs":
137157
return handleTmpfsToMount(volume)
158+
case "npipe":
159+
return handleNpipeToMount(volume)
138160
}
139-
return mount.Mount{}, errors.New("volume type must be volume, bind, or tmpfs")
161+
return mount.Mount{}, errors.New("volume type must be volume, bind, tmpfs or npipe")
140162
}

cli/compose/convert/volume_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestConvertVolumeToMountUnapprovedType(t *testing.T) {
4141
Target: "/foo/bar",
4242
}
4343
_, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo"))
44-
assert.Error(t, err, "volume type must be volume, bind, or tmpfs")
44+
assert.Error(t, err, "volume type must be volume, bind, tmpfs or npipe")
4545
}
4646

4747
func TestConvertVolumeToMountConflictingOptionsBindInVolume(t *testing.T) {
@@ -343,3 +343,19 @@ func TestConvertTmpfsToMountVolumeWithSource(t *testing.T) {
343343
_, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo"))
344344
assert.Error(t, err, "invalid tmpfs source, source must be empty")
345345
}
346+
347+
func TestConvertVolumeToMountAnonymousNpipe(t *testing.T) {
348+
config := composetypes.ServiceVolumeConfig{
349+
Type: "npipe",
350+
Source: `\\.\pipe\foo`,
351+
Target: `\\.\pipe\foo`,
352+
}
353+
expected := mount.Mount{
354+
Type: mount.TypeNamedPipe,
355+
Source: `\\.\pipe\foo`,
356+
Target: `\\.\pipe\foo`,
357+
}
358+
mount, err := convertVolumeToMount(config, volumes{}, NewNamespace("foo"))
359+
assert.NilError(t, err)
360+
assert.Check(t, is.DeepEqual(expected, mount))
361+
}

0 commit comments

Comments
 (0)
0