This repository has been archived by the owner on Feb 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement video feature in docker engine
- Loading branch information
Wander Lairson Costa
committed
May 23, 2018
1 parent
4d93412
commit f0ae3ea
Showing
7 changed files
with
167 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package dockerengine | ||
|
||
import ( | ||
"path/filepath" | ||
"regexp" | ||
|
||
"github.com/pkg/errors" | ||
funk "github.com/thoas/go-funk" | ||
) | ||
|
||
type device struct { | ||
path string | ||
claimed bool | ||
} | ||
|
||
type videoDeviceManager struct { | ||
devices []device | ||
} | ||
|
||
func newVideoDeviceManager() (*videoDeviceManager, error) { | ||
matches, err := filepath.Glob("/dev/video*") | ||
if err != nil { | ||
return nil, errors.Wrap(err, "Failed to call filepath.Glob function") | ||
} | ||
|
||
r := regexp.MustCompile("/dev/video[0-9]+") | ||
matches = funk.FilterString(matches, r.MatchString) | ||
|
||
devices := make([]device, len(matches)) | ||
for i := range devices { | ||
devices[i].path = matches[i] | ||
} | ||
|
||
return &videoDeviceManager{ | ||
devices: devices, | ||
}, nil | ||
} | ||
|
||
func (d *videoDeviceManager) claim() *device { | ||
for i := range d.devices { | ||
if !d.devices[i].claimed { | ||
return &d.devices[i] | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (d *videoDeviceManager) release(dev *device) { | ||
dev.claimed = false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// +build dockervideo | ||
|
||
package dockerengine | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/taskcluster/taskcluster-worker/engines/enginetest" | ||
) | ||
|
||
// Image and tag used in test cases below | ||
const ( | ||
videoDockerImageName = "alpine:3.6" | ||
) | ||
|
||
var videoProvider = &enginetest.EngineProvider{ | ||
Engine: "docker", | ||
Config: `{ | ||
"privileged": "allow", | ||
"enableDevices": true | ||
}`, | ||
} | ||
|
||
func TestVideo(t *testing.T) { | ||
c := enginetest.LoggingTestCase{ | ||
EngineProvider: videoProvider, | ||
Target: "/dev/video0", | ||
TargetPayload: `{ | ||
"command": ["sh", "-c", "ls /dev/video0"], | ||
"devices": ["video"], | ||
"image": "` + videoDockerImageName + `" | ||
}`, | ||
} | ||
|
||
c.Test() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters