mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-29 08:57:44 +08:00
build: tidy up print func
Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
parent
341fb65f6f
commit
91c17f25fb
@ -886,59 +886,60 @@ 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
|
if opt.PrintFunc != nil {
|
||||||
var origErr error
|
if _, ok := req.FrontendOpt["frontend.caps"]; !ok {
|
||||||
for {
|
req.FrontendOpt["frontend.caps"] = "moby.buildkit.frontend.subrequests+forward"
|
||||||
if opt.PrintFunc != nil {
|
} else {
|
||||||
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"
|
|
||||||
} else {
|
|
||||||
req.FrontendOpt["frontend.caps"] += ",moby.buildkit.frontend.subrequests+forward"
|
|
||||||
}
|
|
||||||
req.FrontendOpt["requestid"] = "frontend." + opt.PrintFunc.Name
|
|
||||||
if isFallback {
|
|
||||||
req.FrontendOpt["build-arg:BUILDKIT_SYNTAX"] = printFallbackImage
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
res, err := c.Solve(ctx, req)
|
req.FrontendOpt["requestid"] = "frontend." + opt.PrintFunc.Name
|
||||||
if err != nil {
|
}
|
||||||
if origErr != nil {
|
|
||||||
|
res, err := c.Solve(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
fallback := false
|
||||||
|
var reqErr *errdefs.UnsupportedSubrequestError
|
||||||
|
if errors.As(err, &reqErr) {
|
||||||
|
switch reqErr.Name {
|
||||||
|
case "frontend.outline", "frontend.targets":
|
||||||
|
fallback = true
|
||||||
|
default:
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var reqErr *errdefs.UnsupportedSubrequestError
|
} else {
|
||||||
if !isFallback {
|
|
||||||
if errors.As(err, &reqErr) {
|
|
||||||
switch reqErr.Name {
|
|
||||||
case "frontend.outline", "frontend.targets":
|
|
||||||
isFallback = true
|
|
||||||
origErr = err
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
// 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") {
|
|
||||||
isFallback = true
|
|
||||||
origErr = err
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if opt.PrintFunc != nil {
|
// buildkit v0.8 vendored in Docker 20.10 does not support typed errors
|
||||||
printRes = res.Metadata
|
if strings.Contains(err.Error(), "unsupported request frontend.outline") || strings.Contains(err.Error(), "unsupported request frontend.targets") {
|
||||||
|
fallback = true
|
||||||
}
|
}
|
||||||
results.Set(resultKey(dp.driverIndex, k), res)
|
|
||||||
if resultHandleFunc != nil {
|
if fallback {
|
||||||
resultCtx, err := NewResultContext(ctx, cc, so, res)
|
fmt.Println("falling back!")
|
||||||
if err == nil {
|
req.FrontendOpt["build-arg:BUILDKIT_SYNTAX"] = printFallbackImage
|
||||||
resultHandleFunc(dp.driverIndex, resultCtx)
|
res2, err2 := c.Solve(ctx, req)
|
||||||
} else {
|
if err2 != nil {
|
||||||
logrus.Warnf("failed to record result: %s", err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
res = res2
|
||||||
|
} else {
|
||||||
|
return nil, err
|
||||||
}
|
}
|
||||||
return res, nil
|
|
||||||
}
|
}
|
||||||
|
if opt.PrintFunc != nil {
|
||||||
|
printRes = res.Metadata
|
||||||
|
}
|
||||||
|
|
||||||
|
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)
|
}, ch)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
Loading…
x
Reference in New Issue
Block a user