diff --git a/cmd/buildkitd/main.go b/cmd/buildkitd/main.go index 0284973f..9ccf5b81 100644 --- a/cmd/buildkitd/main.go +++ b/cmd/buildkitd/main.go @@ -21,8 +21,9 @@ import ( registryremotecache "github.com/moby/buildkit/cache/remotecache/registry" "github.com/moby/buildkit/control" "github.com/moby/buildkit/frontend" - "github.com/moby/buildkit/frontend/dockerfile" + "github.com/moby/buildkit/frontend/dockerfile/builder" "github.com/moby/buildkit/frontend/gateway" + "github.com/moby/buildkit/frontend/gateway/forwarder" "github.com/moby/buildkit/session" "github.com/moby/buildkit/solver/boltdbcachestorage" "github.com/moby/buildkit/util/apicaps" @@ -383,7 +384,7 @@ func newController(c *cli.Context, root string) (*control.Controller, error) { return nil, err } frontends := map[string]frontend.Frontend{} - frontends["dockerfile.v0"] = dockerfile.NewDockerfileFrontend(wc) + frontends["dockerfile.v0"] = forwarder.NewGatewayForwarder(wc, builder.Build2) frontends["gateway.v0"] = gateway.NewGatewayFrontend(wc) cacheStorage, err := boltdbcachestorage.NewStore(filepath.Join(root, "cache.db")) diff --git a/frontend/dockerfile/builder/build.go b/frontend/dockerfile/builder/build.go index c5354c30..a2887553 100644 --- a/frontend/dockerfile/builder/build.go +++ b/frontend/dockerfile/builder/build.go @@ -36,6 +36,10 @@ const ( var httpPrefix = regexp.MustCompile("^https?://") var gitUrlPathWithFragmentSuffix = regexp.MustCompile("\\.git(?:#.+)?$") +func Build2(ctx context.Context, c client.Client) (*client.Result, error) { + return nil, errors.Errorf("not-implemented") +} + func Build(ctx context.Context, c client.Client) error { opts := c.BuildOpts().Opts diff --git a/frontend/dockerfile/dockerfile.go b/frontend/dockerfile/dockerfile.go index b1433fc1..a529f585 100644 --- a/frontend/dockerfile/dockerfile.go +++ b/frontend/dockerfile/dockerfile.go @@ -1,45 +1 @@ package dockerfile - -import ( - "context" - - "github.com/moby/buildkit/frontend" - "github.com/moby/buildkit/frontend/dockerfile/builder" - "github.com/moby/buildkit/solver" -) - -func NewDockerfileFrontend(w frontend.WorkerInfos) frontend.Frontend { - return &dfFrontend{ - workers: w, - } -} - -type dfFrontend struct { - workers frontend.WorkerInfos -} - -func (f *dfFrontend) Solve(ctx context.Context, llbBridge frontend.FrontendLLBBridge, opts map[string]string) (retRef solver.CachedResult, exporterAttr map[string][]byte, retErr error) { - - c, err := llbBridgeToGatewayClient(ctx, llbBridge, opts, f.workers.WorkerInfos()) - if err != nil { - return nil, nil, err - } - - defer func() { - for _, r := range c.refs { - if r != nil && (c.final != r || retErr != nil) { - r.Release(context.TODO()) - } - } - }() - - if err := builder.Build(ctx, c); err != nil { - return nil, nil, err - } - - if c.final == nil || c.final.CachedResult == nil { - return nil, c.exporterAttr, nil - } - - return c.final, c.exporterAttr, nil -} diff --git a/frontend/dockerfile/forward.go b/frontend/gateway/forwarder/forward.go similarity index 99% rename from frontend/dockerfile/forward.go rename to frontend/gateway/forwarder/forward.go index 257143cf..9eaf6a16 100644 --- a/frontend/dockerfile/forward.go +++ b/frontend/gateway/forwarder/forward.go @@ -1,4 +1,4 @@ -package dockerfile +package forwarder import ( "context" diff --git a/frontend/gateway/forwarder/frontend.go b/frontend/gateway/forwarder/frontend.go new file mode 100644 index 00000000..213d2853 --- /dev/null +++ b/frontend/gateway/forwarder/frontend.go @@ -0,0 +1,47 @@ +package forwarder + +import ( + "context" + + "github.com/moby/buildkit/frontend" + "github.com/moby/buildkit/frontend/dockerfile/builder" + "github.com/moby/buildkit/frontend/gateway/client" + "github.com/moby/buildkit/solver" +) + +func NewGatewayForwarder(w frontend.WorkerInfos, f client.BuildFunc) frontend.Frontend { + return &GatewayForwarder{ + workers: w, + f: f, + } +} + +type GatewayForwarder struct { + workers frontend.WorkerInfos + f client.BuildFunc +} + +func (gf *GatewayForwarder) Solve(ctx context.Context, llbBridge frontend.FrontendLLBBridge, opts map[string]string) (retRef solver.CachedResult, exporterAttr map[string][]byte, retErr error) { + c, err := llbBridgeToGatewayClient(ctx, llbBridge, opts, gf.workers.WorkerInfos()) + if err != nil { + return nil, nil, err + } + + defer func() { + for _, r := range c.refs { + if r != nil && (c.final != r || retErr != nil) { + r.Release(context.TODO()) + } + } + }() + + if err := builder.Build(ctx, c); err != nil { + return nil, nil, err + } + + if c.final == nil || c.final.CachedResult == nil { + return nil, c.exporterAttr, nil + } + + return c.final, c.exporterAttr, nil +}