vendor: update buildkit to 0e3037c0182e

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
This commit is contained in:
Tonis Tiigi
2025-02-10 16:48:59 -08:00
parent c8c9c72ca6
commit f11496448a
49 changed files with 2005 additions and 1377 deletions

View File

@ -18,7 +18,6 @@ import (
"github.com/moby/buildkit/frontend/gateway/client"
"github.com/moby/buildkit/solver/pb"
"github.com/moby/buildkit/util/flightcontrol"
dockerspec "github.com/moby/docker-image-spec/specs-go/v1"
"github.com/moby/patternmatcher/ignorefile"
digest "github.com/opencontainers/go-digest"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
@ -452,10 +451,10 @@ func (bc *Client) MainContext(ctx context.Context, opts ...llb.LocalOption) (*ll
return &st, nil
}
func (bc *Client) NamedContext(ctx context.Context, name string, opt ContextOpt) (*llb.State, *dockerspec.DockerOCIImage, error) {
func (bc *Client) NamedContext(name string, opt ContextOpt) (*NamedContext, error) {
named, err := reference.ParseNormalizedNamed(name)
if err != nil {
return nil, nil, errors.Wrapf(err, "invalid context name %s", name)
return nil, errors.Wrapf(err, "invalid context name %s", name)
}
name = strings.TrimSuffix(reference.FamiliarString(named), ":latest")
@ -464,11 +463,11 @@ func (bc *Client) NamedContext(ctx context.Context, name string, opt ContextOpt)
pp = *opt.Platform
}
pname := name + "::" + platforms.FormatAll(platforms.Normalize(pp))
st, img, err := bc.namedContext(ctx, name, pname, opt)
if err != nil || st != nil {
return st, img, err
nc, err := bc.namedContext(name, pname, opt)
if err != nil || nc != nil {
return nc, err
}
return bc.namedContext(ctx, name, name, opt)
return bc.namedContext(name, name, opt)
}
func (bc *Client) IsNoCache(name string) bool {

View File

@ -26,31 +26,51 @@ const (
maxContextRecursion = 10
)
func (bc *Client) namedContext(ctx context.Context, name string, nameWithPlatform string, opt ContextOpt) (*llb.State, *dockerspec.DockerOCIImage, error) {
return bc.namedContextRecursive(ctx, name, nameWithPlatform, opt, 0)
type NamedContext struct {
input string
bc *Client
name string
nameWithPlatform string
opt ContextOpt
}
func (bc *Client) namedContextRecursive(ctx context.Context, name string, nameWithPlatform string, opt ContextOpt, count int) (*llb.State, *dockerspec.DockerOCIImage, error) {
func (bc *Client) namedContext(name string, nameWithPlatform string, opt ContextOpt) (*NamedContext, error) {
opts := bc.bopts.Opts
contextKey := contextPrefix + nameWithPlatform
v, ok := opts[contextKey]
if !ok {
return nil, nil, nil
return nil, nil
}
return &NamedContext{
input: v,
bc: bc,
name: name,
nameWithPlatform: nameWithPlatform,
opt: opt,
}, nil
}
func (nc *NamedContext) Load(ctx context.Context) (*llb.State, *dockerspec.DockerOCIImage, error) {
return nc.load(ctx, 0)
}
func (nc *NamedContext) load(ctx context.Context, count int) (*llb.State, *dockerspec.DockerOCIImage, error) {
opt := nc.opt
if count > maxContextRecursion {
return nil, nil, errors.New("context recursion limit exceeded; this may indicate a cycle in the provided source policies: " + v)
return nil, nil, errors.New("context recursion limit exceeded; this may indicate a cycle in the provided source policies: " + nc.input)
}
vv := strings.SplitN(v, ":", 2)
vv := strings.SplitN(nc.input, ":", 2)
if len(vv) != 2 {
return nil, nil, errors.Errorf("invalid context specifier %s for %s", v, nameWithPlatform)
return nil, nil, errors.Errorf("invalid context specifier %s for %s", nc.input, nc.nameWithPlatform)
}
// allow git@ without protocol for SSH URLs for backwards compatibility
if strings.HasPrefix(vv[0], "git@") {
vv[0] = "git"
}
switch vv[0] {
case "docker-image":
ref := strings.TrimPrefix(vv[1], "//")
@ -60,7 +80,7 @@ func (bc *Client) namedContextRecursive(ctx context.Context, name string, nameWi
}
imgOpt := []llb.ImageOption{
llb.WithCustomName("[context " + nameWithPlatform + "] " + ref),
llb.WithCustomName("[context " + nc.nameWithPlatform + "] " + ref),
}
if opt.Platform != nil {
imgOpt = append(imgOpt, llb.Platform(*opt.Platform))
@ -73,8 +93,8 @@ func (bc *Client) namedContextRecursive(ctx context.Context, name string, nameWi
named = reference.TagNameOnly(named)
ref, dgst, data, err := bc.client.ResolveImageConfig(ctx, named.String(), sourceresolver.Opt{
LogName: fmt.Sprintf("[context %s] load metadata for %s", nameWithPlatform, ref),
ref, dgst, data, err := nc.bc.client.ResolveImageConfig(ctx, named.String(), sourceresolver.Opt{
LogName: fmt.Sprintf("[context %s] load metadata for %s", nc.nameWithPlatform, ref),
Platform: opt.Platform,
ImageOpt: &sourceresolver.ResolveImageOpt{
ResolveMode: opt.ResolveMode,
@ -88,8 +108,16 @@ func (bc *Client) namedContextRecursive(ctx context.Context, name string, nameWi
return nil, nil, errors.Errorf("could not parse ref: %s", e.Updated)
}
bc.bopts.Opts[contextKey] = before + ":" + after
return bc.namedContextRecursive(ctx, name, nameWithPlatform, opt, count+1)
nc.bc.bopts.Opts[contextPrefix+nc.nameWithPlatform] = before + ":" + after
ncnew, err := nc.bc.namedContext(nc.name, nc.nameWithPlatform, nc.opt)
if err != nil {
return nil, nil, err
}
if ncnew == nil {
return nil, nil, nil
}
return ncnew.load(ctx, count+1)
}
return nil, nil, err
}
@ -110,15 +138,15 @@ func (bc *Client) namedContextRecursive(ctx context.Context, name string, nameWi
}
return &st, &img, nil
case "git":
st, ok := DetectGitContext(v, true)
st, ok := DetectGitContext(nc.input, true)
if !ok {
return nil, nil, errors.Errorf("invalid git context %s", v)
return nil, nil, errors.Errorf("invalid git context %s", nc.input)
}
return st, nil, nil
case "http", "https":
st, ok := DetectGitContext(v, true)
st, ok := DetectGitContext(nc.input, true)
if !ok {
httpst := llb.HTTP(v, llb.WithCustomName("[context "+nameWithPlatform+"] "+v))
httpst := llb.HTTP(nc.input, llb.WithCustomName("[context "+nc.nameWithPlatform+"] "+nc.input))
st = &httpst
}
return st, nil, nil
@ -139,21 +167,21 @@ func (bc *Client) namedContextRecursive(ctx context.Context, name string, nameWi
// for the dummy ref primarily used in log messages, we can use the
// original name, since the store key may not be significant
dummyRef, err := reference.ParseNormalizedNamed(name)
dummyRef, err := reference.ParseNormalizedNamed(nc.name)
if err != nil {
return nil, nil, errors.Wrapf(err, "could not parse oci-layout reference %q", name)
return nil, nil, errors.Wrapf(err, "could not parse oci-layout reference %q", nc.name)
}
dummyRef, err = reference.WithDigest(dummyRef, dgstd.Digest())
if err != nil {
return nil, nil, errors.Wrapf(err, "could not wrap %q with digest", name)
return nil, nil, errors.Wrapf(err, "could not wrap %q with digest", nc.name)
}
_, dgst, data, err := bc.client.ResolveImageConfig(ctx, dummyRef.String(), sourceresolver.Opt{
LogName: fmt.Sprintf("[context %s] load metadata for %s", nameWithPlatform, dummyRef.String()),
_, dgst, data, err := nc.bc.client.ResolveImageConfig(ctx, dummyRef.String(), sourceresolver.Opt{
LogName: fmt.Sprintf("[context %s] load metadata for %s", nc.nameWithPlatform, dummyRef.String()),
Platform: opt.Platform,
OCILayoutOpt: &sourceresolver.ResolveOCILayoutOpt{
Store: sourceresolver.ResolveImageConfigOptStore{
SessionID: bc.bopts.SessionID,
SessionID: nc.bc.bopts.SessionID,
StoreID: named.Name(),
},
},
@ -168,8 +196,8 @@ func (bc *Client) namedContextRecursive(ctx context.Context, name string, nameWi
}
ociOpt := []llb.OCILayoutOption{
llb.WithCustomName("[context " + nameWithPlatform + "] OCI load from client"),
llb.OCIStore(bc.bopts.SessionID, named.Name()),
llb.WithCustomName("[context " + nc.nameWithPlatform + "] OCI load from client"),
llb.OCIStore(nc.bc.bopts.SessionID, named.Name()),
}
if opt.Platform != nil {
ociOpt = append(ociOpt, llb.Platform(*opt.Platform))
@ -187,22 +215,22 @@ func (bc *Client) namedContextRecursive(ctx context.Context, name string, nameWi
}
return &st, &img, nil
case "local":
sessionID := bc.bopts.SessionID
if v, ok := bc.localsSessionIDs[vv[1]]; ok {
sessionID := nc.bc.bopts.SessionID
if v, ok := nc.bc.localsSessionIDs[vv[1]]; ok {
sessionID = v
}
st := llb.Local(vv[1],
llb.SessionID(sessionID),
llb.FollowPaths([]string{DefaultDockerignoreName}),
llb.SharedKeyHint("context:"+nameWithPlatform+"-"+DefaultDockerignoreName),
llb.WithCustomName("[context "+nameWithPlatform+"] load "+DefaultDockerignoreName),
llb.SharedKeyHint("context:"+nc.nameWithPlatform+"-"+DefaultDockerignoreName),
llb.WithCustomName("[context "+nc.nameWithPlatform+"] load "+DefaultDockerignoreName),
llb.Differ(llb.DiffNone, false),
)
def, err := st.Marshal(ctx)
if err != nil {
return nil, nil, err
}
res, err := bc.client.Solve(ctx, client.SolveRequest{
res, err := nc.bc.client.Solve(ctx, client.SolveRequest{
Evaluate: true,
Definition: def.ToPB(),
})
@ -229,7 +257,7 @@ func (bc *Client) namedContextRecursive(ctx context.Context, name string, nameWi
localOutput := &asyncLocalOutput{
name: vv[1],
nameWithPlatform: nameWithPlatform,
nameWithPlatform: nc.nameWithPlatform,
sessionID: sessionID,
excludes: excludes,
extraOpts: opt.AsyncLocalOpts,
@ -237,15 +265,15 @@ func (bc *Client) namedContextRecursive(ctx context.Context, name string, nameWi
st = llb.NewState(localOutput)
return &st, nil, nil
case "input":
inputs, err := bc.client.Inputs(ctx)
inputs, err := nc.bc.client.Inputs(ctx)
if err != nil {
return nil, nil, err
}
st, ok := inputs[vv[1]]
if !ok {
return nil, nil, errors.Errorf("invalid input %s for %s", vv[1], nameWithPlatform)
return nil, nil, errors.Errorf("invalid input %s for %s", vv[1], nc.nameWithPlatform)
}
md, ok := opts[inputMetadataPrefix+vv[1]]
md, ok := nc.bc.bopts.Opts[inputMetadataPrefix+vv[1]]
if ok {
m := make(map[string][]byte)
if err := json.Unmarshal([]byte(md), &m); err != nil {
@ -258,14 +286,14 @@ func (bc *Client) namedContextRecursive(ctx context.Context, name string, nameWi
return nil, nil, err
}
if err := json.Unmarshal(dtic, &img); err != nil {
return nil, nil, errors.Wrapf(err, "failed to parse image config for %s", nameWithPlatform)
return nil, nil, errors.Wrapf(err, "failed to parse image config for %s", nc.nameWithPlatform)
}
}
return &st, img, nil
}
return &st, nil, nil
default:
return nil, nil, errors.Errorf("unsupported context source %s for %s", vv[0], nameWithPlatform)
return nil, nil, errors.Errorf("unsupported context source %s for %s", vv[0], nc.nameWithPlatform)
}
}