Add support for volume Subpath option

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2024-03-22 13:58:05 +01:00 committed by Nicolas De loof
parent 3b541b071c
commit 3950460703
2 changed files with 18 additions and 5 deletions

View File

@ -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 ?
}

View File

@ -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) {