forked from moby/buildkit
/
main_oci_worker.go
56 lines (50 loc) · 1.22 KB
/
main_oci_worker.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// +build linux,!no_oci_worker
package main
import (
"os/exec"
"github.com/moby/buildkit/worker"
"github.com/moby/buildkit/worker/base"
"github.com/moby/buildkit/worker/runc"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
)
func init() {
registerWorkerInitializer(
workerInitializer{
fn: ociWorkerInitializer,
priority: 0,
},
cli.StringFlag{
Name: "oci-worker",
Usage: "enable oci workers (true/false/auto)",
Value: "auto",
})
// TODO: allow multiple oci runtimes and snapshotters
}
func ociWorkerInitializer(c *cli.Context, common workerInitializerOpt) ([]worker.Worker, error) {
boolOrAuto, err := parseBoolOrAuto(c.GlobalString("oci-worker"))
if err != nil {
return nil, err
}
if (boolOrAuto == nil && !validOCIBinary()) || (boolOrAuto != nil && !*boolOrAuto) {
return nil, nil
}
opt, err := runc.NewWorkerOpt(common.root)
if err != nil {
return nil, err
}
opt.SessionManager = common.sessionManager
w, err := base.NewWorker(opt)
if err != nil {
return nil, err
}
return []worker.Worker{w}, nil
}
func validOCIBinary() bool {
_, err := exec.LookPath("runc")
if err != nil {
logrus.Warnf("skipping oci worker, as runc does not exist")
return false
}
return true
}