introduce `mount` to force use of the Mount vs Bind API

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
Nicolas De Loof 2025-07-08 15:29:13 +02:00
parent 9e17a091be
commit eb07f3f778
No known key found for this signature in database
GPG Key ID: 9858809D6F8F6E7E
3 changed files with 20 additions and 14 deletions

2
go.mod
View File

@ -212,3 +212,5 @@ exclude (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2
)
replace github.com/compose-spec/compose-go/v2 => github.com/ndeloof/compose-go/v2 v2.0.1-0.20250708094812-f253188b15ad

4
go.sum
View File

@ -80,8 +80,6 @@ github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004 h1:lkAMpLVBDaj17e
github.com/cloudflare/cfssl v0.0.0-20180223231731-4e2dcbde5004/go.mod h1:yMWuSON2oQp+43nFtAV/uvKQIFpSPerB57DCt9t8sSA=
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb h1:EDmT6Q9Zs+SbUoc7Ik9EfrFqcylYqgPZ9ANSbTAntnE=
github.com/codahale/rfc6979 v0.0.0-20141003034818-6a90f24967eb/go.mod h1:ZjrT6AXHbDs86ZSdt/osfBi5qfexBrKUdONk989Wnk4=
github.com/compose-spec/compose-go/v2 v2.7.1 h1:EUIbuaD0R/J1KA+FbJMNbcS9+jt/CVudbp5iHqUllSs=
github.com/compose-spec/compose-go/v2 v2.7.1/go.mod h1:TmjkIB9W73fwVxkYY+u2uhMbMUakjiif79DlYgXsyvU=
github.com/containerd/cgroups/v3 v3.0.5 h1:44na7Ud+VwyE7LIoJ8JTNQOa549a8543BmzaJHo6Bzo=
github.com/containerd/cgroups/v3 v3.0.5/go.mod h1:SA5DLYnXO8pTGYiAHXz94qvLQTKfVM5GEVisn4jpins=
github.com/containerd/console v1.0.5 h1:R0ymNeydRqH2DmakFNdmjR2k0t7UPuiOV/N/27/qqsc=
@ -361,6 +359,8 @@ github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8m
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f h1:y5//uYreIhSUg3J1GEMiLbxo1LJaP8RfCpH6pymGZus=
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f/go.mod h1:ZdcZmHo+o7JKHSa8/e818NopupXU1YMK5fe1lsApnBw=
github.com/ndeloof/compose-go/v2 v2.0.1-0.20250708094812-f253188b15ad h1:C/1Fowfdus9LTaDte3HASN2YRIFee6aN0vOFlrkU/oE=
github.com/ndeloof/compose-go/v2 v2.0.1-0.20250708094812-f253188b15ad/go.mod h1:Zow/3eYNOnl2T4qLGZEizf8d/ht1qfy09G7WGOSzGOY=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.0 h1:Iw5WCbBcaAAd0fpRb1c9r5YCylv4XDoCSigm1zLevwU=

View File

@ -826,7 +826,7 @@ func (s *composeService) buildContainerVolumes(
if v.Type != types.VolumeTypeBind {
v.Source = m.Source
}
if !bindRequiresMountAPI(v.Bind) {
if !bindRequiresMountAPI(v) {
source := m.Source
if vol := findVolumeByName(p.Volumes, m.Source); vol != nil {
source = m.Source
@ -840,7 +840,7 @@ func (s *composeService) buildContainerVolumes(
vol := findVolumeByName(p.Volumes, m.Source)
if v != nil && vol != nil {
// Prefer the bind API if no advanced option is used, to preserve backward compatibility
if !volumeRequiresMountAPI(v.Volume) {
if !volumeRequiresMountAPI(v) {
binds = append(binds, toBindString(vol.Name, v))
continue
}
@ -897,15 +897,17 @@ func findVolumeByTarget(volumes []types.ServiceVolumeConfig, target string) *typ
// bindRequiresMountAPI check if Bind declaration can be implemented by the plain old Bind API or uses any of the advanced
// options which require use of Mount API
func bindRequiresMountAPI(bind *types.ServiceVolumeBind) bool {
func bindRequiresMountAPI(v *types.ServiceVolumeConfig) bool {
switch {
case bind == nil:
case v.Mount != nil:
return *v.Mount
case v.Bind == nil:
return false
case !bind.CreateHostPath:
case !v.Bind.CreateHostPath:
return true
case bind.Propagation != "":
case v.Bind.Propagation != "":
return true
case bind.Recursive != "":
case v.Bind.Recursive != "":
return true
default:
return false
@ -914,15 +916,17 @@ func bindRequiresMountAPI(bind *types.ServiceVolumeBind) bool {
// volumeRequiresMountAPI check if Volume declaration can be implemented by the plain old Bind API or uses any of the advanced
// options which require use of Mount API
func volumeRequiresMountAPI(vol *types.ServiceVolumeVolume) bool {
func volumeRequiresMountAPI(v *types.ServiceVolumeConfig) bool {
switch {
case vol == nil:
case v.Mount != nil:
return *v.Mount
case v.Volume == nil:
return false
case len(vol.Labels) > 0:
case len(v.Volume.Labels) > 0:
return true
case vol.Subpath != "":
case v.Volume.Subpath != "":
return true
case vol.NoCopy:
case v.Volume.NoCopy:
return true
default:
return false