diff --git a/client/build.go b/client/build.go index f91b543a779b..25b3aa6d7ccf 100644 --- a/client/build.go +++ b/client/build.go @@ -44,7 +44,13 @@ func (c *Client) Build(ctx context.Context, opt SolveOpt, product string, buildF }) } - cb := func(ref string, s *session.Session) error { + cb := func(ref string, s *session.Session, opts map[string]string) error { + for k, v := range opts { + if feOpts == nil { + feOpts = map[string]string{} + } + feOpts[k] = v + } gwClient := c.gatewayClientForBuild(ref) g, err := grpcclient.New(ctx, feOpts, s.ID(), product, gwClient, gworkers) if err != nil { diff --git a/client/solve.go b/client/solve.go index 40a12c7a89de..f14d9c410d79 100644 --- a/client/solve.go +++ b/client/solve.go @@ -75,7 +75,7 @@ func (c *Client) Solve(ctx context.Context, def *llb.Definition, opt SolveOpt, s return c.solve(ctx, def, nil, opt, statusChan) } -type runGatewayCB func(ref string, s *session.Session) error +type runGatewayCB func(ref string, s *session.Session, opts map[string]string) error func (c *Client) solve(ctx context.Context, def *llb.Definition, runGateway runGatewayCB, opt SolveOpt, statusChan chan *SolveStatus) (*SolveResponse, error) { if def != nil && runGateway != nil { @@ -109,7 +109,7 @@ func (c *Client) solve(ctx context.Context, def *llb.Definition, runGateway runG } } - cacheOpt, err := parseCacheOptions(ctx, opt) + cacheOpt, err := parseCacheOptions(ctx, runGateway != nil, opt) if err != nil { return nil, err } @@ -171,6 +171,9 @@ func (c *Client) solve(ctx context.Context, def *llb.Definition, runGateway runG } for k, v := range cacheOpt.frontendAttrs { + if opt.FrontendAttrs == nil { + opt.FrontendAttrs = map[string]string{} + } opt.FrontendAttrs[k] = v } @@ -225,7 +228,7 @@ func (c *Client) solve(ctx context.Context, def *llb.Definition, runGateway runG if runGateway != nil { eg.Go(func() error { - err := runGateway(ref, s) + err := runGateway(ref, s, opt.FrontendAttrs) if err == nil { return nil } @@ -386,7 +389,7 @@ type cacheOptions struct { frontendAttrs map[string]string } -func parseCacheOptions(ctx context.Context, opt SolveOpt) (*cacheOptions, error) { +func parseCacheOptions(ctx context.Context, isGateway bool, opt SolveOpt) (*cacheOptions, error) { var ( cacheExports []*controlapi.CacheOptionsEntry cacheImports []*controlapi.CacheOptionsEntry @@ -471,7 +474,7 @@ func parseCacheOptions(ctx context.Context, opt SolveOpt) (*cacheOptions, error) }) } } - if opt.Frontend != "" { + if opt.Frontend != "" || isGateway { // use legacy API for registry importers, because the frontend might not support the new API if len(legacyImportRefs) > 0 { frontendAttrs["cache-from"] = strings.Join(legacyImportRefs, ",") diff --git a/frontend/gateway/grpcclient/client.go b/frontend/gateway/grpcclient/client.go index a7394891fb9e..d8e2799ff0dc 100644 --- a/frontend/gateway/grpcclient/client.go +++ b/frontend/gateway/grpcclient/client.go @@ -341,6 +341,24 @@ func (c *grpcClient) Solve(ctx context.Context, creq client.SolveRequest) (res * } } + // these options are added by go client in solve() + if _, ok := creq.FrontendOpt["cache-imports"]; !ok { + if v, ok := c.opts["cache-imports"]; ok { + if creq.FrontendOpt == nil { + creq.FrontendOpt = map[string]string{} + } + creq.FrontendOpt["cache-imports"] = v + } + } + if _, ok := creq.FrontendOpt["cache-from"]; !ok { + if v, ok := c.opts["cache-from"]; ok { + if creq.FrontendOpt == nil { + creq.FrontendOpt = map[string]string{} + } + creq.FrontendOpt["cache-from"] = v + } + } + req := &pb.SolveRequest{ Definition: creq.Definition, Frontend: creq.Frontend,