Skip to content

Commit

Permalink
build: move main solve request into main gateway call
Browse files Browse the repository at this point in the history
Now, we always perform the full solve request in the main gateway call.
This ensures that progress works properly, and makes the lifetime
semantics much clearer.

NewResultContext abstracts the details of a successful/failed build, to
always return a single ResultContext, even though the details of how a
gateway is created is different:
- For a failed build, we can just keep the gateway open.
- For a successful build, we immediately open another gateway and
  re-evaluate the build definition in that gateway. This should give an
  instant cache hit (since the build was just successful).

Signed-off-by: Justin Chadwell <me@jedevc.com>
  • Loading branch information
jedevc committed May 17, 2023
1 parent 1a87b52 commit c030a70
Show file tree
Hide file tree
Showing 2 changed files with 221 additions and 131 deletions.
22 changes: 11 additions & 11 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -882,10 +882,11 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s

ch, done := progress.NewChannel(pw)
defer func() { <-done }()
_ = done

cc := c
var printRes map[string][]byte
rr, err := c.Build(ctx, so, "buildx", func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
buildFunc := func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
if opt.PrintFunc != nil {
if _, ok := req.FrontendOpt["frontend.caps"]; !ok {
req.FrontendOpt["frontend.caps"] = "moby.buildkit.frontend.subrequests+forward"
Expand Down Expand Up @@ -915,7 +916,6 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
}

if fallback {
fmt.Println("falling back!")
req.FrontendOpt["build-arg:BUILDKIT_SYNTAX"] = printFallbackImage
res2, err2 := c.Solve(ctx, req)
if err2 != nil {
Expand All @@ -931,16 +931,16 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
}

results.Set(resultKey(dp.driverIndex, k), res)
if resultHandleFunc != nil {
resultCtx, err := NewResultContext(ctx, cc, so, res)
if err == nil {
resultHandleFunc(dp.driverIndex, resultCtx)
} else {
logrus.Warnf("failed to record result: %s", err)
}
}
return res, nil
}, ch)
}
var rr *client.SolveResponse
if resultHandleFunc != nil {
var resultCtx *ResultContext
resultCtx, rr, err = NewResultContext(ctx, cc, so, "buildx", buildFunc, ch)
resultHandleFunc(dp.driverIndex, resultCtx)
} else {
rr, err = c.Build(ctx, so, "buildx", buildFunc, ch)
}
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit c030a70

Please sign in to comment.