forked from moby/buildkit
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- [X] put multiples workers in a single binary ("-tags containerd standalone") - [X] add worker selector to LLB vertex metadata - [X] s/worker/executor/g - [X] introduce the new "worker" concept moby#176 (comment) - [X] fix up CLI - [X] fix up tests - allow using multiples workers (requires inter-vertex cache copier, HUGE!) --> will be separate PR Implementation notes: - "Workers" are renamed to "executors" now - The new "worker" instance holds an "executor" instance and its related stuffs such as the snapshotter - The default worker is "runc-overlay" Signed-off-by: Akihiro Suda <[email protected]>
- Loading branch information
1 parent
b7664f7
commit 8899776
Showing
30 changed files
with
975 additions
and
575 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,70 @@ | ||
// +build containerd,!standalone | ||
// +build containerd | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/moby/buildkit/control" | ||
"os" | ||
"strings" | ||
|
||
ctd "github.com/containerd/containerd" | ||
"github.com/moby/buildkit/worker" | ||
"github.com/moby/buildkit/worker/containerd" | ||
"github.com/sirupsen/logrus" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
func appendFlags(f []cli.Flag) []cli.Flag { | ||
return append(f, []cli.Flag{ | ||
func init() { | ||
registerWorkerInitializer( | ||
workerInitializer{ | ||
fn: containerdWorkerInitializer, | ||
// 1 is less preferred than 0 (runcCtor) | ||
priority: 1, | ||
}, | ||
cli.StringFlag{ | ||
Name: "containerd-worker", | ||
Usage: "enable containerd workers (true/false/auto)", | ||
Value: "auto", | ||
}, | ||
cli.StringFlag{ | ||
Name: "containerd", | ||
Name: "containerd-worker-addr", | ||
Usage: "containerd socket", | ||
Value: "/run/containerd/containerd.sock", | ||
}, | ||
}...) | ||
}) | ||
// TODO(AkihiroSuda): allow using multiple snapshotters. should be useful for some applications that does not work with the default overlay snapshotter. e.g. mysql (docker/for-linux#72)", | ||
} | ||
|
||
// root must be an absolute path | ||
func newController(c *cli.Context, root string) (*control.Controller, error) { | ||
socket := c.GlobalString("containerd") | ||
func containerdWorkerInitializer(c *cli.Context, common workerInitializerOpt) ([]*worker.Worker, error) { | ||
socket := c.GlobalString("containerd-worker-addr") | ||
boolOrAuto, err := parseBoolOrAuto(c.GlobalString("containerd-worker")) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if (boolOrAuto == nil && !validContainerdSocket(socket)) || (boolOrAuto != nil && !*boolOrAuto) { | ||
return nil, nil | ||
} | ||
opt, err := containerd.NewWorkerOpt(common.root, socket, ctd.DefaultSnapshotter) | ||
if err != nil { | ||
return nil, err | ||
} | ||
opt.SessionManager = common.sessionManager | ||
w, err := worker.NewWorker(opt) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return []*worker.Worker{w}, nil | ||
} | ||
|
||
return control.NewContainerd(root, socket) | ||
func validContainerdSocket(socket string) bool { | ||
if strings.HasPrefix(socket, "tcp://") { | ||
// FIXME(AkihiroSuda): prohibit tcp? | ||
return true | ||
} | ||
socketPath := strings.TrimPrefix(socket, "unix://") | ||
if _, err := os.Stat(socketPath); os.IsNotExist(err) { | ||
// FIXME(AkihiroSuda): add more conditions | ||
logrus.Warnf("skipping containerd worker, as %q does not exist", socketPath) | ||
return false | ||
} | ||
// TODO: actually dial and call introspection API | ||
return true | ||
} |
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 |
---|---|---|
@@ -1,17 +1,57 @@ | ||
// +build standalone,!containerd | ||
// +build standalone | ||
|
||
// TODO(AkihiroSuda): s/standalone/oci/g | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/moby/buildkit/control" | ||
"os/exec" | ||
|
||
"github.com/moby/buildkit/worker" | ||
"github.com/moby/buildkit/worker/runc" | ||
"github.com/sirupsen/logrus" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
func appendFlags(f []cli.Flag) []cli.Flag { | ||
return f | ||
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 := worker.NewWorker(opt) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return []*worker.Worker{w}, nil | ||
} | ||
|
||
// root must be an absolute path | ||
func newController(c *cli.Context, root string) (*control.Controller, error) { | ||
return control.NewStandalone(root) | ||
func validOCIBinary() bool { | ||
_, err := exec.LookPath("runc") | ||
if err != nil { | ||
logrus.Warnf("skipping oci worker, as runc does not exist") | ||
return false | ||
} | ||
return true | ||
} |
This file was deleted.
Oops, something went wrong.
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,15 @@ | ||
package main | ||
|
||
import ( | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
// parseBoolOrAuto returns (nil, nil) if s is "auto" | ||
func parseBoolOrAuto(s string) (*bool, error) { | ||
if s == "" || strings.ToLower(s) == "auto" { | ||
return nil, nil | ||
} | ||
b, err := strconv.ParseBool(s) | ||
return &b, err | ||
} |
Oops, something went wrong.