build: tidy up print func

Signed-off-by: Justin Chadwell <me@jedevc.com>
pull/1804/head
Justin Chadwell 2 years ago
parent 341fb65f6f
commit 91c17f25fb

@ -886,9 +886,6 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
cc := c cc := c
var printRes map[string][]byte var printRes map[string][]byte
rr, err := c.Build(ctx, so, "buildx", func(ctx context.Context, c gateway.Client) (*gateway.Result, error) { rr, err := c.Build(ctx, so, "buildx", func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
var isFallback bool
var origErr error
for {
if opt.PrintFunc != nil { if opt.PrintFunc != nil {
if _, ok := req.FrontendOpt["frontend.caps"]; !ok { if _, ok := req.FrontendOpt["frontend.caps"]; !ok {
req.FrontendOpt["frontend.caps"] = "moby.buildkit.frontend.subrequests+forward" req.FrontendOpt["frontend.caps"] = "moby.buildkit.frontend.subrequests+forward"
@ -896,38 +893,43 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
req.FrontendOpt["frontend.caps"] += ",moby.buildkit.frontend.subrequests+forward" req.FrontendOpt["frontend.caps"] += ",moby.buildkit.frontend.subrequests+forward"
} }
req.FrontendOpt["requestid"] = "frontend." + opt.PrintFunc.Name req.FrontendOpt["requestid"] = "frontend." + opt.PrintFunc.Name
if isFallback {
req.FrontendOpt["build-arg:BUILDKIT_SYNTAX"] = printFallbackImage
}
} }
res, err := c.Solve(ctx, req) res, err := c.Solve(ctx, req)
if err != nil { if err != nil {
if origErr != nil { fallback := false
return nil, err
}
var reqErr *errdefs.UnsupportedSubrequestError var reqErr *errdefs.UnsupportedSubrequestError
if !isFallback {
if errors.As(err, &reqErr) { if errors.As(err, &reqErr) {
switch reqErr.Name { switch reqErr.Name {
case "frontend.outline", "frontend.targets": case "frontend.outline", "frontend.targets":
isFallback = true fallback = true
origErr = err default:
continue return nil, err
} }
} else {
return nil, err return nil, err
} }
// buildkit v0.8 vendored in Docker 20.10 does not support typed errors // buildkit v0.8 vendored in Docker 20.10 does not support typed errors
if strings.Contains(err.Error(), "unsupported request frontend.outline") || strings.Contains(err.Error(), "unsupported request frontend.targets") { if strings.Contains(err.Error(), "unsupported request frontend.outline") || strings.Contains(err.Error(), "unsupported request frontend.targets") {
isFallback = true fallback = true
origErr = err
continue
} }
if fallback {
fmt.Println("falling back!")
req.FrontendOpt["build-arg:BUILDKIT_SYNTAX"] = printFallbackImage
res2, err2 := c.Solve(ctx, req)
if err2 != nil {
return nil, err
} }
res = res2
} else {
return nil, err return nil, err
} }
}
if opt.PrintFunc != nil { if opt.PrintFunc != nil {
printRes = res.Metadata printRes = res.Metadata
} }
results.Set(resultKey(dp.driverIndex, k), res) results.Set(resultKey(dp.driverIndex, k), res)
if resultHandleFunc != nil { if resultHandleFunc != nil {
resultCtx, err := NewResultContext(ctx, cc, so, res) resultCtx, err := NewResultContext(ctx, cc, so, res)
@ -938,7 +940,6 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
} }
} }
return res, nil return res, nil
}
}, ch) }, ch)
if err != nil { if err != nil {
return err return err

Loading…
Cancel
Save