frontend: move forwarder under gateway

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
docker-18.09
Tonis Tiigi 2018-07-05 14:31:50 -07:00
parent d9f1a1d99f
commit 9684362cb0
5 changed files with 55 additions and 47 deletions

View File

@ -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"))

View File

@ -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

View File

@ -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
}

View File

@ -1,4 +1,4 @@
package dockerfile
package forwarder
import (
"context"

View File

@ -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
}