vendor: github.com/moby/buildkit v0.21.0-rc1

Signed-off-by: Jonathan A. Sternberg <jonathan.sternberg@docker.com>
This commit is contained in:
Jonathan A. Sternberg
2025-04-09 10:28:03 -05:00
parent a34cdff84e
commit 8fb1157b5f
221 changed files with 6530 additions and 3986 deletions

View File

@ -148,14 +148,16 @@ func parseDirective(key string, dt []byte, anyFormat bool) (string, string, []Ra
}
// use json directive, and search for { "key": "..." }
jsonDirective := map[string]string{}
jsonDirective := map[string]any{}
if err := json.Unmarshal(dt, &jsonDirective); err == nil {
if v, ok := jsonDirective[key]; ok {
loc := []Range{{
Start: Position{Line: line},
End: Position{Line: line},
}}
return v, v, loc, true
if vAny, ok := jsonDirective[key]; ok {
if v, ok := vAny.(string); ok {
loc := []Range{{
Start: Position{Line: line},
End: Position{Line: line},
}}
return v, v, loc, true
}
}
}

View File

@ -281,7 +281,7 @@ func parseJSON(rest string) (*Node, map[string]bool, error) {
return nil, nil, errDockerfileNotJSONArray
}
var myJSON []interface{}
var myJSON []any
if err := json.Unmarshal([]byte(rest), &myJSON); err != nil {
return nil, nil, err
}

View File

@ -220,7 +220,7 @@ func init() {
// based on the command and command arguments. A Node is created from the
// result of the dispatch.
func newNodeFromLine(line string, d *directives, comments []string) (*Node, error) {
cmd, flags, args, err := splitCommand(line)
cmd, flags, args, err := splitCommand(line, d)
if err != nil {
return nil, err
}

View File

@ -7,7 +7,7 @@ import (
// splitCommand takes a single line of text and parses out the cmd and args,
// which are used for dispatching to more exact parsing functions.
func splitCommand(line string) (string, []string, string, error) {
func splitCommand(line string, d *directives) (string, []string, string, error) {
var args string
var flags []string
@ -16,7 +16,7 @@ func splitCommand(line string) (string, []string, string, error) {
if len(cmdline) == 2 {
var err error
args, flags, err = extractBuilderFlags(cmdline[1])
args, flags, err = extractBuilderFlags(cmdline[1], d)
if err != nil {
return "", nil, "", err
}
@ -25,7 +25,7 @@ func splitCommand(line string) (string, []string, string, error) {
return cmdline[0], flags, strings.TrimSpace(args), nil
}
func extractBuilderFlags(line string) (string, []string, error) {
func extractBuilderFlags(line string, d *directives) (string, []string, error) {
// Parses the BuilderFlags and returns the remaining part of the line
const (
@ -87,7 +87,7 @@ func extractBuilderFlags(line string) (string, []string, error) {
phase = inQuote
continue
}
if ch == '\\' {
if ch == d.escapeToken {
if pos+1 == len(line) {
continue // just skip \ at end
}
@ -104,7 +104,7 @@ func extractBuilderFlags(line string) (string, []string, error) {
phase = inWord
continue
}
if ch == '\\' {
if ch == d.escapeToken {
if pos+1 == len(line) {
phase = inWord
continue // just skip \ at end

View File

@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"slices"
"github.com/containerd/platforms"
"github.com/moby/buildkit/exporter/containerimage/exptypes"
@ -54,23 +55,16 @@ func (bc *Client) Build(ctx context.Context, fn BuildFunc) (*ResultBuilder, erro
}
}
p := platforms.DefaultSpec()
var p ocispecs.Platform
if tp != nil {
p = *tp
} else {
p = platforms.DefaultSpec()
}
// in certain conditions we allow input platform to be extended from base image
if p.OS == "windows" && img.OS == p.OS {
if p.OSVersion == "" && img.OSVersion != "" {
p.OSVersion = img.OSVersion
}
if p.OSFeatures == nil && len(img.OSFeatures) > 0 {
p.OSFeatures = append([]string{}, img.OSFeatures...)
}
}
p = platforms.Normalize(p)
k := platforms.FormatAll(p)
p = extendWindowsPlatform(p, img.Platform)
p = platforms.Normalize(p)
if bc.MultiPlatformRequested {
res.AddRef(k, ref)
@ -126,3 +120,16 @@ func (rb *ResultBuilder) EachPlatform(ctx context.Context, fn func(ctx context.C
}
return eg.Wait()
}
func extendWindowsPlatform(p, imgP ocispecs.Platform) ocispecs.Platform {
// in certain conditions we allow input platform to be extended from base image
if p.OS == "windows" && imgP.OS == p.OS {
if p.OSVersion == "" && imgP.OSVersion != "" {
p.OSVersion = imgP.OSVersion
}
if p.OSFeatures == nil && len(imgP.OSFeatures) > 0 {
p.OSFeatures = slices.Clone(imgP.OSFeatures)
}
}
return p
}

View File

@ -148,9 +148,11 @@ func (bc *Client) BuildOpts() client.BuildOpts {
func (bc *Client) init() error {
opts := bc.bopts.Opts
defaultBuildPlatform := platforms.Normalize(platforms.DefaultSpec())
var defaultBuildPlatform ocispecs.Platform
if workers := bc.bopts.Workers; len(workers) > 0 && len(workers[0].Platforms) > 0 {
defaultBuildPlatform = workers[0].Platforms[0]
} else {
defaultBuildPlatform = platforms.Normalize(platforms.DefaultSpec())
}
buildPlatforms := []ocispecs.Platform{defaultBuildPlatform}
targetPlatforms := []ocispecs.Platform{}
@ -459,9 +461,11 @@ func (bc *Client) NamedContext(name string, opt ContextOpt) (*NamedContext, erro
}
name = strings.TrimSuffix(reference.FamiliarString(named), ":latest")
pp := platforms.DefaultSpec()
var pp ocispecs.Platform
if opt.Platform != nil {
pp = *opt.Platform
} else {
pp = platforms.DefaultSpec()
}
pname := name + "::" + platforms.FormatAll(platforms.Normalize(pp))
nc, err := bc.namedContext(name, pname, opt)

View File

@ -134,7 +134,7 @@ func (results *LintResults) ToResult(scb SourceInfoMap) (*client.Result, error)
if len(results.Warnings) > 0 || results.Error != nil {
status = 1
}
res.AddMeta("result.statuscode", []byte(fmt.Sprintf("%d", status)))
res.AddMeta("result.statuscode", fmt.Appendf(nil, "%d", status))
res.AddMeta("version", []byte(SubrequestLintDefinition.Version))
return res, nil