2017-12-15 07:00:13 +00:00
|
|
|
// +build linux,!no_oci_worker
|
2017-06-08 00:54:29 +00:00
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2017-11-21 08:08:36 +00:00
|
|
|
"os/exec"
|
|
|
|
|
|
|
|
"github.com/moby/buildkit/worker"
|
2017-12-15 08:06:54 +00:00
|
|
|
"github.com/moby/buildkit/worker/base"
|
2017-11-21 08:08:36 +00:00
|
|
|
"github.com/moby/buildkit/worker/runc"
|
|
|
|
"github.com/sirupsen/logrus"
|
2017-06-08 00:54:29 +00:00
|
|
|
"github.com/urfave/cli"
|
|
|
|
)
|
|
|
|
|
2017-11-21 08:08:36 +00:00
|
|
|
func init() {
|
|
|
|
registerWorkerInitializer(
|
|
|
|
workerInitializer{
|
|
|
|
fn: ociWorkerInitializer,
|
|
|
|
priority: 0,
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "oci-worker",
|
|
|
|
Usage: "enable oci workers (true/false/auto)",
|
|
|
|
Value: "auto",
|
2017-12-19 09:34:34 +00:00
|
|
|
},
|
|
|
|
cli.StringSliceFlag{
|
|
|
|
Name: "oci-worker-labels",
|
|
|
|
Usage: "user-specific annotation labels (com.example.foo=bar)",
|
|
|
|
},
|
2018-02-19 05:33:49 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "oci-worker-snapshotter",
|
|
|
|
Usage: "name of snapshotter (overlayfs or naive)",
|
|
|
|
// TODO(AkihiroSuda): autodetect overlayfs availability when the value is set to "auto"?
|
|
|
|
Value: "overlayfs",
|
|
|
|
},
|
2017-12-19 09:34:34 +00:00
|
|
|
)
|
2017-11-21 08:08:36 +00:00
|
|
|
// TODO: allow multiple oci runtimes and snapshotters
|
|
|
|
}
|
|
|
|
|
2017-12-15 08:06:54 +00:00
|
|
|
func ociWorkerInitializer(c *cli.Context, common workerInitializerOpt) ([]worker.Worker, error) {
|
2017-11-21 08:08:36 +00:00
|
|
|
boolOrAuto, err := parseBoolOrAuto(c.GlobalString("oci-worker"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if (boolOrAuto == nil && !validOCIBinary()) || (boolOrAuto != nil && !*boolOrAuto) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
2017-12-19 09:34:34 +00:00
|
|
|
labels, err := attrMap(c.GlobalStringSlice("oci-worker-labels"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-02-19 05:33:49 +00:00
|
|
|
opt, err := runc.NewWorkerOpt(common.root, labels, c.GlobalString("oci-worker-snapshotter"))
|
2017-11-21 08:08:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
opt.SessionManager = common.sessionManager
|
2017-12-15 08:06:54 +00:00
|
|
|
w, err := base.NewWorker(opt)
|
2017-11-21 08:08:36 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-12-15 08:06:54 +00:00
|
|
|
return []worker.Worker{w}, nil
|
2017-06-08 19:00:31 +00:00
|
|
|
}
|
|
|
|
|
2017-11-21 08:08:36 +00:00
|
|
|
func validOCIBinary() bool {
|
|
|
|
_, err := exec.LookPath("runc")
|
|
|
|
if err != nil {
|
|
|
|
logrus.Warnf("skipping oci worker, as runc does not exist")
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
return true
|
2017-06-08 00:54:29 +00:00
|
|
|
}
|