Skip to content

Commit 2215dc5

Browse files
authored
Merge pull request #3903 from dancavallaro/dancavallaro/propagation
Support bind propagation options in Compose volume long syntax
2 parents 98f3846 + c169499 commit 2215dc5

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

pkg/composer/serviceparser/serviceparser.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,8 +781,7 @@ func serviceVolumeConfigToFlagV(c types.ServiceVolumeConfig, project *types.Proj
781781
log.L.Warnf("Ignoring: volume: %+v", unknown)
782782
}
783783
if c.Bind != nil {
784-
// c.Bind is expected to be a non-nil reference to an empty Bind struct
785-
if unknown := reflectutil.UnknownNonEmptyFields(c.Bind, "CreateHostPath"); len(unknown) > 0 {
784+
if unknown := reflectutil.UnknownNonEmptyFields(c.Bind, "CreateHostPath", "Propagation"); len(unknown) > 0 {
786785
log.L.Warnf("Ignoring: volume: Bind: %+v", unknown)
787786
}
788787
}
@@ -810,6 +809,7 @@ func serviceVolumeConfigToFlagV(c types.ServiceVolumeConfig, project *types.Proj
810809
}
811810

812811
var src string
812+
var opts []string
813813
switch c.Type {
814814
case "volume":
815815
vol, ok := project.Volumes[c.Source]
@@ -830,12 +830,18 @@ func serviceVolumeConfigToFlagV(c types.ServiceVolumeConfig, project *types.Proj
830830
mkdir = append(mkdir, src)
831831
}
832832
}
833+
if c.Bind != nil && c.Bind.Propagation != "" {
834+
opts = append(opts, c.Bind.Propagation)
835+
}
833836
default:
834837
return "", nil, fmt.Errorf("unsupported volume type: %q", c.Type)
835838
}
836839
s := fmt.Sprintf("%s:%s", src, c.Target)
837840
if c.ReadOnly {
838-
s += ":ro"
841+
opts = append(opts, "ro")
842+
}
843+
if len(opts) > 0 {
844+
s = fmt.Sprintf("%s:%s", s, strings.Join(opts, ","))
839845
}
840846
return s, mkdir, nil
841847
}

pkg/composer/serviceparser/serviceparser_test.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -403,6 +403,42 @@ services:
403403
}
404404
}
405405

406+
func TestParseVolumeLongSyntax(t *testing.T) {
407+
t.Parallel()
408+
409+
if runtime.GOOS == "windows" {
410+
t.Skip("test is not compatible with windows")
411+
}
412+
const dockerComposeYAML = `
413+
services:
414+
foo:
415+
image: nginx:alpine
416+
volumes:
417+
- type: bind
418+
source: /src/dir1
419+
target: /tgt/dir1
420+
read_only: true
421+
bind:
422+
propagation: rshared
423+
`
424+
comp := testutil.NewComposeDir(t, dockerComposeYAML)
425+
defer comp.CleanUp()
426+
427+
project, err := testutil.LoadProject(comp.YAMLFullPath(), comp.ProjectName(), nil)
428+
assert.NilError(t, err)
429+
430+
fooSvc, err := project.GetService("foo")
431+
assert.NilError(t, err)
432+
433+
foo, err := Parse(project, fooSvc)
434+
assert.NilError(t, err)
435+
436+
t.Logf("foo: %+v", foo)
437+
for _, c := range foo.Containers {
438+
assert.Assert(t, in(c.RunArgs, "-v=/src/dir1:/tgt/dir1:rshared,ro"))
439+
}
440+
}
441+
406442
func TestParseNetworkMode(t *testing.T) {
407443
t.Parallel()
408444
const dockerComposeYAML = `

0 commit comments

Comments
 (0)