From 3950460703bc0054a9bbcf2b29e64308a25cc983 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Fri, 22 Mar 2024 13:58:05 +0100 Subject: [PATCH] Add support for volume Subpath option Signed-off-by: Nicolas De Loof --- pkg/compose/create.go | 3 ++- pkg/compose/create_test.go | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/pkg/compose/create.go b/pkg/compose/create.go index ad66314f6..d6cf18908 100644 --- a/pkg/compose/create.go +++ b/pkg/compose/create.go @@ -1136,7 +1136,8 @@ func buildVolumeOptions(vol *types.ServiceVolumeVolume) *mount.VolumeOptions { return nil } return &mount.VolumeOptions{ - NoCopy: vol.NoCopy, + NoCopy: vol.NoCopy, + Subpath: vol.Subpath, // Labels: , // FIXME missing from model ? // DriverConfig: , // FIXME missing from model ? } diff --git a/pkg/compose/create_test.go b/pkg/compose/create_test.go index 7991d09e8..81ce8e124 100644 --- a/pkg/compose/create_test.go +++ b/pkg/compose/create_test.go @@ -113,6 +113,14 @@ func TestBuildContainerMountOptions(t *testing.T) { Type: composetypes.VolumeTypeVolume, Target: "/var/myvolume2", }, + { + Type: composetypes.VolumeTypeVolume, + Source: "myVolume3", + Target: "/var/myvolume3", + Volume: &composetypes.ServiceVolumeVolume{ + Subpath: "etc", + }, + }, { Type: composetypes.VolumeTypeNamedPipe, Source: "\\\\.\\pipe\\docker_engine_windows", @@ -149,20 +157,24 @@ func TestBuildContainerMountOptions(t *testing.T) { return mounts[i].Target < mounts[j].Target }) assert.NilError(t, err) - assert.Assert(t, len(mounts) == 3) + assert.Assert(t, len(mounts) == 4) assert.Equal(t, mounts[0].Target, "/var/myvolume1") assert.Equal(t, mounts[1].Target, "/var/myvolume2") - assert.Equal(t, mounts[2].Target, "\\\\.\\pipe\\docker_engine") + assert.Equal(t, mounts[2].Target, "/var/myvolume3") + assert.Equal(t, mounts[2].VolumeOptions.Subpath, "etc") + assert.Equal(t, mounts[3].Target, "\\\\.\\pipe\\docker_engine") mounts, err = buildContainerMountOptions(project, project.Services["myService"], moby.ImageInspect{}, inherit) sort.Slice(mounts, func(i, j int) bool { return mounts[i].Target < mounts[j].Target }) assert.NilError(t, err) - assert.Assert(t, len(mounts) == 3) + assert.Assert(t, len(mounts) == 4) assert.Equal(t, mounts[0].Target, "/var/myvolume1") assert.Equal(t, mounts[1].Target, "/var/myvolume2") - assert.Equal(t, mounts[2].Target, "\\\\.\\pipe\\docker_engine") + assert.Equal(t, mounts[2].Target, "/var/myvolume3") + assert.Equal(t, mounts[2].VolumeOptions.Subpath, "etc") + assert.Equal(t, mounts[3].Target, "\\\\.\\pipe\\docker_engine") } func TestDefaultNetworkSettings(t *testing.T) {