Merge pull request #2417 from tonistiigi/update-buildkit-240417

vendor: update buildkit to 71f99c52a669
This commit is contained in:
Tõnis Tiigi 2024-04-17 10:02:29 -07:00 committed by GitHub
commit 171fcbeb69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
19 changed files with 114 additions and 88 deletions

View File

@ -54,9 +54,9 @@ var (
const (
//nolint:gosec // G101: false-positive
printFallbackImage = "docker/dockerfile:1.5@sha256:dbbd5e059e8a07ff7ea6233b213b36aa516b4c53c645f1817a4dd18b83cbea56"
// https://github.com/moby/buildkit/commit/3fd813cfa5eec6633b21da8164e93673d005df02
// https://github.com/moby/buildkit/commit/71f99c52a669dc0322b5ea57bc28a09c20427227
//nolint:gosec // G101: false-positive
printLintFallbackImage = "docker/dockerfile-upstream@sha256:2e302d1450bb1c3d9ef9b52800d2f3738cdfd21ead73a403e32a9bc275290e7c"
printLintFallbackImage = "docker.io/docker/dockerfile-upstream@sha256:47663570b6cc49ed90dc6e3215090a366989ab934d12dc93856a8ae0d27a95e7"
)
type Options struct {

2
go.mod
View File

@ -26,7 +26,7 @@ require (
github.com/hashicorp/go-cty-funcs v0.0.0-20230405223818-a090f58aa992
github.com/hashicorp/hcl/v2 v2.20.1
github.com/in-toto/in-toto-golang v0.5.0
github.com/moby/buildkit v0.13.0-rc3.0.20240411143343-549891b34890 // v0.14.0-dev
github.com/moby/buildkit v0.13.0-rc3.0.20240417151852-71f99c52a669 // v0.14.0-dev
github.com/moby/sys/mountinfo v0.7.1
github.com/moby/sys/signal v0.7.0
github.com/morikuni/aec v1.0.0

4
go.sum
View File

@ -293,8 +293,8 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mitchellh/reflectwalk v1.0.2 h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
github.com/mitchellh/reflectwalk v1.0.2/go.mod h1:mSTlrgnPZtwu0c4WaC2kGObEpuNDbx0jmZXqmk4esnw=
github.com/moby/buildkit v0.13.0-rc3.0.20240411143343-549891b34890 h1:ikD8s7J6fN9kme4Yq1nUKlpZhEnakiMEcN9XeKFZXbs=
github.com/moby/buildkit v0.13.0-rc3.0.20240411143343-549891b34890/go.mod h1:iqJg3dy9wLt5maCeC8WBbDISnLvuSX+R9jVNzg2zACU=
github.com/moby/buildkit v0.13.0-rc3.0.20240417151852-71f99c52a669 h1:DnnuoY7BDEXoW4qbDHBvWy2lCzus6AO4CJGaEq94e7M=
github.com/moby/buildkit v0.13.0-rc3.0.20240417151852-71f99c52a669/go.mod h1:iqJg3dy9wLt5maCeC8WBbDISnLvuSX+R9jVNzg2zACU=
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
github.com/moby/locker v1.0.1 h1:fOXqR41zeveg4fFODix+1Ch4mj/gT0NE1XJbp/epuBg=

View File

@ -642,7 +642,7 @@ type fileActionState struct {
fa *FileAction
}
func (ms *marshalState) addInput(st *fileActionState, c *Constraints, o Output) (pb.InputIndex, error) {
func (ms *marshalState) addInput(c *Constraints, o Output) (pb.InputIndex, error) {
inp, err := o.ToInput(ms.ctx, c)
if err != nil {
return 0, err
@ -684,7 +684,7 @@ func (ms *marshalState) add(fa *FileAction, c *Constraints) (*fileActionState, e
}
if source := fa.state.Output(); source != nil {
inp, err := ms.addInput(st, c, source)
inp, err := ms.addInput(c, source)
if err != nil {
return nil, err
}
@ -700,7 +700,7 @@ func (ms *marshalState) add(fa *FileAction, c *Constraints) (*fileActionState, e
if a, ok := fa.action.(*fileActionCopy); ok {
if a.state != nil {
if out := a.state.Output(); out != nil {
inp, err := ms.addInput(st, c, out)
inp, err := ms.addInput(c, out)
if err != nil {
return nil, err
}

View File

@ -269,7 +269,7 @@ func parseString(rest string, d *directives) (*Node, map[string]bool, error) {
}
// parseJSON converts JSON arrays to an AST.
func parseJSON(rest string, d *directives) (*Node, map[string]bool, error) {
func parseJSON(rest string) (*Node, map[string]bool, error) {
rest = strings.TrimLeftFunc(rest, unicode.IsSpace)
if !strings.HasPrefix(rest, "[") {
return nil, nil, errors.Errorf("Error parsing %q as a JSON array", rest)
@ -307,7 +307,7 @@ func parseMaybeJSON(rest string, d *directives) (*Node, map[string]bool, error)
return nil, nil, nil
}
node, attrs, err := parseJSON(rest, d)
node, attrs, err := parseJSON(rest)
if err == nil {
return node, attrs, nil
@ -325,7 +325,7 @@ func parseMaybeJSON(rest string, d *directives) (*Node, map[string]bool, error)
// so, passes to parseJSON; if not, attempts to parse it as a whitespace
// delimited string.
func parseMaybeJSONToList(rest string, d *directives) (*Node, map[string]bool, error) {
node, attrs, err := parseJSON(rest, d)
node, attrs, err := parseJSON(rest)
if err == nil {
return node, attrs, nil

View File

@ -6,13 +6,14 @@ import (
"fmt"
"io"
"sort"
"text/tabwriter"
"github.com/moby/buildkit/client/llb"
"github.com/moby/buildkit/frontend/dockerfile/parser"
"github.com/moby/buildkit/frontend/gateway/client"
"github.com/moby/buildkit/frontend/subrequests"
"github.com/moby/buildkit/solver/errdefs"
"github.com/moby/buildkit/solver/pb"
"github.com/pkg/errors"
)
const RequestLint = "frontend.lint"
@ -26,16 +27,10 @@ var SubrequestLintDefinition = subrequests.Request{
Metadata: []subrequests.Named{
{Name: "result.json"},
{Name: "result.txt"},
{Name: "result.statuscode"},
},
}
type Source struct {
Filename string `json:"fileName"`
Language string `json:"language"`
Definition *pb.Definition `json:"definition"`
Data []byte `json:"data"`
}
type Warning struct {
RuleName string `json:"ruleName"`
Description string `json:"description,omitempty"`
@ -45,19 +40,19 @@ type Warning struct {
}
type LintResults struct {
Warnings []Warning `json:"warnings"`
Sources []Source `json:"sources"`
Warnings []Warning `json:"warnings"`
Sources []*pb.SourceInfo `json:"sources"`
}
func (results *LintResults) AddSource(sourceMap *llb.SourceMap) int {
newSource := Source{
newSource := &pb.SourceInfo{
Filename: sourceMap.Filename,
Language: sourceMap.Language,
Definition: sourceMap.Definition.ToPB(),
Data: sourceMap.Data,
}
for i, source := range results.Sources {
if sourceEqual(source, newSource) {
if sourceInfoEqual(source, newSource) {
return i
}
}
@ -92,13 +87,6 @@ func (results *LintResults) AddWarning(rulename, description, url, fmtmsg string
})
}
func sourceEqual(a, b Source) bool {
if a.Filename != b.Filename || a.Language != b.Language {
return false
}
return bytes.Equal(a.Data, b.Data)
}
func (results *LintResults) ToResult() (*client.Result, error) {
res := client.NewResult()
dt, err := json.MarshalIndent(results, "", " ")
@ -113,51 +101,91 @@ func (results *LintResults) ToResult() (*client.Result, error) {
}
res.AddMeta("result.txt", b.Bytes())
status := 0
if len(results.Warnings) > 0 {
status = 1
}
res.AddMeta("result.statuscode", []byte(fmt.Sprintf("%d", status)))
res.AddMeta("version", []byte(SubrequestLintDefinition.Version))
return res, nil
}
func PrintLintViolations(dt []byte, w io.Writer) error {
var warnings LintResults
func (results *LintResults) validateWarnings() error {
for _, warning := range results.Warnings {
if int(warning.Location.SourceIndex) >= len(results.Sources) {
return errors.Errorf("sourceIndex is out of range")
}
if warning.Location.SourceIndex > 0 {
warningSource := results.Sources[warning.Location.SourceIndex]
if warningSource == nil {
return errors.Errorf("sourceIndex points to nil source")
}
}
}
return nil
}
if err := json.Unmarshal(dt, &warnings); err != nil {
func PrintLintViolations(dt []byte, w io.Writer) error {
var results LintResults
if err := json.Unmarshal(dt, &results); err != nil {
return err
}
// Here, we're grouping the warnings by rule name
lintWarnings := make(map[string][]Warning)
lintWarningRules := []string{}
for _, warning := range warnings.Warnings {
if _, ok := lintWarnings[warning.RuleName]; !ok {
lintWarningRules = append(lintWarningRules, warning.RuleName)
lintWarnings[warning.RuleName] = []Warning{}
}
lintWarnings[warning.RuleName] = append(lintWarnings[warning.RuleName], warning)
}
sort.Strings(lintWarningRules)
tw := tabwriter.NewWriter(w, 0, 0, 2, ' ', 0)
for _, rule := range lintWarningRules {
fmt.Fprintf(tw, "Lint Rule %s\n", rule)
for _, warning := range lintWarnings[rule] {
source := warnings.Sources[warning.Location.SourceIndex]
sourceData := bytes.Split(source.Data, []byte("\n"))
firstRange := warning.Location.Ranges[0]
if firstRange.Start.Line != firstRange.End.Line {
fmt.Fprintf(tw, "\t%s:%d-%d\n", source.Filename, firstRange.Start.Line, firstRange.End.Line)
} else {
fmt.Fprintf(tw, "\t%s:%d\n", source.Filename, firstRange.Start.Line)
}
fmt.Fprintf(tw, "\t%s\n", warning.Detail)
for _, r := range warning.Location.Ranges {
for i := r.Start.Line; i <= r.End.Line; i++ {
fmt.Fprintf(tw, "\t%d\t|\t%s\n", i, sourceData[i-1])
}
}
fmt.Fprintln(tw)
}
fmt.Fprintln(tw)
if err := results.validateWarnings(); err != nil {
return err
}
return tw.Flush()
sort.Slice(results.Warnings, func(i, j int) bool {
warningI := results.Warnings[i]
warningJ := results.Warnings[j]
sourceIndexI := warningI.Location.SourceIndex
sourceIndexJ := warningJ.Location.SourceIndex
if sourceIndexI < 0 && sourceIndexJ < 0 {
return warningI.RuleName < warningJ.RuleName
} else if sourceIndexI < 0 || sourceIndexJ < 0 {
return sourceIndexI < 0
}
sourceInfoI := results.Sources[warningI.Location.SourceIndex]
sourceInfoJ := results.Sources[warningJ.Location.SourceIndex]
if sourceInfoI.Filename != sourceInfoJ.Filename {
return sourceInfoI.Filename < sourceInfoJ.Filename
}
if len(warningI.Location.Ranges) == 0 && len(warningJ.Location.Ranges) == 0 {
return warningI.RuleName < warningJ.RuleName
} else if len(warningI.Location.Ranges) == 0 || len(warningJ.Location.Ranges) == 0 {
return len(warningI.Location.Ranges) == 0
}
return warningI.Location.Ranges[0].Start.Line < warningJ.Location.Ranges[0].Start.Line
})
for _, warning := range results.Warnings {
fmt.Fprintf(w, "\n- %s\n%s\n", warning.Detail, warning.Description)
if warning.URL != "" {
fmt.Fprintf(w, "URL: %s\n", warning.URL)
}
if warning.Location.SourceIndex < 0 {
continue
}
sourceInfo := results.Sources[warning.Location.SourceIndex]
source := errdefs.Source{
Info: sourceInfo,
Ranges: warning.Location.Ranges,
}
err := source.Print(w)
if err != nil {
return err
}
}
return nil
}
func sourceInfoEqual(a, b *pb.SourceInfo) bool {
if a.Filename != b.Filename || a.Language != b.Language {
return false
}
return bytes.Equal(a.Data, b.Data)
}

View File

@ -11,6 +11,6 @@ func getFallbackAgentPath() (string, error) {
return "", errors.Errorf("make sure SSH_AUTH_SOCK is set")
}
func getWindowsPipeDialer(path string) *socketDialer {
func getWindowsPipeDialer(_ string) *socketDialer {
return nil
}

View File

@ -37,8 +37,8 @@ type Upload struct {
cc Upload_PullClient
}
func (u *Upload) WriteTo(w io.Writer) (int, error) {
n := 0
func (u *Upload) WriteTo(w io.Writer) (int64, error) {
var n int64
for {
var bm BytesMessage
if err := u.cc.RecvMsg(&bm); err != nil {
@ -48,7 +48,7 @@ func (u *Upload) WriteTo(w io.Writer) (int, error) {
return n, errors.WithStack(err)
}
nn, err := w.Write(bm.Data)
n += nn
n += int64(nn)
if err != nil {
return n, errors.WithStack(err)
}

View File

@ -113,14 +113,14 @@ func (b *buffer) Writer(ctx context.Context, opts ...content.WriterOpt) (content
}
func (b *buffer) ReaderAt(ctx context.Context, desc ocispecs.Descriptor) (content.ReaderAt, error) {
r, err := b.getBytesReader(ctx, desc.Digest)
r, err := b.getBytesReader(desc.Digest)
if err != nil {
return nil, err
}
return &readerAt{Reader: r, Closer: io.NopCloser(r), size: int64(r.Len())}, nil
}
func (b *buffer) getBytesReader(ctx context.Context, dgst digest.Digest) (*bytes.Reader, error) {
func (b *buffer) getBytesReader(dgst digest.Digest) (*bytes.Reader, error) {
b.mu.Lock()
defer b.mu.Unlock()

View File

@ -69,7 +69,7 @@ func ParseGitRef(ref string) (*GitRef, error) {
} else {
remote, err = ParseURL(ref)
if errors.Is(err, ErrUnknownProtocol) {
remote, err = ParseURL("https://" + ref)
return nil, err
}
if err != nil {
return nil, err

View File

@ -115,7 +115,7 @@ func Config(ctx context.Context, str string, resolver remotes.Resolver, cache Co
}
if desc.MediaType == images.MediaTypeDockerSchema1Manifest {
dgst, dt, err := readSchema1Config(ctx, ref.String(), desc, fetcher, cache)
dgst, dt, err := readSchema1Config(ctx, desc, fetcher)
return dgst, dt, err
}

View File

@ -14,7 +14,7 @@ import (
"github.com/pkg/errors"
)
func readSchema1Config(ctx context.Context, ref string, desc ocispecs.Descriptor, fetcher remotes.Fetcher, cache ContentCache) (digest.Digest, []byte, error) {
func readSchema1Config(ctx context.Context, desc ocispecs.Descriptor, fetcher remotes.Fetcher) (digest.Digest, []byte, error) {
rc, err := fetcher.Fetch(ctx, desc)
if err != nil {
return "", nil, err

View File

@ -155,7 +155,7 @@ func NewDisplay(out io.Writer, mode DisplayMode, opts ...DisplayOpt) (Display, e
case PlainMode:
return newPlainDisplay(out, opts...), nil
case RawJSONMode:
return newRawJSONDisplay(out, opts...), nil
return newRawJSONDisplay(out), nil
case QuietMode:
return newDiscardDisplay(), nil
default:
@ -283,7 +283,7 @@ type rawJSONDisplay struct {
// newRawJSONDisplay creates a new Display that outputs an unbuffered
// output of status update events.
func newRawJSONDisplay(w io.Writer, opts ...DisplayOpt) Display {
func newRawJSONDisplay(w io.Writer) Display {
enc := json.NewEncoder(w)
enc.SetIndent("", " ")
return Display{

View File

@ -231,7 +231,7 @@ disabled_plugins = ["cri"]
"nsenter", "-U", "--preserve-credentials", "-m", "-t", fmt.Sprintf("%d", pid)},
append(buildkitdArgs, "--containerd-worker-snapshotter=native")...)
}
buildkitdSock, stop, err := runBuildkitd(ctx, cfg, buildkitdArgs, cfg.Logs, c.UID, c.GID, c.ExtraEnv)
buildkitdSock, stop, err := runBuildkitd(cfg, buildkitdArgs, cfg.Logs, c.UID, c.GID, c.ExtraEnv)
if err != nil {
integration.PrintLogs(cfg.Logs, log.Println)
return nil, nil, err

View File

@ -77,7 +77,7 @@ func (s *OCI) New(ctx context.Context, cfg *integration.BackendConfig) (integrat
if runtime.GOOS != "windows" && s.Snapshotter != "native" {
extraEnv = append(extraEnv, "BUILDKIT_DEBUG_FORCE_OVERLAY_DIFF=true")
}
buildkitdSock, stop, err := runBuildkitd(ctx, cfg, buildkitdArgs, cfg.Logs, s.UID, s.GID, extraEnv)
buildkitdSock, stop, err := runBuildkitd(cfg, buildkitdArgs, cfg.Logs, s.UID, s.GID, extraEnv)
if err != nil {
integration.PrintLogs(cfg.Logs, log.Println)
return nil, nil, err

View File

@ -2,7 +2,6 @@ package workers
import (
"bytes"
"context"
"fmt"
"os"
"os/exec"
@ -27,7 +26,6 @@ func (osp otelSocketPath) UpdateConfigFile(in string) string {
}
func runBuildkitd(
ctx context.Context,
conf *integration.BackendConfig,
args []string,
logs map[string]*bytes.Buffer,

View File

@ -35,11 +35,11 @@ func getContainerdDebugSock(tmpdir string) string {
}
// no-op for parity with unix
func mountInfo(tmpdir string) error {
func mountInfo(_ string) error {
return nil
}
func chown(name string, uid, gid int) error {
func chown(_ string, _, _ int) error {
// Chown not supported on Windows
return nil
}

View File

@ -66,7 +66,7 @@ func (c *Connection) StartConnection(ctx context.Context) error {
c.disconnectedCh = make(chan bool, 1)
c.backgroundConnectionDoneCh = make(chan struct{})
if err := c.connect(ctx); err == nil {
if err := c.connect(); err == nil {
c.setStateConnected()
} else {
c.SetStateDisconnected(err)
@ -148,7 +148,7 @@ func (c *Connection) indefiniteBackgroundConnection() {
// Normal scenario that we'll wait for
}
if err := c.connect(context.Background()); err == nil {
if err := c.connect(); err == nil {
c.setStateConnected()
} else {
// this code is unreachable in most cases
@ -168,7 +168,7 @@ func (c *Connection) indefiniteBackgroundConnection() {
}
}
func (c *Connection) connect(ctx context.Context) error {
func (c *Connection) connect() error {
c.newConnectionHandler(c.cc)
return nil
}

2
vendor/modules.txt vendored
View File

@ -510,7 +510,7 @@ github.com/mitchellh/mapstructure
# github.com/mitchellh/reflectwalk v1.0.2
## explicit
github.com/mitchellh/reflectwalk
# github.com/moby/buildkit v0.13.0-rc3.0.20240411143343-549891b34890
# github.com/moby/buildkit v0.13.0-rc3.0.20240417151852-71f99c52a669
## explicit; go 1.21
github.com/moby/buildkit/api/services/control
github.com/moby/buildkit/api/types