Skip to content

Commit

Permalink
Add support for volume Subpath option
Browse files Browse the repository at this point in the history
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
  • Loading branch information
ndeloof committed Mar 22, 2024
1 parent 3b541b0 commit 3950460
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion pkg/compose/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 ?
}
Expand Down
20 changes: 16 additions & 4 deletions pkg/compose/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 3950460

Please sign in to comment.