@@ -326,23 +326,12 @@ func generateMainComposeFile(
326326 if err = validateDevices (devices , requiredDeviceClasses ); err != nil {
327327 return fmt .Errorf ("missing required device: %w" , err )
328328 }
329- if devices .hasVideoDevice {
330- // If we are adding video devices, mount also /dev/v4l if it exists to allow access to by-id/path links
331- if paths .New ("/dev/v4l" ).Exist () {
329+ if len (devices .additionalDeviceVolumes ) > 0 {
330+ for _ , devVolume := range devices .additionalDeviceVolumes {
332331 volumes = append (volumes , volume {
333332 Type : "bind" ,
334- Source : "/dev/v4l" ,
335- Target : "/dev/v4l" ,
336- })
337- }
338- }
339- if devices .hasSoundDevice {
340- // If we are adding sound devices, mount also /dev/snd if it exists to allow access to by-id links
341- if paths .New ("/dev/snd" ).Exist () {
342- volumes = append (volumes , volume {
343- Type : "bind" ,
344- Source : "/dev/snd" ,
345- Target : "/dev/snd" ,
333+ Source : devVolume ,
334+ Target : devVolume ,
346335 })
347336 }
348337 }
@@ -409,7 +398,7 @@ func generateMainComposeFile(
409398
410399 // If there are services that require devices, we need to generate an override compose file
411400 // Write additional file to override devices section in included compose files
412- if e := generateServicesOverrideFile (app , slices .Collect (maps .Keys (services )), servicesThatRequireDevices , devices . devicePaths , getCurrentUser (), groups , overrideComposeFile , envs ); e != nil {
401+ if e := generateServicesOverrideFile (app , slices .Collect (maps .Keys (services )), servicesThatRequireDevices , devices , getCurrentUser (), groups , overrideComposeFile , envs ); e != nil {
413402 return e
414403 }
415404
@@ -463,7 +452,7 @@ func extractServicesFromComposeFile(composeFile *paths.Path) (map[string]service
463452 return services , nil
464453}
465454
466- func generateServicesOverrideFile (arduinoApp * app.ArduinoApp , services []string , servicesThatRequireDevices []string , devices [] string , user string , groups []string , overrideComposeFile * paths.Path , envs helpers.EnvVars ) error {
455+ func generateServicesOverrideFile (arduinoApp * app.ArduinoApp , services []string , servicesThatRequireDevices []string , devices * deviceResult , user string , groups []string , overrideComposeFile * paths.Path , envs helpers.EnvVars ) error {
467456 if overrideComposeFile .Exist () {
468457 if err := overrideComposeFile .Remove (); err != nil {
469458 return fmt .Errorf ("failed to remove existing override compose file: %w" , err )
@@ -476,11 +465,12 @@ func generateServicesOverrideFile(arduinoApp *app.ArduinoApp, services []string,
476465 }
477466
478467 type serviceOverride struct {
479- User string `yaml:"user,omitempty"`
480- Devices * []string `yaml:"devices,omitempty"`
481- GroupAdd * []string `yaml:"group_add,omitempty"`
482- Labels map [string ]string `yaml:"labels,omitempty"`
483- Environment map [string ]string `yaml:"environment,omitempty"`
468+ User string `yaml:"user,omitempty"`
469+ Devices * []string `yaml:"devices,omitempty"`
470+ DeviceCgroupRules * []string `yaml:"device_cgroup_rules,omitempty"`
471+ GroupAdd * []string `yaml:"group_add,omitempty"`
472+ Labels map [string ]string `yaml:"labels,omitempty"`
473+ Environment map [string ]string `yaml:"environment,omitempty"`
484474 }
485475 var overrideCompose struct {
486476 Services map [string ]serviceOverride `yaml:"services,omitempty"`
@@ -494,8 +484,9 @@ func generateServicesOverrideFile(arduinoApp *app.ArduinoApp, services []string,
494484 DockerAppPathLabel : arduinoApp .FullPath .String (),
495485 },
496486 }
497- if slices .Contains (servicesThatRequireDevices , svc ) {
498- override .Devices = & devices
487+ if slices .Contains (servicesThatRequireDevices , svc ) && devices != nil {
488+ override .Devices = & devices .devicePaths
489+ override .DeviceCgroupRules = & devices .deviceCgroupRules
499490 override .GroupAdd = & groups
500491 }
501492 override .Environment = envs
0 commit comments