diff --git a/go.mod b/go.mod index 370e6029..135877fa 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 5528b420..3da905bd 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/vendor/github.com/moby/buildkit/client/llb/fileop.go b/vendor/github.com/moby/buildkit/client/llb/fileop.go index 831c4f38..fa2d7247 100644 --- a/vendor/github.com/moby/buildkit/client/llb/fileop.go +++ b/vendor/github.com/moby/buildkit/client/llb/fileop.go @@ -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 } diff --git a/vendor/github.com/moby/buildkit/frontend/dockerfile/parser/line_parsers.go b/vendor/github.com/moby/buildkit/frontend/dockerfile/parser/line_parsers.go index db8d0bda..33f7965d 100644 --- a/vendor/github.com/moby/buildkit/frontend/dockerfile/parser/line_parsers.go +++ b/vendor/github.com/moby/buildkit/frontend/dockerfile/parser/line_parsers.go @@ -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 diff --git a/vendor/github.com/moby/buildkit/frontend/subrequests/lint/lint.go b/vendor/github.com/moby/buildkit/frontend/subrequests/lint/lint.go index cfe1420b..6237eb3c 100644 --- a/vendor/github.com/moby/buildkit/frontend/subrequests/lint/lint.go +++ b/vendor/github.com/moby/buildkit/frontend/subrequests/lint/lint.go @@ -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) } diff --git a/vendor/github.com/moby/buildkit/session/sshforward/sshprovider/agentprovider_unix.go b/vendor/github.com/moby/buildkit/session/sshforward/sshprovider/agentprovider_unix.go index f63f0d9e..01552c30 100644 --- a/vendor/github.com/moby/buildkit/session/sshforward/sshprovider/agentprovider_unix.go +++ b/vendor/github.com/moby/buildkit/session/sshforward/sshprovider/agentprovider_unix.go @@ -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 } diff --git a/vendor/github.com/moby/buildkit/session/upload/upload.go b/vendor/github.com/moby/buildkit/session/upload/upload.go index c739b92d..e3fce5c1 100644 --- a/vendor/github.com/moby/buildkit/session/upload/upload.go +++ b/vendor/github.com/moby/buildkit/session/upload/upload.go @@ -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) } diff --git a/vendor/github.com/moby/buildkit/util/contentutil/buffer.go b/vendor/github.com/moby/buildkit/util/contentutil/buffer.go index 9230b207..3698cb26 100644 --- a/vendor/github.com/moby/buildkit/util/contentutil/buffer.go +++ b/vendor/github.com/moby/buildkit/util/contentutil/buffer.go @@ -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() diff --git a/vendor/github.com/moby/buildkit/util/gitutil/git_ref.go b/vendor/github.com/moby/buildkit/util/gitutil/git_ref.go index 8a78bc16..5e386293 100644 --- a/vendor/github.com/moby/buildkit/util/gitutil/git_ref.go +++ b/vendor/github.com/moby/buildkit/util/gitutil/git_ref.go @@ -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 diff --git a/vendor/github.com/moby/buildkit/util/imageutil/config.go b/vendor/github.com/moby/buildkit/util/imageutil/config.go index 2202a517..773d425c 100644 --- a/vendor/github.com/moby/buildkit/util/imageutil/config.go +++ b/vendor/github.com/moby/buildkit/util/imageutil/config.go @@ -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 } diff --git a/vendor/github.com/moby/buildkit/util/imageutil/schema1.go b/vendor/github.com/moby/buildkit/util/imageutil/schema1.go index fde33421..e87018e4 100644 --- a/vendor/github.com/moby/buildkit/util/imageutil/schema1.go +++ b/vendor/github.com/moby/buildkit/util/imageutil/schema1.go @@ -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 diff --git a/vendor/github.com/moby/buildkit/util/progress/progressui/display.go b/vendor/github.com/moby/buildkit/util/progress/progressui/display.go index 722fb77c..fcc4b835 100644 --- a/vendor/github.com/moby/buildkit/util/progress/progressui/display.go +++ b/vendor/github.com/moby/buildkit/util/progress/progressui/display.go @@ -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{ diff --git a/vendor/github.com/moby/buildkit/util/testutil/workers/containerd.go b/vendor/github.com/moby/buildkit/util/testutil/workers/containerd.go index 7456c3e5..ac32aa28 100644 --- a/vendor/github.com/moby/buildkit/util/testutil/workers/containerd.go +++ b/vendor/github.com/moby/buildkit/util/testutil/workers/containerd.go @@ -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 diff --git a/vendor/github.com/moby/buildkit/util/testutil/workers/oci.go b/vendor/github.com/moby/buildkit/util/testutil/workers/oci.go index a851c252..154ba264 100644 --- a/vendor/github.com/moby/buildkit/util/testutil/workers/oci.go +++ b/vendor/github.com/moby/buildkit/util/testutil/workers/oci.go @@ -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 diff --git a/vendor/github.com/moby/buildkit/util/testutil/workers/util.go b/vendor/github.com/moby/buildkit/util/testutil/workers/util.go index 4d9d7dcc..9a10cb46 100644 --- a/vendor/github.com/moby/buildkit/util/testutil/workers/util.go +++ b/vendor/github.com/moby/buildkit/util/testutil/workers/util.go @@ -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, diff --git a/vendor/github.com/moby/buildkit/util/testutil/workers/util_windows.go b/vendor/github.com/moby/buildkit/util/testutil/workers/util_windows.go index 8d95f04e..1a55bad9 100644 --- a/vendor/github.com/moby/buildkit/util/testutil/workers/util_windows.go +++ b/vendor/github.com/moby/buildkit/util/testutil/workers/util_windows.go @@ -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 } diff --git a/vendor/github.com/moby/buildkit/util/tracing/otlptracegrpc/connection.go b/vendor/github.com/moby/buildkit/util/tracing/otlptracegrpc/connection.go index 6b52d359..25078c13 100644 --- a/vendor/github.com/moby/buildkit/util/tracing/otlptracegrpc/connection.go +++ b/vendor/github.com/moby/buildkit/util/tracing/otlptracegrpc/connection.go @@ -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 } diff --git a/vendor/modules.txt b/vendor/modules.txt index 5b39379f..a38eb746 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -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