Skip to content

Commit

Permalink
build: add fallback to outline requests if not supported by frontend
Browse files Browse the repository at this point in the history
Signed-off-by: Tonis Tiigi <[email protected]>
  • Loading branch information
tonistiigi committed May 7, 2022
1 parent b9995f5 commit 60c543a
Showing 1 changed file with 57 additions and 16 deletions.
73 changes: 57 additions & 16 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
gateway "github.com/moby/buildkit/frontend/gateway/client"
"github.com/moby/buildkit/session"
"github.com/moby/buildkit/session/upload/uploadprovider"
"github.com/moby/buildkit/solver/errdefs"
"github.com/moby/buildkit/solver/pb"
"github.com/moby/buildkit/util/apicaps"
"github.com/moby/buildkit/util/entitlements"
Expand Down Expand Up @@ -631,7 +632,7 @@ func Build(ctx context.Context, drivers []DriverInfo, opt map[string]Options, do
}
}

if noMobyDriver != nil && !noDefaultLoad() {
if noMobyDriver != nil && !noDefaultLoad() && noPrintFunc(opt) {
for _, opt := range opt {
if len(opt.Exports) == 0 {
logrus.Warnf("No output specified for %s driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load", noMobyDriver.Factory().Name())
Expand Down Expand Up @@ -918,29 +919,60 @@ func Build(ctx context.Context, drivers []DriverInfo, opt map[string]Options, do
var printRes map[string][]byte

rr, err := c.Build(ctx, so, "buildx", func(ctx context.Context, c gateway.Client) (*gateway.Result, error) {
if opt.PrintFunc != "" {
if _, ok := req.FrontendOpt["frontend.caps"]; !ok {
req.FrontendOpt["frontend.caps"] = "moby.buildkit.frontend.subrequests+forward"
} else {
req.FrontendOpt["frontend.caps"] += ",moby.buildkit.frontend.subrequests+forward"
var isFallback bool
var origErr error
for {
if opt.PrintFunc != "" {
if _, ok := req.FrontendOpt["frontend.caps"]; !ok {
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
if isFallback {
req.FrontendOpt["build-arg:BUILDKIT_SYNTAX"] = "docker/dockerfile-upstream:1.4-outline"
}
}
req.FrontendOpt["requestid"] = "frontend." + opt.PrintFunc
}
res, err := c.Solve(ctx, req)
if err != nil {
return nil, err
}
if opt.PrintFunc != "" {
printRes = res.Metadata
res, err := c.Solve(ctx, req)
if err != nil {
if origErr != nil {
return nil, err
}
var reqErr *errdefs.UnsupportedSubrequestError
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
}
if opt.PrintFunc != "" {
printRes = res.Metadata
}
results.Set(resultKey(dp.driverIndex, k), res)
return res, nil
}
results.Set(resultKey(dp.driverIndex, k), res)
return res, nil
}, ch)
if err != nil {
return err
}
res[i] = rr

if rr.ExporterResponse == nil {
rr.ExporterResponse = map[string]string{}
}
for k, v := range printRes {
rr.ExporterResponse[k] = string(v)
}
Expand Down Expand Up @@ -1494,3 +1526,12 @@ func tryNodeIdentifier(configDir string) (out string) {
}
return
}

func noPrintFunc(opt map[string]Options) bool {
for _, v := range opt {
if v.PrintFunc != "" {
return false
}
}
return true
}

0 comments on commit 60c543a

Please sign in to comment.