2017-06-08 00:54:29 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2018-01-16 22:30:10 +00:00
|
|
|
"context"
|
2017-12-20 10:45:06 +00:00
|
|
|
"crypto/tls"
|
|
|
|
"crypto/x509"
|
2017-06-08 00:54:29 +00:00
|
|
|
"fmt"
|
2017-12-20 10:45:06 +00:00
|
|
|
"io/ioutil"
|
2017-09-21 15:49:26 +00:00
|
|
|
"net"
|
2017-06-08 00:54:29 +00:00
|
|
|
"os"
|
2018-04-11 13:34:39 +00:00
|
|
|
"os/user"
|
2017-06-12 08:49:48 +00:00
|
|
|
"path/filepath"
|
2017-11-21 08:08:36 +00:00
|
|
|
"sort"
|
2018-04-11 13:34:39 +00:00
|
|
|
"strconv"
|
2017-09-21 15:49:26 +00:00
|
|
|
"strings"
|
2017-06-08 00:54:29 +00:00
|
|
|
|
2018-07-17 18:15:14 +00:00
|
|
|
"github.com/containerd/containerd/pkg/seed"
|
2018-06-24 05:59:17 +00:00
|
|
|
"github.com/containerd/containerd/platforms"
|
2017-06-08 00:54:29 +00:00
|
|
|
"github.com/containerd/containerd/sys"
|
2017-09-21 15:49:26 +00:00
|
|
|
"github.com/docker/go-connections/sockets"
|
2018-01-05 23:17:35 +00:00
|
|
|
"github.com/grpc-ecosystem/grpc-opentracing/go/otgrpc"
|
2018-07-03 09:59:33 +00:00
|
|
|
registryremotecache "github.com/moby/buildkit/cache/remotecache/registry"
|
2017-11-21 08:08:36 +00:00
|
|
|
"github.com/moby/buildkit/control"
|
|
|
|
"github.com/moby/buildkit/frontend"
|
2018-07-05 23:32:01 +00:00
|
|
|
dockerfile "github.com/moby/buildkit/frontend/dockerfile/builder"
|
2017-11-21 08:08:36 +00:00
|
|
|
"github.com/moby/buildkit/frontend/gateway"
|
2018-07-05 21:31:50 +00:00
|
|
|
"github.com/moby/buildkit/frontend/gateway/forwarder"
|
2017-11-21 08:08:36 +00:00
|
|
|
"github.com/moby/buildkit/session"
|
2018-05-11 05:58:41 +00:00
|
|
|
"github.com/moby/buildkit/solver/boltdbcachestorage"
|
2018-07-09 22:02:52 +00:00
|
|
|
"github.com/moby/buildkit/util/apicaps"
|
2017-07-03 04:21:40 +00:00
|
|
|
"github.com/moby/buildkit/util/appcontext"
|
2017-07-12 05:08:53 +00:00
|
|
|
"github.com/moby/buildkit/util/appdefaults"
|
2017-07-12 22:17:23 +00:00
|
|
|
"github.com/moby/buildkit/util/profiler"
|
2018-05-21 10:42:59 +00:00
|
|
|
"github.com/moby/buildkit/version"
|
2017-11-21 08:08:36 +00:00
|
|
|
"github.com/moby/buildkit/worker"
|
2018-06-24 05:59:17 +00:00
|
|
|
specs "github.com/opencontainers/image-spec/specs-go/v1"
|
2018-07-02 04:56:50 +00:00
|
|
|
"github.com/opencontainers/runc/libcontainer/system"
|
2017-06-08 00:54:29 +00:00
|
|
|
"github.com/pkg/errors"
|
2017-07-19 01:05:19 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2017-06-08 00:54:29 +00:00
|
|
|
"github.com/urfave/cli"
|
2017-12-04 03:09:39 +00:00
|
|
|
"golang.org/x/sync/errgroup"
|
2017-06-08 18:17:44 +00:00
|
|
|
"google.golang.org/grpc"
|
2017-12-20 10:45:06 +00:00
|
|
|
"google.golang.org/grpc/credentials"
|
2017-06-08 00:54:29 +00:00
|
|
|
)
|
|
|
|
|
2018-07-09 22:02:52 +00:00
|
|
|
func init() {
|
|
|
|
apicaps.ExportedProduct = "buildkit"
|
2018-07-17 18:15:14 +00:00
|
|
|
seed.WithTimeAndRand()
|
2018-07-09 22:02:52 +00:00
|
|
|
}
|
|
|
|
|
2017-11-21 08:08:36 +00:00
|
|
|
type workerInitializerOpt struct {
|
|
|
|
sessionManager *session.Manager
|
|
|
|
root string
|
|
|
|
}
|
|
|
|
|
|
|
|
type workerInitializer struct {
|
2017-12-15 08:06:54 +00:00
|
|
|
fn func(c *cli.Context, common workerInitializerOpt) ([]worker.Worker, error)
|
2017-11-21 08:08:36 +00:00
|
|
|
// less priority number, more preferred
|
|
|
|
priority int
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
appFlags []cli.Flag
|
|
|
|
workerInitializers []workerInitializer
|
|
|
|
)
|
|
|
|
|
|
|
|
func registerWorkerInitializer(wi workerInitializer, flags ...cli.Flag) {
|
|
|
|
workerInitializers = append(workerInitializers, wi)
|
|
|
|
sort.Slice(workerInitializers,
|
|
|
|
func(i, j int) bool {
|
|
|
|
return workerInitializers[i].priority < workerInitializers[j].priority
|
|
|
|
})
|
|
|
|
appFlags = append(appFlags, flags...)
|
|
|
|
}
|
|
|
|
|
2017-06-08 00:54:29 +00:00
|
|
|
func main() {
|
2018-05-21 10:42:59 +00:00
|
|
|
cli.VersionPrinter = func(c *cli.Context) {
|
|
|
|
fmt.Println(c.App.Name, version.Package, c.App.Version, version.Revision)
|
|
|
|
}
|
2017-06-08 00:54:29 +00:00
|
|
|
app := cli.NewApp()
|
2017-12-18 07:33:02 +00:00
|
|
|
app.Name = "buildkitd"
|
2017-06-08 00:54:29 +00:00
|
|
|
app.Usage = "build daemon"
|
2018-05-30 02:49:43 +00:00
|
|
|
defaultRoot := appdefaults.Root
|
|
|
|
defaultAddress := appdefaults.Address
|
|
|
|
rootlessUsage := "set all the default options to be compatible with rootless containers"
|
2018-07-02 04:56:50 +00:00
|
|
|
if system.RunningInUserNS() {
|
2018-05-30 02:49:43 +00:00
|
|
|
app.Flags = append(app.Flags, cli.BoolTFlag{
|
|
|
|
Name: "rootless",
|
|
|
|
Usage: rootlessUsage + " (default: true)",
|
|
|
|
})
|
2018-07-02 04:56:50 +00:00
|
|
|
// if buildkitd is being executed as the mapped-root (not only EUID==0 but also $USER==root)
|
|
|
|
// in a user namespace, we need to enable the rootless mode but
|
|
|
|
// we don't want to honor $HOME for setting up default paths.
|
|
|
|
if u := os.Getenv("USER"); u != "" && u != "root" {
|
|
|
|
defaultRoot = appdefaults.UserRoot()
|
|
|
|
defaultAddress = appdefaults.UserAddress()
|
|
|
|
appdefaults.EnsureUserAddressDir()
|
|
|
|
}
|
2018-05-30 02:49:43 +00:00
|
|
|
} else {
|
|
|
|
app.Flags = append(app.Flags, cli.BoolFlag{
|
|
|
|
Name: "rootless",
|
|
|
|
Usage: rootlessUsage,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
app.Flags = append(app.Flags,
|
2017-06-08 00:54:29 +00:00
|
|
|
cli.BoolFlag{
|
|
|
|
Name: "debug",
|
|
|
|
Usage: "enable debug output in logs",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
|
|
|
Name: "root",
|
|
|
|
Usage: "path to state directory",
|
2018-05-30 02:49:43 +00:00
|
|
|
Value: defaultRoot,
|
2017-06-08 00:54:29 +00:00
|
|
|
},
|
2017-12-04 03:09:39 +00:00
|
|
|
cli.StringSliceFlag{
|
2017-09-21 15:49:26 +00:00
|
|
|
Name: "addr",
|
|
|
|
Usage: "listening address (socket or tcp)",
|
2018-05-30 02:49:43 +00:00
|
|
|
Value: &cli.StringSlice{defaultAddress},
|
2017-06-08 00:54:29 +00:00
|
|
|
},
|
2018-04-11 13:34:39 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "group",
|
|
|
|
Usage: "group (name or gid) which will own all Unix socket listening addresses",
|
|
|
|
Value: "",
|
|
|
|
},
|
2017-07-03 06:52:27 +00:00
|
|
|
cli.StringFlag{
|
|
|
|
Name: "debugaddr",
|
2017-09-21 15:49:26 +00:00
|
|
|
Usage: "debugging address (eg. 0.0.0.0:6060)",
|
2017-07-03 06:52:27 +00:00
|
|
|
Value: "",
|
|
|
|
},
|
2017-12-20 10:45:06 +00:00
|
|
|
cli.StringFlag{
|
2017-12-21 05:18:54 +00:00
|
|
|
Name: "tlscert",
|
2017-12-20 10:45:06 +00:00
|
|
|
Usage: "certificate file to use",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2017-12-21 05:18:54 +00:00
|
|
|
Name: "tlskey",
|
2017-12-20 10:45:06 +00:00
|
|
|
Usage: "key file to use",
|
|
|
|
},
|
|
|
|
cli.StringFlag{
|
2017-12-21 05:18:54 +00:00
|
|
|
Name: "tlscacert",
|
2017-12-20 10:45:06 +00:00
|
|
|
Usage: "ca certificate to verify clients",
|
|
|
|
},
|
2018-05-30 02:49:43 +00:00
|
|
|
)
|
2017-11-21 08:08:36 +00:00
|
|
|
app.Flags = append(app.Flags, appFlags...)
|
2017-06-08 19:00:31 +00:00
|
|
|
|
2017-06-08 00:54:29 +00:00
|
|
|
app.Action = func(c *cli.Context) error {
|
2018-07-02 05:22:49 +00:00
|
|
|
if os.Geteuid() != 0 {
|
|
|
|
return errors.New("rootless mode requires to be executed as the mapped root in a user namespace; you may use RootlessKit for setting up the namespace")
|
|
|
|
}
|
2017-07-03 04:21:40 +00:00
|
|
|
ctx, cancel := context.WithCancel(appcontext.Context())
|
2018-01-16 22:30:10 +00:00
|
|
|
defer cancel()
|
2017-06-08 00:54:29 +00:00
|
|
|
|
2017-07-03 06:52:27 +00:00
|
|
|
if debugAddr := c.GlobalString("debugaddr"); debugAddr != "" {
|
|
|
|
if err := setupDebugHandlers(debugAddr); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
2018-01-05 23:17:35 +00:00
|
|
|
opts := []grpc.ServerOption{unaryInterceptor(ctx), grpc.StreamInterceptor(otgrpc.OpenTracingStreamServerInterceptor(tracer))}
|
2017-12-20 10:45:06 +00:00
|
|
|
creds, err := serverCredentials(c)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if creds != nil {
|
|
|
|
opts = append(opts, creds)
|
|
|
|
}
|
|
|
|
server := grpc.NewServer(opts...)
|
2017-06-08 00:54:29 +00:00
|
|
|
|
2017-06-12 08:49:48 +00:00
|
|
|
// relative path does not work with nightlyone/lockfile
|
|
|
|
root, err := filepath.Abs(c.GlobalString("root"))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2017-06-08 00:54:29 +00:00
|
|
|
|
|
|
|
if err := os.MkdirAll(root, 0700); err != nil {
|
|
|
|
return errors.Wrapf(err, "failed to create %s", root)
|
|
|
|
}
|
|
|
|
|
2017-06-12 08:49:48 +00:00
|
|
|
controller, err := newController(c, root)
|
2017-06-08 00:54:29 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
controller.Register(server)
|
|
|
|
|
2017-07-03 04:21:40 +00:00
|
|
|
errCh := make(chan error, 1)
|
2017-12-04 03:09:39 +00:00
|
|
|
addrs := c.GlobalStringSlice("addr")
|
|
|
|
if len(addrs) > 1 {
|
|
|
|
addrs = addrs[1:] // https://github.com/urfave/cli/issues/160
|
|
|
|
}
|
2018-04-11 13:34:39 +00:00
|
|
|
if err := serveGRPC(c, server, addrs, errCh); err != nil {
|
2017-06-08 00:54:29 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2017-07-03 04:21:40 +00:00
|
|
|
select {
|
|
|
|
case serverErr := <-errCh:
|
|
|
|
err = serverErr
|
|
|
|
cancel()
|
|
|
|
case <-ctx.Done():
|
|
|
|
err = ctx.Err()
|
|
|
|
}
|
|
|
|
|
|
|
|
logrus.Infof("stopping server")
|
|
|
|
server.GracefulStop()
|
|
|
|
|
|
|
|
return err
|
2017-06-08 00:54:29 +00:00
|
|
|
}
|
|
|
|
app.Before = func(context *cli.Context) error {
|
|
|
|
if context.GlobalBool("debug") {
|
|
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2017-07-12 22:17:23 +00:00
|
|
|
|
2018-01-05 23:17:35 +00:00
|
|
|
app.After = func(context *cli.Context) error {
|
|
|
|
if closeTracer != nil {
|
|
|
|
return closeTracer.Close()
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2017-07-12 22:17:23 +00:00
|
|
|
profiler.Attach(app)
|
|
|
|
|
2017-06-08 00:54:29 +00:00
|
|
|
if err := app.Run(os.Args); err != nil {
|
2017-12-18 07:33:02 +00:00
|
|
|
fmt.Fprintf(os.Stderr, "buildkitd: %s\n", err)
|
2017-06-08 00:54:29 +00:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-11 13:34:39 +00:00
|
|
|
func serveGRPC(c *cli.Context, server *grpc.Server, addrs []string, errCh chan error) error {
|
2017-12-04 03:09:39 +00:00
|
|
|
if len(addrs) == 0 {
|
2017-09-21 15:49:26 +00:00
|
|
|
return errors.New("--addr cannot be empty")
|
2017-06-08 00:54:29 +00:00
|
|
|
}
|
2017-12-04 03:09:39 +00:00
|
|
|
eg, _ := errgroup.WithContext(context.Background())
|
|
|
|
listeners := make([]net.Listener, 0, len(addrs))
|
|
|
|
for _, addr := range addrs {
|
2018-04-11 13:34:39 +00:00
|
|
|
l, err := getListener(c, addr)
|
2017-12-04 03:09:39 +00:00
|
|
|
if err != nil {
|
|
|
|
for _, l := range listeners {
|
|
|
|
l.Close()
|
|
|
|
}
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
listeners = append(listeners, l)
|
|
|
|
}
|
|
|
|
for _, l := range listeners {
|
|
|
|
func(l net.Listener) {
|
|
|
|
eg.Go(func() error {
|
|
|
|
defer l.Close()
|
|
|
|
logrus.Infof("running server on %s", l.Addr())
|
|
|
|
return server.Serve(l)
|
|
|
|
})
|
|
|
|
}(l)
|
2017-06-08 00:54:29 +00:00
|
|
|
}
|
|
|
|
go func() {
|
2017-12-04 03:09:39 +00:00
|
|
|
errCh <- eg.Wait()
|
2017-06-08 00:54:29 +00:00
|
|
|
}()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2018-04-11 13:34:39 +00:00
|
|
|
// Convert a string containing either a group name or a stringified gid into a numeric id)
|
|
|
|
func groupToGid(group string) (int, error) {
|
|
|
|
if group == "" {
|
|
|
|
return os.Getgid(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
var (
|
|
|
|
err error
|
|
|
|
id int
|
|
|
|
)
|
|
|
|
|
|
|
|
// Try and parse as a number, if the error is ErrSyntax
|
|
|
|
// (i.e. its not a number) then we carry on and try it as a
|
|
|
|
// name.
|
|
|
|
if id, err = strconv.Atoi(group); err == nil {
|
|
|
|
return id, nil
|
|
|
|
} else if err.(*strconv.NumError).Err != strconv.ErrSyntax {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
ginfo, err := user.LookupGroup(group)
|
|
|
|
if err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
group = ginfo.Gid
|
|
|
|
|
|
|
|
if id, err = strconv.Atoi(group); err != nil {
|
|
|
|
return 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return id, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getListener(c *cli.Context, addr string) (net.Listener, error) {
|
2017-09-21 15:49:26 +00:00
|
|
|
addrSlice := strings.SplitN(addr, "://", 2)
|
2018-01-23 02:29:07 +00:00
|
|
|
if len(addrSlice) < 2 {
|
|
|
|
return nil, errors.Errorf("address %s does not contain proto, you meant unix://%s ?",
|
|
|
|
addr, addr)
|
|
|
|
}
|
2017-09-21 15:49:26 +00:00
|
|
|
proto := addrSlice[0]
|
|
|
|
listenAddr := addrSlice[1]
|
|
|
|
switch proto {
|
|
|
|
case "unix", "npipe":
|
2018-04-11 13:34:39 +00:00
|
|
|
uid := os.Getuid()
|
|
|
|
gid, err := groupToGid(c.GlobalString("group"))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return sys.GetLocalListener(listenAddr, uid, gid)
|
2017-09-21 15:49:26 +00:00
|
|
|
case "tcp":
|
|
|
|
return sockets.NewTCPSocket(listenAddr, nil)
|
|
|
|
default:
|
|
|
|
return nil, errors.Errorf("addr %s not supported", addr)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-03 04:21:40 +00:00
|
|
|
func unaryInterceptor(globalCtx context.Context) grpc.ServerOption {
|
2018-01-05 23:17:35 +00:00
|
|
|
withTrace := otgrpc.OpenTracingServerInterceptor(tracer, otgrpc.LogPayloads())
|
|
|
|
|
2018-05-01 01:10:54 +00:00
|
|
|
return grpc.UnaryInterceptor(func(ctx context.Context, req interface{}, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp interface{}, err error) {
|
2017-07-03 04:21:40 +00:00
|
|
|
ctx, cancel := context.WithCancel(ctx)
|
|
|
|
defer cancel()
|
|
|
|
|
|
|
|
go func() {
|
|
|
|
select {
|
|
|
|
case <-ctx.Done():
|
|
|
|
case <-globalCtx.Done():
|
|
|
|
cancel()
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
|
2018-01-05 23:17:35 +00:00
|
|
|
resp, err = withTrace(ctx, req, info, handler)
|
2017-06-09 01:16:19 +00:00
|
|
|
if err != nil {
|
|
|
|
logrus.Errorf("%s returned error: %+v", info.FullMethod, err)
|
|
|
|
}
|
|
|
|
return
|
|
|
|
})
|
|
|
|
}
|
2017-11-21 08:08:36 +00:00
|
|
|
|
2017-12-20 10:45:06 +00:00
|
|
|
func serverCredentials(c *cli.Context) (grpc.ServerOption, error) {
|
2017-12-21 07:54:20 +00:00
|
|
|
certFile := c.GlobalString("tlscert")
|
|
|
|
keyFile := c.GlobalString("tlskey")
|
|
|
|
caFile := c.GlobalString("tlscacert")
|
2017-12-20 10:45:06 +00:00
|
|
|
if certFile == "" && keyFile == "" {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
err := errors.New("you must specify key and cert file if one is specified")
|
|
|
|
if certFile == "" {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if keyFile == "" {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
certificate, err := tls.LoadX509KeyPair(certFile, keyFile)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not load server key pair")
|
|
|
|
}
|
|
|
|
tlsConf := &tls.Config{
|
|
|
|
Certificates: []tls.Certificate{certificate},
|
|
|
|
}
|
|
|
|
if caFile != "" {
|
|
|
|
certPool := x509.NewCertPool()
|
|
|
|
ca, err := ioutil.ReadFile(caFile)
|
|
|
|
if err != nil {
|
|
|
|
return nil, errors.Wrap(err, "could not read ca certificate")
|
|
|
|
}
|
|
|
|
// Append the client certificates from the CA
|
|
|
|
if ok := certPool.AppendCertsFromPEM(ca); !ok {
|
|
|
|
return nil, errors.New("failed to append ca cert")
|
|
|
|
}
|
|
|
|
tlsConf.ClientAuth = tls.RequireAndVerifyClientCert
|
|
|
|
tlsConf.ClientCAs = certPool
|
|
|
|
}
|
|
|
|
creds := grpc.Creds(credentials.NewTLS(tlsConf))
|
|
|
|
return creds, nil
|
|
|
|
}
|
|
|
|
|
2017-11-21 08:08:36 +00:00
|
|
|
func newController(c *cli.Context, root string) (*control.Controller, error) {
|
|
|
|
sessionManager, err := session.NewManager()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
wc, err := newWorkerController(c, workerInitializerOpt{
|
|
|
|
sessionManager: sessionManager,
|
|
|
|
root: root,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
frontends := map[string]frontend.Frontend{}
|
2018-07-05 23:32:01 +00:00
|
|
|
frontends["dockerfile.v0"] = forwarder.NewGatewayForwarder(wc, dockerfile.Build)
|
2018-06-30 01:35:39 +00:00
|
|
|
frontends["gateway.v0"] = gateway.NewGatewayFrontend(wc)
|
2017-12-15 08:06:54 +00:00
|
|
|
|
2018-04-13 21:13:48 +00:00
|
|
|
cacheStorage, err := boltdbcachestorage.NewStore(filepath.Join(root, "cache.db"))
|
2017-12-15 08:06:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2017-11-21 08:08:36 +00:00
|
|
|
return control.NewController(control.Opt{
|
|
|
|
SessionManager: sessionManager,
|
|
|
|
WorkerController: wc,
|
|
|
|
Frontends: frontends,
|
2018-07-03 09:59:33 +00:00
|
|
|
// TODO: support non-registry remote cache
|
|
|
|
ResolveCacheExporterFunc: registryremotecache.ResolveCacheExporterFunc(sessionManager),
|
|
|
|
ResolveCacheImporterFunc: registryremotecache.ResolveCacheImporterFunc(sessionManager),
|
|
|
|
CacheKeyStorage: cacheStorage,
|
2017-11-21 08:08:36 +00:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func newWorkerController(c *cli.Context, wiOpt workerInitializerOpt) (*worker.Controller, error) {
|
|
|
|
wc := &worker.Controller{}
|
2017-12-19 09:34:34 +00:00
|
|
|
nWorkers := 0
|
2017-11-21 08:08:36 +00:00
|
|
|
for _, wi := range workerInitializers {
|
|
|
|
ws, err := wi.fn(c, wiOpt)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
for _, w := range ws {
|
2018-06-24 05:59:17 +00:00
|
|
|
logrus.Infof("found worker %q, labels=%v, platforms=%v", w.ID(), w.Labels(), formatPlatforms(w.Platforms()))
|
2017-11-21 08:08:36 +00:00
|
|
|
if err = wc.Add(w); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-12-19 09:34:34 +00:00
|
|
|
nWorkers++
|
2017-11-21 08:08:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if nWorkers == 0 {
|
2017-12-15 07:00:13 +00:00
|
|
|
return nil, errors.New("no worker found, rebuild the buildkit daemon?")
|
2017-11-21 08:08:36 +00:00
|
|
|
}
|
|
|
|
defaultWorker, err := wc.GetDefault()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2017-12-19 09:34:34 +00:00
|
|
|
logrus.Infof("found %d workers, default=%q", nWorkers, defaultWorker.ID())
|
2017-12-15 08:06:54 +00:00
|
|
|
logrus.Warn("currently, only the default worker can be used.")
|
2017-11-21 08:08:36 +00:00
|
|
|
return wc, nil
|
|
|
|
}
|
2017-12-19 09:34:34 +00:00
|
|
|
|
|
|
|
func attrMap(sl []string) (map[string]string, error) {
|
|
|
|
m := map[string]string{}
|
|
|
|
for _, v := range sl {
|
|
|
|
parts := strings.SplitN(v, "=", 2)
|
|
|
|
if len(parts) != 2 {
|
|
|
|
return nil, errors.Errorf("invalid value %s", v)
|
|
|
|
}
|
|
|
|
m[parts[0]] = parts[1]
|
|
|
|
}
|
|
|
|
return m, nil
|
|
|
|
}
|
2018-06-24 05:59:17 +00:00
|
|
|
|
|
|
|
func formatPlatforms(p []specs.Platform) []string {
|
|
|
|
str := make([]string, 0, len(p))
|
|
|
|
for _, pp := range p {
|
|
|
|
str = append(str, platforms.Format(platforms.Normalize(pp)))
|
|
|
|
}
|
|
|
|
return str
|
|
|
|
}
|
2018-07-16 17:05:05 +00:00
|
|
|
|
|
|
|
func parsePlatforms(platformsStr []string) ([]specs.Platform, error) {
|
|
|
|
out := make([]specs.Platform, 0, len(platformsStr))
|
|
|
|
for _, s := range platformsStr {
|
|
|
|
p, err := platforms.Parse(s)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
out = append(out, platforms.Normalize(p))
|
|
|
|
}
|
|
|
|
return out, nil
|
|
|
|
}
|