diff --git a/go.mod b/go.mod index 34e58e1f5e..4a14e175c2 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/Microsoft/go-winio v0.6.2 github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d github.com/buger/goterm v1.0.4 - github.com/compose-spec/compose-go/v2 v2.3.0 + github.com/compose-spec/compose-go/v2 v2.3.1-0.20241015085011-35c9659361ef github.com/containerd/containerd v1.7.22 github.com/containerd/platforms v0.2.1 github.com/davecgh/go-spew v1.1.1 diff --git a/go.sum b/go.sum index d636e3ae51..f70a546234 100644 --- a/go.sum +++ b/go.sum @@ -85,8 +85,8 @@ github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa h1:jQCWAUqqlij9Pgj2i/P github.com/cncf/xds/go v0.0.0-20231128003011-0fa0005c9caa/go.mod h1:x/1Gn8zydmfq8dk6e9PdstVsDgu9RuyIIJqAaF//0IM= 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.3.0 h1:5eomqgNcs/GqVknPtXF68V3muc67cOdXD35zCXn1aes= -github.com/compose-spec/compose-go/v2 v2.3.0/go.mod h1:lFN0DrMxIncJGYAXTfWuajfwj5haBJqrBkarHcnjJKc= +github.com/compose-spec/compose-go/v2 v2.3.1-0.20241015085011-35c9659361ef h1:E3qLbOpEyqemgAkQQg3uKNFaJJ+cVXGKiy1Xj4zh49k= +github.com/compose-spec/compose-go/v2 v2.3.1-0.20241015085011-35c9659361ef/go.mod h1:lFN0DrMxIncJGYAXTfWuajfwj5haBJqrBkarHcnjJKc= github.com/containerd/cgroups v1.1.0 h1:v8rEWFl6EoqHB+swVNjVoCJE8o3jX7e8nqBGPLaDFBM= github.com/containerd/cgroups v1.1.0/go.mod h1:6ppBcbh/NOOUU+dMKrykgaBnK9lCIBxHqJDGwsa1mIw= github.com/containerd/console v1.0.4 h1:F2g4+oChYvBTsASRTz8NP6iIAi97J3TtSAsLbIFn4ro= diff --git a/pkg/compose/create.go b/pkg/compose/create.go index 8608ac971c..f82b3c105b 100644 --- a/pkg/compose/create.go +++ b/pkg/compose/create.go @@ -848,7 +848,7 @@ MOUNTS: case string(m.Type) != v.Type: v.Source = m.Source fallthrough - case v.Bind != nil && v.Bind.CreateHostPath: + case !requireMountAPI(v.Bind): binds = append(binds, v.String()) continue MOUNTS } @@ -860,6 +860,23 @@ MOUNTS: return binds, mounts, nil } +// requireMountAPI 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 requireMountAPI(bind *types.ServiceVolumeBind) bool { + switch { + case bind == nil: + return false + case !bind.CreateHostPath: + return true + case bind.Propagation != "": + return true + case bind.Recursive != "": + return true + default: + return false + } +} + func buildContainerMountOptions(p types.Project, s types.ServiceConfig, img moby.ImageInspect, inherit *moby.Container) ([]mount.Mount, error) { var mounts = map[string]mount.Mount{} if inherit != nil { @@ -1147,10 +1164,19 @@ func buildBindOption(bind *types.ServiceVolumeBind) *mount.BindOptions { if bind == nil { return nil } - return &mount.BindOptions{ - Propagation: mount.Propagation(bind.Propagation), - // NonRecursive: false, FIXME missing from model ? + opts := &mount.BindOptions{ + Propagation: mount.Propagation(bind.Propagation), + CreateMountpoint: bind.CreateHostPath, + } + switch bind.Recursive { + case "disabled": + opts.NonRecursive = true + case "writable": + opts.ReadOnlyNonRecursive = true + case "readonly": + opts.ReadOnlyForceRecursive = true } + return opts } func buildVolumeOptions(vol *types.ServiceVolumeVolume) *mount.VolumeOptions {