@@ -15,6 +15,7 @@ import (
1515 "github.com/taskcluster/taskcluster-worker/runtime"
1616 "github.com/taskcluster/taskcluster-worker/runtime/atomics"
1717 "github.com/taskcluster/taskcluster-worker/runtime/ioext"
18+ funk "github.com/thoas/go-funk"
1819)
1920
2021const dockerEngineKillTimeout = 5 * time .Second
@@ -32,6 +33,7 @@ type sandbox struct {
3233 taskCtx * runtime.TaskContext
3334 networkHandle * network.Handle
3435 imageHandle * imagecache.ImageHandle
36+ videoDev * device
3537}
3638
3739func newSandbox (sb * sandboxBuilder ) (* sandbox , error ) {
@@ -52,6 +54,21 @@ func newSandbox(sb *sandboxBuilder) (*sandbox, error) {
5254 return nil , errors .Wrap (err , "docker.CreateNetwork failed" )
5355 }
5456
57+ devices := []docker.Device {}
58+ var dev * device
59+ if funk .InStrings (sb .payload .Devices , "video" ) {
60+ dev = sb .e .video .claim ()
61+ if dev == nil {
62+ return nil , errors .New ("No video device available" )
63+ }
64+ debug (fmt .Sprintf ("Claimed %s" , dev .path ))
65+ devices = append (devices , docker.Device {
66+ PathOnHost : dev .path ,
67+ PathInContainer : dev .path ,
68+ CgroupPermissions : "rwm" ,
69+ })
70+ }
71+
5572 // Create the container
5673 container , err := sb .e .docker .CreateContainer (docker.CreateContainerOptions {
5774 Config : & docker.Config {
@@ -70,6 +87,7 @@ func newSandbox(sb *sandboxBuilder) (*sandbox, error) {
7087 // to the proxies added to proxyMux above..
7188 ExtraHosts : []string {fmt .Sprintf ("taskcluster:%s" , networkHandle .Gateway ())},
7289 Mounts : sb .mounts ,
90+ Devices : devices ,
7391 },
7492 NetworkingConfig : & docker.NetworkingConfig {
7593 EndpointsConfig : map [string ]* docker.EndpointConfig {
@@ -79,6 +97,7 @@ func newSandbox(sb *sandboxBuilder) (*sandbox, error) {
7997 })
8098 if err != nil {
8199 imageHandle .Release ()
100+ sb .e .video .release (dev )
82101 return nil , runtime .NewMalformedPayloadError (
83102 "could not create container: " + err .Error ())
84103 }
@@ -87,6 +106,7 @@ func newSandbox(sb *sandboxBuilder) (*sandbox, error) {
87106 storage , err := sb .e .Environment .TemporaryStorage .NewFolder ()
88107 if err != nil {
89108 imageHandle .Release ()
109+ sb .e .video .release (dev )
90110 monitor .ReportError (err , "failed to create temporary folder" )
91111 return nil , runtime .ErrFatalInternalError
92112 }
@@ -101,6 +121,7 @@ func newSandbox(sb *sandboxBuilder) (*sandbox, error) {
101121 "containerId" : container .ID ,
102122 "networkId" : networkHandle .NetworkID (),
103123 }),
124+ videoDev : dev ,
104125 }
105126
106127 // attach to the container before starting so that we get all the logs
@@ -277,5 +298,9 @@ func (s *sandbox) dispose() error {
277298 if hasErr {
278299 return runtime .ErrNonFatalInternalError
279300 }
301+
302+ if s .videoDev != nil {
303+ s .videoDev .claimed = false
304+ }
280305 return nil
281306}
0 commit comments