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 - [WIP] introduce the new "worker" concept moby#176 (comment) - [X] fix up CLI - [ ] 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 - For containerd, we have separate workers for each of the available snapshotters: containerd-overlay, containerd-btrfs, ... However, only the default one is used, unless `containerd-worker-multiple-snapshotter` is specified. - The default worker is "runc-overlay" Signed-off-by: Akihiro Suda <[email protected]>
- Loading branch information
1 parent
bd9992f
commit 6f1d8dd
Showing
29 changed files
with
970 additions
and
693 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,73 @@ | ||
// +build containerd,!standalone | ||
// +build containerd | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/moby/buildkit/control" | ||
"os" | ||
"strings" | ||
|
||
"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() { | ||
appFlags = append(appFlags, | ||
cli.StringFlag{ | ||
Name: "containerd-worker", | ||
Usage: "enable containerd workers (true/false/auto)", | ||
}, | ||
cli.BoolFlag{ | ||
Name: "containerd-worker-multiple-snapshotters", | ||
Usage: "use multiple snapshotters. useful for some applications that does not work with the default snapshotter (overlay)", | ||
}, | ||
cli.StringFlag{ | ||
Name: "containerd", | ||
Name: "containerd-worker-addr", | ||
Usage: "containerd socket", | ||
Value: "/run/containerd/containerd.sock", | ||
}, | ||
}...) | ||
}) | ||
// 1 is less preferred than 0 (runcCtor) | ||
workerCtors[1] = containerdCtor | ||
} | ||
|
||
// root must be an absolute path | ||
func newController(c *cli.Context, root string) (*control.Controller, error) { | ||
socket := c.GlobalString("containerd") | ||
func containerdCtor(c *cli.Context, root string) ([]*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 && skipContainerd(socket)) || (boolOrAuto != nil && !*boolOrAuto) { | ||
return nil, nil | ||
} | ||
opts, err := containerd.NewWorkerOpts(root, socket) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if !c.GlobalBool("containerd-worker-multiple-snapshotters") { | ||
opts = opts[0:1] | ||
} | ||
var ws []*worker.Worker | ||
for _, opt := range opts { | ||
w, err := worker.NewWorker(opt) | ||
if err != nil { | ||
return ws, err | ||
} | ||
ws = append(ws, w) | ||
} | ||
return ws, nil | ||
} | ||
|
||
return control.NewContainerd(root, socket) | ||
func skipContainerd(socket string) bool { | ||
if strings.HasPrefix(socket, "tcp://") { | ||
// FIXME(AkihiroSuda): prohibit tcp? | ||
return false | ||
} | ||
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 true | ||
} | ||
return 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 |
---|---|---|
@@ -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() { | ||
appFlags = append(appFlags, | ||
cli.StringFlag{ | ||
Name: "oci-worker", | ||
Usage: "enable oci workers (true/false/auto)", | ||
}, | ||
) | ||
// TODO: allow multiple oci runtimes and snapshotters | ||
workerCtors[0] = runcCtor | ||
} | ||
|
||
func runcCtor(c *cli.Context, root string) ([]*worker.Worker, error) { | ||
boolOrAuto, err := parseBoolOrAuto(c.GlobalString("oci-worker")) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if (boolOrAuto == nil && skipRunc()) || (boolOrAuto != nil && !*boolOrAuto) { | ||
return nil, nil | ||
} | ||
opts, err := runc.NewWorkerOpts(root) | ||
if err != nil { | ||
return nil, err | ||
} | ||
var ws []*worker.Worker | ||
for _, opt := range opts { | ||
w, err := worker.NewWorker(opt) | ||
if err != nil { | ||
return ws, err | ||
} | ||
ws = append(ws, w) | ||
} | ||
return ws, nil | ||
} | ||
|
||
// root must be an absolute path | ||
func newController(c *cli.Context, root string) (*control.Controller, error) { | ||
return control.NewStandalone(root) | ||
func skipRunc() bool { | ||
_, err := exec.LookPath("runc") | ||
if err != nil { | ||
logrus.Warnf("skipping oci worker, as runc does not exist") | ||
return true | ||
} | ||
return false | ||
} |
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 strings.ToLower(s) == "auto" { | ||
return nil, nil | ||
} | ||
b, err := strconv.ParseBool(s) | ||
return &b, err | ||
} |
Oops, something went wrong.