|
|
@ -39,6 +39,7 @@ import (
|
|
|
|
gateway "github.com/moby/buildkit/frontend/gateway/client"
|
|
|
|
gateway "github.com/moby/buildkit/frontend/gateway/client"
|
|
|
|
"github.com/moby/buildkit/session"
|
|
|
|
"github.com/moby/buildkit/session"
|
|
|
|
"github.com/moby/buildkit/session/upload/uploadprovider"
|
|
|
|
"github.com/moby/buildkit/session/upload/uploadprovider"
|
|
|
|
|
|
|
|
"github.com/moby/buildkit/solver/errdefs"
|
|
|
|
"github.com/moby/buildkit/solver/pb"
|
|
|
|
"github.com/moby/buildkit/solver/pb"
|
|
|
|
"github.com/moby/buildkit/util/apicaps"
|
|
|
|
"github.com/moby/buildkit/util/apicaps"
|
|
|
|
"github.com/moby/buildkit/util/entitlements"
|
|
|
|
"github.com/moby/buildkit/util/entitlements"
|
|
|
@ -57,6 +58,10 @@ var (
|
|
|
|
errDockerfileConflict = errors.New("ambiguous Dockerfile source: both stdin and flag correspond to Dockerfiles")
|
|
|
|
errDockerfileConflict = errors.New("ambiguous Dockerfile source: both stdin and flag correspond to Dockerfiles")
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const (
|
|
|
|
|
|
|
|
printFallbackImage = "docker/dockerfile-upstream:1.4-outline@sha256:ccd574ab34a8875c64bb6a8fb3cfae2e6d62d31b28b9f688075cc14c9b669a59"
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
type Options struct {
|
|
|
|
type Options struct {
|
|
|
|
Inputs Inputs
|
|
|
|
Inputs Inputs
|
|
|
|
|
|
|
|
|
|
|
@ -731,7 +736,7 @@ func BuildWithResultHandler(ctx context.Context, drivers []DriverInfo, opt map[s
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if noMobyDriver != nil && !noDefaultLoad() {
|
|
|
|
if noMobyDriver != nil && !noDefaultLoad() && noPrintFunc(opt) {
|
|
|
|
var noOutputTargets []string
|
|
|
|
var noOutputTargets []string
|
|
|
|
for name, opt := range opt {
|
|
|
|
for name, opt := range opt {
|
|
|
|
if !opt.Linked && len(opt.Exports) == 0 {
|
|
|
|
if !opt.Linked && len(opt.Exports) == 0 {
|
|
|
@ -1042,32 +1047,63 @@ func BuildWithResultHandler(ctx context.Context, drivers []DriverInfo, 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) {
|
|
|
|
if opt.PrintFunc != "" {
|
|
|
|
var isFallback bool
|
|
|
|
if _, ok := req.FrontendOpt["frontend.caps"]; !ok {
|
|
|
|
var origErr error
|
|
|
|
req.FrontendOpt["frontend.caps"] = "moby.buildkit.frontend.subrequests+forward"
|
|
|
|
for {
|
|
|
|
} else {
|
|
|
|
if opt.PrintFunc != "" {
|
|
|
|
req.FrontendOpt["frontend.caps"] += ",moby.buildkit.frontend.subrequests+forward"
|
|
|
|
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"] = printFallbackImage
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
req.FrontendOpt["requestid"] = "frontend." + opt.PrintFunc
|
|
|
|
res, err := c.Solve(ctx, req)
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
res, err := c.Solve(ctx, req)
|
|
|
|
if origErr != nil {
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var reqErr *errdefs.UnsupportedSubrequestError
|
|
|
|
if opt.PrintFunc != "" {
|
|
|
|
if !isFallback {
|
|
|
|
printRes = res.Metadata
|
|
|
|
if errors.As(err, &reqErr) {
|
|
|
|
}
|
|
|
|
switch reqErr.Name {
|
|
|
|
results.Set(resultKey(dp.driverIndex, k), res)
|
|
|
|
case "frontend.outline", "frontend.targets":
|
|
|
|
if resultHandleFunc != nil {
|
|
|
|
isFallback = true
|
|
|
|
resultHandleFunc(dp.driverIndex, &ResultContext{cc, res})
|
|
|
|
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)
|
|
|
|
|
|
|
|
if resultHandleFunc != nil {
|
|
|
|
|
|
|
|
resultHandleFunc(dp.driverIndex, &ResultContext{cc, res})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return res, nil
|
|
|
|
|
|
|
|
}, ch)
|
|
|
|
}, ch)
|
|
|
|
if err != nil {
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
res[i] = rr
|
|
|
|
res[i] = rr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if rr.ExporterResponse == nil {
|
|
|
|
|
|
|
|
rr.ExporterResponse = map[string]string{}
|
|
|
|
|
|
|
|
}
|
|
|
|
for k, v := range printRes {
|
|
|
|
for k, v := range printRes {
|
|
|
|
rr.ExporterResponse[k] = string(v)
|
|
|
|
rr.ExporterResponse[k] = string(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -1647,3 +1683,12 @@ func tryNodeIdentifier(configDir string) (out string) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func noPrintFunc(opt map[string]Options) bool {
|
|
|
|
|
|
|
|
for _, v := range opt {
|
|
|
|
|
|
|
|
if v.PrintFunc != "" {
|
|
|
|
|
|
|
|
return false
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
}
|
|
|
|