Skip to content

Commit c41cc9d

Browse files
committed
Pass appropriate --device arguments from compose to run
This was passing a stringified version of the DeviceMapping struct instead of a source:target:permissions string. Signed-off-by: Ryan Fowler <[email protected]>
1 parent 370b691 commit c41cc9d

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

pkg/composer/serviceparser/serviceparser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ func newContainer(project *types.Project, parsed *Service, i int) (*Container, e
515515
}
516516

517517
for _, v := range svc.Devices {
518-
c.RunArgs = append(c.RunArgs, fmt.Sprintf("--device=%s", v))
518+
c.RunArgs = append(c.RunArgs, fmt.Sprintf("--device=%s:%s:%s", v.Source, v.Target, v.Permissions))
519519
}
520520

521521
for _, v := range svc.DNS {

pkg/composer/serviceparser/serviceparser_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,36 @@ services:
337337

338338
}
339339

340+
func TestParseDevices(t *testing.T) {
341+
const dockerComposeYAML = `
342+
services:
343+
foo:
344+
image: nginx:alpine
345+
devices:
346+
- /dev/a
347+
- /dev/b:/dev/b
348+
- /dev/c:/dev/c:rw
349+
`
350+
comp := testutil.NewComposeDir(t, dockerComposeYAML)
351+
defer comp.CleanUp()
352+
353+
project, err := testutil.LoadProject(comp.YAMLFullPath(), comp.ProjectName(), nil)
354+
assert.NilError(t, err)
355+
356+
fooSvc, err := project.GetService("foo")
357+
assert.NilError(t, err)
358+
359+
foo, err := Parse(project, fooSvc)
360+
assert.NilError(t, err)
361+
362+
t.Logf("foo: %+v", foo)
363+
for _, c := range foo.Containers {
364+
assert.Assert(t, in(c.RunArgs, "--device=/dev/a:/dev/a:rwm"))
365+
assert.Assert(t, in(c.RunArgs, "--device=/dev/b:/dev/b:rwm"))
366+
assert.Assert(t, in(c.RunArgs, "--device=/dev/c:/dev/c:rw"))
367+
}
368+
}
369+
340370
func TestParseRelative(t *testing.T) {
341371
t.Parallel()
342372

0 commit comments

Comments
 (0)