From 4fe611958cc7d44a2a9d95ab892340349ed02072 Mon Sep 17 00:00:00 2001 From: "bingshen.wbs" Date: Wed, 15 Feb 2017 17:32:37 +0800 Subject: [PATCH] fix docker stack volume's nocopy parameter Signed-off-by: bingshen.wbs --- cli/compose/convert/volume.go | 3 +++ cli/compose/convert/volume_test.go | 26 ++++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/cli/compose/convert/volume.go b/cli/compose/convert/volume.go index 24442d4dc7b09..53c50958facf7 100644 --- a/cli/compose/convert/volume.go +++ b/cli/compose/convert/volume.go @@ -75,6 +75,9 @@ func convertVolumeToMount(volumeSpec string, stackVolumes volumes, namespace Nam var volumeOptions *mount.VolumeOptions if stackVolume.External.Name != "" { + volumeOptions = &mount.VolumeOptions{ + NoCopy: isNoCopy(mode), + } source = stackVolume.External.Name } else { volumeOptions = &mount.VolumeOptions{ diff --git a/cli/compose/convert/volume_test.go b/cli/compose/convert/volume_test.go index 1132136b22c23..d218e7c2f593e 100644 --- a/cli/compose/convert/volume_test.go +++ b/cli/compose/convert/volume_test.go @@ -105,12 +105,38 @@ func TestConvertVolumeToMountNamedVolumeExternal(t *testing.T) { Type: mount.TypeVolume, Source: "special", Target: "/foo", + VolumeOptions: &mount.VolumeOptions{ + NoCopy: false, + }, } mount, err := convertVolumeToMount("outside:/foo", stackVolumes, namespace) assert.NilError(t, err) assert.DeepEqual(t, mount, expected) } +func TestConvertVolumeToMountNamedVolumeExternalNoCopy(t *testing.T) { + stackVolumes := volumes{ + "outside": composetypes.VolumeConfig{ + External: composetypes.External{ + External: true, + Name: "special", + }, + }, + } + namespace := NewNamespace("foo") + expected := mount.Mount{ + Type: mount.TypeVolume, + Source: "special", + Target: "/foo", + VolumeOptions: &mount.VolumeOptions{ + NoCopy: true, + }, + } + mount, err := convertVolumeToMount("outside:/foo:nocopy", stackVolumes, namespace) + assert.NilError(t, err) + assert.DeepEqual(t, mount, expected) +} + func TestConvertVolumeToMountBind(t *testing.T) { stackVolumes := volumes{} namespace := NewNamespace("foo")