From b606e2f6bb70aab62e35b9649476e85d10932c7d Mon Sep 17 00:00:00 2001 From: CrazyMax <1951866+crazy-max@users.noreply.github.com> Date: Tue, 13 May 2025 16:09:17 +0200 Subject: [PATCH] update golangci-lint to v2.1.5 Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com> --- .golangci.yml | 185 +++++++++++---------- bake/hclparser/hclparser.go | 2 +- bake/hclparser/stdlib.go | 2 +- build/build.go | 10 +- build/dial.go | 8 +- build/driver.go | 20 +-- build/driver_test.go | 86 +++++----- build/git.go | 6 +- build/git_test.go | 23 +-- build/opt.go | 2 +- build/result.go | 12 +- builder/builder.go | 10 +- builder/node.go | 2 +- commands/bake.go | 2 +- commands/dial_stdio.go | 4 +- commands/history/inspect.go | 9 +- commands/history/logs.go | 2 +- commands/imagetools/create.go | 8 +- commands/inspect.go | 6 +- commands/ls.go | 2 +- commands/rm.go | 2 +- docker-bake.hcl | 3 + driver/docker-container/driver.go | 18 +- driver/kubernetes/manifest/manifest.go | 10 +- driver/manager.go | 4 +- driver/remote/driver.go | 6 +- hack/dockerfiles/lint.Dockerfile | 2 +- store/nodegroup.go | 10 +- util/imagetools/create.go | 46 ++--- util/imagetools/imagetools_helpers_test.go | 89 +++++----- util/imagetools/inspect.go | 16 +- util/imagetools/loader.go | 34 ++-- util/imagetools/printers.go | 2 +- util/platformutil/parse.go | 16 +- 34 files changed, 332 insertions(+), 327 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 05dca7f25..900134f46 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,17 +1,16 @@ +version: "2" + run: - timeout: 30m modules-download-mode: vendor linters: + default: none enable: - bodyclose - depguard - forbidigo - gocritic - - gofmt - - goimports - gosec - - gosimple - govet - ineffassign - makezero @@ -21,99 +20,101 @@ linters: - revive - staticcheck - testifylint - - typecheck - unused - whitespace - disable-all: true - -linters-settings: - gocritic: - disabled-checks: - - "ifElseChain" - - "assignOp" - - "appendAssign" - - "singleCaseSwitch" - - "exitAfterDefer" # FIXME - importas: - alias: - # Enforce alias to prevent it accidentally being used instead of - # buildkit errdefs package (or vice-versa). - - pkg: "github.com/containerd/errdefs" - alias: "cerrdefs" - # Use a consistent alias to prevent confusion with "github.com/moby/buildkit/client" - - pkg: "github.com/docker/docker/client" - alias: "dockerclient" - - pkg: "github.com/opencontainers/image-spec/specs-go/v1" - alias: "ocispecs" - - pkg: "github.com/opencontainers/go-digest" - alias: "digest" - govet: - enable: - - nilness - - unusedwrite - # enable-all: true - # disable: - # - fieldalignment - # - shadow - depguard: + settings: + depguard: + rules: + main: + deny: + - pkg: "github.com/containerd/containerd/errdefs" + desc: The containerd errdefs package was migrated to a separate module. Use github.com/containerd/errdefs instead. + - pkg: "github.com/containerd/containerd/log" + desc: The containerd log package was migrated to a separate module. Use github.com/containerd/log instead. + - pkg: "github.com/containerd/containerd/platforms" + desc: The containerd platforms package was migrated to a separate module. Use github.com/containerd/platforms instead. + - pkg: "io/ioutil" + desc: The io/ioutil package has been deprecated. + forbidigo: + forbid: + - pattern: ^context\.WithCancel(# use context\.WithCancelCause instead)?$ + - pattern: ^context\.WithDeadline(# use context\.WithDeadline instead)?$ + - pattern: ^context\.WithTimeout(# use context\.WithTimeoutCause instead)?$ + - pattern: ^ctx\.Err(# use context\.Cause instead)?$ + - pattern: ^fmt\.Errorf(# use errors\.Errorf instead)?$ + - pattern: ^platforms\.DefaultString(# use platforms\.Format(platforms\.DefaultSpec()) instead\.)?$ + gocritic: + disabled-checks: + - "ifElseChain" + - "assignOp" + - "appendAssign" + - "singleCaseSwitch" + - "exitAfterDefer" # FIXME + gosec: + excludes: + - G204 + - G402 + - G115 + config: + G306: "0644" + govet: + enable: + - nilness + - unusedwrite + importas: + alias: + - pkg: "github.com/containerd/errdefs" + alias: "cerrdefs" + - pkg: "github.com/docker/docker/client" + alias: "dockerclient" + - pkg: "github.com/opencontainers/image-spec/specs-go/v1" + alias: "ocispecs" + - pkg: "github.com/opencontainers/go-digest" + alias: "digest" + testifylint: + disable: + - empty + - bool-compare + - len + - negative-positive + exclusions: + generated: lax + presets: + - comments + - common-false-positives + - legacy + - std-error-handling rules: - main: - deny: - - pkg: "github.com/containerd/containerd/errdefs" - desc: The containerd errdefs package was migrated to a separate module. Use github.com/containerd/errdefs instead. - - pkg: "github.com/containerd/containerd/log" - desc: The containerd log package was migrated to a separate module. Use github.com/containerd/log instead. - - pkg: "github.com/containerd/containerd/platforms" - desc: The containerd platforms package was migrated to a separate module. Use github.com/containerd/platforms instead. - - pkg: "io/ioutil" - desc: The io/ioutil package has been deprecated. - forbidigo: - forbid: - - '^context\.WithCancel(# use context\.WithCancelCause instead)?$' - - '^context\.WithDeadline(# use context\.WithDeadline instead)?$' - - '^context\.WithTimeout(# use context\.WithTimeoutCause instead)?$' - - '^ctx\.Err(# use context\.Cause instead)?$' - - '^fmt\.Errorf(# use errors\.Errorf instead)?$' - - '^platforms\.DefaultString(# use platforms\.Format(platforms\.DefaultSpec()) instead\.)?$' - gosec: - excludes: - - G204 # Audit use of command execution - - G402 # TLS MinVersion too low - - G115 # integer overflow conversion (TODO: verify these) - config: - G306: "0644" - testifylint: - disable: - # disable rules that reduce the test condition - - "empty" - - "bool-compare" - - "len" - - "negative-positive" + - linters: + - revive + text: stutters + - linters: + - revive + text: empty-block + - linters: + - revive + text: superfluous-else + - linters: + - revive + text: unused-parameter + - linters: + - revive + text: redefines-builtin-id + - linters: + - revive + text: if-return + paths: + - .*\.pb\.go$ +formatters: + enable: + - gofmt + - goimports + exclusions: + generated: lax + paths: + - .*\.pb\.go$ issues: - exclude-files: - - ".*\\.pb\\.go$" - exclude-rules: - - linters: - - revive - text: "stutters" - - linters: - - revive - text: "empty-block" - - linters: - - revive - text: "superfluous-else" - - linters: - - revive - text: "unused-parameter" - - linters: - - revive - text: "redefines-builtin-id" - - linters: - - revive - text: "if-return" - - # show all max-issues-per-linter: 0 max-same-issues: 0 diff --git a/bake/hclparser/hclparser.go b/bake/hclparser/hclparser.go index 16ffc4546..24e3b7c1b 100644 --- a/bake/hclparser/hclparser.go +++ b/bake/hclparser/hclparser.go @@ -936,7 +936,7 @@ func Parse(b hcl.Body, opt Opt, val any) (*ParseMeta, hcl.Diagnostics) { } } if exists { - if m := oldValue.Value.MethodByName("Merge"); m.IsValid() { + if m := oldValue.MethodByName("Merge"); m.IsValid() { m.Call([]reflect.Value{vv}) } else { v.Elem().Field(t.idx).Index(oldValue.idx).Set(vv) diff --git a/bake/hclparser/stdlib.go b/bake/hclparser/stdlib.go index df04bb8ac..d8ef0004e 100644 --- a/bake/hclparser/stdlib.go +++ b/bake/hclparser/stdlib.go @@ -144,7 +144,7 @@ func indexOfFunc() function.Function { }, Type: function.StaticReturnType(cty.Number), Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) { - if !(args[0].Type().IsListType() || args[0].Type().IsTupleType()) { + if !args[0].Type().IsListType() && !args[0].Type().IsTupleType() { return cty.NilVal, errors.New("argument must be a list or tuple") } diff --git a/build/build.go b/build/build.go index 0414b3500..a857fba4d 100644 --- a/build/build.go +++ b/build/build.go @@ -44,7 +44,7 @@ import ( "github.com/moby/buildkit/util/progress/progresswriter" "github.com/moby/buildkit/util/tracing" "github.com/opencontainers/go-digest" - specs "github.com/opencontainers/image-spec/specs-go/v1" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" "github.com/sirupsen/logrus" "github.com/tonistiigi/fsutil" @@ -76,7 +76,7 @@ type Options struct { NetworkMode string NoCache bool NoCacheFilter []string - Platforms []specs.Platform + Platforms []ocispecs.Platform Pull bool SecretSpecs []*controllerapi.Secret SSHSpecs []*controllerapi.SSH @@ -600,7 +600,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opts map[ if pushNames != "" { err := progress.Write(pw, fmt.Sprintf("merging manifest list %s", pushNames), func() error { - descs := make([]specs.Descriptor, 0, len(res)) + descs := make([]ocispecs.Descriptor, 0, len(res)) for _, r := range res { s, ok := r.ExporterResponse[exptypes.ExporterImageDescriptorKey] @@ -609,7 +609,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opts map[ if err != nil { return err } - var desc specs.Descriptor + var desc ocispecs.Descriptor if err := json.Unmarshal(dt, &desc); err != nil { return errors.Wrapf(err, "failed to unmarshal descriptor %s", s) } @@ -622,7 +622,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opts map[ // mediatype value in the Accept header does not seem to matter. s, ok = r.ExporterResponse[exptypes.ExporterImageDigestKey] if ok { - descs = append(descs, specs.Descriptor{ + descs = append(descs, ocispecs.Descriptor{ Digest: digest.Digest(s), MediaType: images.MediaTypeDockerSchema2ManifestList, Size: -1, diff --git a/build/dial.go b/build/dial.go index b842419aa..571d3c1e5 100644 --- a/build/dial.go +++ b/build/dial.go @@ -9,11 +9,11 @@ import ( "github.com/containerd/platforms" "github.com/docker/buildx/builder" "github.com/docker/buildx/util/progress" - v1 "github.com/opencontainers/image-spec/specs-go/v1" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" ) -func Dial(ctx context.Context, nodes []builder.Node, pw progress.Writer, platform *v1.Platform) (net.Conn, error) { +func Dial(ctx context.Context, nodes []builder.Node, pw progress.Writer, platform *ocispecs.Platform) (net.Conn, error) { nodes, err := filterAvailableNodes(nodes) if err != nil { return nil, err @@ -23,9 +23,9 @@ func Dial(ctx context.Context, nodes []builder.Node, pw progress.Writer, platfor return nil, errors.New("no nodes available") } - var pls []v1.Platform + var pls []ocispecs.Platform if platform != nil { - pls = []v1.Platform{*platform} + pls = []ocispecs.Platform{*platform} } opts := map[string]Options{"default": {Platforms: pls}} diff --git a/build/driver.go b/build/driver.go index eaae14113..6eab6db8d 100644 --- a/build/driver.go +++ b/build/driver.go @@ -14,7 +14,7 @@ import ( gateway "github.com/moby/buildkit/frontend/gateway/client" "github.com/moby/buildkit/util/flightcontrol" "github.com/moby/buildkit/util/tracing" - specs "github.com/opencontainers/image-spec/specs-go/v1" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" "go.opentelemetry.io/otel/trace" "golang.org/x/sync/errgroup" @@ -23,7 +23,7 @@ import ( type resolvedNode struct { resolver *nodeResolver driverIndex int - platforms []specs.Platform + platforms []ocispecs.Platform } func (dp resolvedNode) Node() builder.Node { @@ -46,7 +46,7 @@ func (dp resolvedNode) BuildOpts(ctx context.Context) (gateway.BuildOpts, error) return opts[0], nil } -type matchMaker func(specs.Platform) platforms.MatchComparer +type matchMaker func(ocispecs.Platform) platforms.MatchComparer type cachedGroup[T any] struct { g flightcontrol.Group[T] @@ -112,7 +112,7 @@ func (r *nodeResolver) Resolve(ctx context.Context, opt map[string]Options, pw p return nil, err } eg, egCtx := errgroup.WithContext(ctx) - workers := make([][]specs.Platform, len(clients)) + workers := make([][]ocispecs.Platform, len(clients)) for i, c := range clients { i, c := i, c if c == nil { @@ -124,7 +124,7 @@ func (r *nodeResolver) Resolve(ctx context.Context, opt map[string]Options, pw p return errors.Wrap(err, "listing workers") } - ps := make(map[string]specs.Platform, len(ww)) + ps := make(map[string]ocispecs.Platform, len(ww)) for _, w := range ww { for _, p := range w.Platforms { pk := platforms.Format(platforms.Normalize(p)) @@ -145,7 +145,7 @@ func (r *nodeResolver) Resolve(ctx context.Context, opt map[string]Options, pw p // (this time we don't care about imperfect matches) nodes = map[string][]*resolvedNode{} for k, opt := range opt { - node, _, err := r.resolve(ctx, opt.Platforms, pw, platforms.Only, func(idx int, n builder.Node) []specs.Platform { + node, _, err := r.resolve(ctx, opt.Platforms, pw, platforms.Only, func(idx int, n builder.Node) []ocispecs.Platform { return workers[idx] }) if err != nil { @@ -173,7 +173,7 @@ func (r *nodeResolver) Resolve(ctx context.Context, opt map[string]Options, pw p return nodes, nil } -func (r *nodeResolver) resolve(ctx context.Context, ps []specs.Platform, pw progress.Writer, matcher matchMaker, additional func(idx int, n builder.Node) []specs.Platform) ([]*resolvedNode, bool, error) { +func (r *nodeResolver) resolve(ctx context.Context, ps []ocispecs.Platform, pw progress.Writer, matcher matchMaker, additional func(idx int, n builder.Node) []ocispecs.Platform) ([]*resolvedNode, bool, error) { if len(r.nodes) == 0 { return nil, true, nil } @@ -203,7 +203,7 @@ func (r *nodeResolver) resolve(ctx context.Context, ps []specs.Platform, pw prog driverIndex: idx, } if len(ps) > 0 { - node.platforms = []specs.Platform{ps[i]} + node.platforms = []ocispecs.Platform{ps[i]} } nodes = append(nodes, node) } @@ -216,9 +216,9 @@ func (r *nodeResolver) resolve(ctx context.Context, ps []specs.Platform, pw prog return nodes, perfect, nil } -func (r *nodeResolver) get(p specs.Platform, matcher matchMaker, additionalPlatforms func(int, builder.Node) []specs.Platform) int { +func (r *nodeResolver) get(p ocispecs.Platform, matcher matchMaker, additionalPlatforms func(int, builder.Node) []ocispecs.Platform) int { best := -1 - bestPlatform := specs.Platform{} + bestPlatform := ocispecs.Platform{} for i, node := range r.nodes { platforms := node.Platforms if additionalPlatforms != nil { diff --git a/build/driver_test.go b/build/driver_test.go index a65ba97d0..1fbfeb423 100644 --- a/build/driver_test.go +++ b/build/driver_test.go @@ -7,41 +7,41 @@ import ( "github.com/containerd/platforms" "github.com/docker/buildx/builder" - specs "github.com/opencontainers/image-spec/specs-go/v1" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/stretchr/testify/require" ) func TestFindDriverSanity(t *testing.T) { - r := makeTestResolver(map[string][]specs.Platform{ + r := makeTestResolver(map[string][]ocispecs.Platform{ "aaa": {platforms.DefaultSpec()}, }) - res, perfect, err := r.resolve(context.TODO(), []specs.Platform{platforms.DefaultSpec()}, nil, platforms.OnlyStrict, nil) + res, perfect, err := r.resolve(context.TODO(), []ocispecs.Platform{platforms.DefaultSpec()}, nil, platforms.OnlyStrict, nil) require.NoError(t, err) require.True(t, perfect) require.Len(t, res, 1) require.Equal(t, 0, res[0].driverIndex) require.Equal(t, "aaa", res[0].Node().Builder) - require.Equal(t, []specs.Platform{platforms.DefaultSpec()}, res[0].platforms) + require.Equal(t, []ocispecs.Platform{platforms.DefaultSpec()}, res[0].platforms) } func TestFindDriverEmpty(t *testing.T) { r := makeTestResolver(nil) - res, perfect, err := r.resolve(context.TODO(), []specs.Platform{platforms.DefaultSpec()}, nil, platforms.Only, nil) + res, perfect, err := r.resolve(context.TODO(), []ocispecs.Platform{platforms.DefaultSpec()}, nil, platforms.Only, nil) require.NoError(t, err) require.True(t, perfect) require.Nil(t, res) } func TestFindDriverWeirdName(t *testing.T) { - r := makeTestResolver(map[string][]specs.Platform{ + r := makeTestResolver(map[string][]ocispecs.Platform{ "aaa": {platforms.MustParse("linux/amd64")}, "bbb": {platforms.MustParse("linux/foobar")}, }) // find first platform - res, perfect, err := r.resolve(context.TODO(), []specs.Platform{platforms.MustParse("linux/foobar")}, nil, platforms.Only, nil) + res, perfect, err := r.resolve(context.TODO(), []ocispecs.Platform{platforms.MustParse("linux/foobar")}, nil, platforms.Only, nil) require.NoError(t, err) require.True(t, perfect) require.Len(t, res, 1) @@ -50,11 +50,11 @@ func TestFindDriverWeirdName(t *testing.T) { } func TestFindDriverUnknown(t *testing.T) { - r := makeTestResolver(map[string][]specs.Platform{ + r := makeTestResolver(map[string][]ocispecs.Platform{ "aaa": {platforms.MustParse("linux/amd64")}, }) - res, perfect, err := r.resolve(context.TODO(), []specs.Platform{platforms.MustParse("linux/riscv64")}, nil, platforms.Only, nil) + res, perfect, err := r.resolve(context.TODO(), []ocispecs.Platform{platforms.MustParse("linux/riscv64")}, nil, platforms.Only, nil) require.NoError(t, err) require.False(t, perfect) require.Len(t, res, 1) @@ -63,13 +63,13 @@ func TestFindDriverUnknown(t *testing.T) { } func TestSelectNodeSinglePlatform(t *testing.T) { - r := makeTestResolver(map[string][]specs.Platform{ + r := makeTestResolver(map[string][]ocispecs.Platform{ "aaa": {platforms.MustParse("linux/amd64")}, "bbb": {platforms.MustParse("linux/riscv64")}, }) // find first platform - res, perfect, err := r.resolve(context.TODO(), []specs.Platform{platforms.MustParse("linux/amd64")}, nil, platforms.Only, nil) + res, perfect, err := r.resolve(context.TODO(), []ocispecs.Platform{platforms.MustParse("linux/amd64")}, nil, platforms.Only, nil) require.NoError(t, err) require.True(t, perfect) require.Len(t, res, 1) @@ -77,7 +77,7 @@ func TestSelectNodeSinglePlatform(t *testing.T) { require.Equal(t, "aaa", res[0].Node().Builder) // find second platform - res, perfect, err = r.resolve(context.TODO(), []specs.Platform{platforms.MustParse("linux/riscv64")}, nil, platforms.Only, nil) + res, perfect, err = r.resolve(context.TODO(), []ocispecs.Platform{platforms.MustParse("linux/riscv64")}, nil, platforms.Only, nil) require.NoError(t, err) require.True(t, perfect) require.Len(t, res, 1) @@ -85,7 +85,7 @@ func TestSelectNodeSinglePlatform(t *testing.T) { require.Equal(t, "bbb", res[0].Node().Builder) // find an unknown platform, should match the first driver - res, perfect, err = r.resolve(context.TODO(), []specs.Platform{platforms.MustParse("linux/s390x")}, nil, platforms.Only, nil) + res, perfect, err = r.resolve(context.TODO(), []ocispecs.Platform{platforms.MustParse("linux/s390x")}, nil, platforms.Only, nil) require.NoError(t, err) require.False(t, perfect) require.Len(t, res, 1) @@ -94,26 +94,26 @@ func TestSelectNodeSinglePlatform(t *testing.T) { } func TestSelectNodeMultiPlatform(t *testing.T) { - r := makeTestResolver(map[string][]specs.Platform{ + r := makeTestResolver(map[string][]ocispecs.Platform{ "aaa": {platforms.MustParse("linux/amd64"), platforms.MustParse("linux/arm64")}, "bbb": {platforms.MustParse("linux/riscv64")}, }) - res, perfect, err := r.resolve(context.TODO(), []specs.Platform{platforms.MustParse("linux/amd64")}, nil, platforms.Only, nil) + res, perfect, err := r.resolve(context.TODO(), []ocispecs.Platform{platforms.MustParse("linux/amd64")}, nil, platforms.Only, nil) require.NoError(t, err) require.True(t, perfect) require.Len(t, res, 1) require.Equal(t, 0, res[0].driverIndex) require.Equal(t, "aaa", res[0].Node().Builder) - res, perfect, err = r.resolve(context.TODO(), []specs.Platform{platforms.MustParse("linux/arm64")}, nil, platforms.Only, nil) + res, perfect, err = r.resolve(context.TODO(), []ocispecs.Platform{platforms.MustParse("linux/arm64")}, nil, platforms.Only, nil) require.NoError(t, err) require.True(t, perfect) require.Len(t, res, 1) require.Equal(t, 0, res[0].driverIndex) require.Equal(t, "aaa", res[0].Node().Builder) - res, perfect, err = r.resolve(context.TODO(), []specs.Platform{platforms.MustParse("linux/riscv64")}, nil, platforms.Only, nil) + res, perfect, err = r.resolve(context.TODO(), []ocispecs.Platform{platforms.MustParse("linux/riscv64")}, nil, platforms.Only, nil) require.NoError(t, err) require.True(t, perfect) require.Len(t, res, 1) @@ -122,27 +122,27 @@ func TestSelectNodeMultiPlatform(t *testing.T) { } func TestSelectNodeNonStrict(t *testing.T) { - r := makeTestResolver(map[string][]specs.Platform{ + r := makeTestResolver(map[string][]ocispecs.Platform{ "aaa": {platforms.MustParse("linux/amd64")}, "bbb": {platforms.MustParse("linux/arm64")}, }) // arm64 should match itself - res, perfect, err := r.resolve(context.TODO(), []specs.Platform{platforms.MustParse("linux/arm64")}, nil, platforms.Only, nil) + res, perfect, err := r.resolve(context.TODO(), []ocispecs.Platform{platforms.MustParse("linux/arm64")}, nil, platforms.Only, nil) require.NoError(t, err) require.True(t, perfect) require.Len(t, res, 1) require.Equal(t, "bbb", res[0].Node().Builder) // arm64 may support arm/v8 - res, perfect, err = r.resolve(context.TODO(), []specs.Platform{platforms.MustParse("linux/arm/v8")}, nil, platforms.Only, nil) + res, perfect, err = r.resolve(context.TODO(), []ocispecs.Platform{platforms.MustParse("linux/arm/v8")}, nil, platforms.Only, nil) require.NoError(t, err) require.True(t, perfect) require.Len(t, res, 1) require.Equal(t, "bbb", res[0].Node().Builder) // arm64 may support arm/v7 - res, perfect, err = r.resolve(context.TODO(), []specs.Platform{platforms.MustParse("linux/arm/v7")}, nil, platforms.Only, nil) + res, perfect, err = r.resolve(context.TODO(), []ocispecs.Platform{platforms.MustParse("linux/arm/v7")}, nil, platforms.Only, nil) require.NoError(t, err) require.True(t, perfect) require.Len(t, res, 1) @@ -150,19 +150,19 @@ func TestSelectNodeNonStrict(t *testing.T) { } func TestSelectNodeNonStrictARM(t *testing.T) { - r := makeTestResolver(map[string][]specs.Platform{ + r := makeTestResolver(map[string][]ocispecs.Platform{ "aaa": {platforms.MustParse("linux/amd64")}, "bbb": {platforms.MustParse("linux/arm64")}, "ccc": {platforms.MustParse("linux/arm/v8")}, }) - res, perfect, err := r.resolve(context.TODO(), []specs.Platform{platforms.MustParse("linux/arm/v8")}, nil, platforms.Only, nil) + res, perfect, err := r.resolve(context.TODO(), []ocispecs.Platform{platforms.MustParse("linux/arm/v8")}, nil, platforms.Only, nil) require.NoError(t, err) require.True(t, perfect) require.Len(t, res, 1) require.Equal(t, "ccc", res[0].Node().Builder) - res, perfect, err = r.resolve(context.TODO(), []specs.Platform{platforms.MustParse("linux/arm/v7")}, nil, platforms.Only, nil) + res, perfect, err = r.resolve(context.TODO(), []ocispecs.Platform{platforms.MustParse("linux/arm/v7")}, nil, platforms.Only, nil) require.NoError(t, err) require.True(t, perfect) require.Len(t, res, 1) @@ -170,20 +170,20 @@ func TestSelectNodeNonStrictARM(t *testing.T) { } func TestSelectNodeNonStrictLower(t *testing.T) { - r := makeTestResolver(map[string][]specs.Platform{ + r := makeTestResolver(map[string][]ocispecs.Platform{ "aaa": {platforms.MustParse("linux/amd64")}, "bbb": {platforms.MustParse("linux/arm/v7")}, }) // v8 can't be built on v7 (so we should select the default)... - res, perfect, err := r.resolve(context.TODO(), []specs.Platform{platforms.MustParse("linux/arm/v8")}, nil, platforms.Only, nil) + res, perfect, err := r.resolve(context.TODO(), []ocispecs.Platform{platforms.MustParse("linux/arm/v8")}, nil, platforms.Only, nil) require.NoError(t, err) require.False(t, perfect) require.Len(t, res, 1) require.Equal(t, "aaa", res[0].Node().Builder) // ...but v6 can be built on v8 - res, perfect, err = r.resolve(context.TODO(), []specs.Platform{platforms.MustParse("linux/arm/v6")}, nil, platforms.Only, nil) + res, perfect, err = r.resolve(context.TODO(), []ocispecs.Platform{platforms.MustParse("linux/arm/v6")}, nil, platforms.Only, nil) require.NoError(t, err) require.True(t, perfect) require.Len(t, res, 1) @@ -191,13 +191,13 @@ func TestSelectNodeNonStrictLower(t *testing.T) { } func TestSelectNodePreferStart(t *testing.T) { - r := makeTestResolver(map[string][]specs.Platform{ + r := makeTestResolver(map[string][]ocispecs.Platform{ "aaa": {platforms.MustParse("linux/amd64")}, "bbb": {platforms.MustParse("linux/riscv64")}, "ccc": {platforms.MustParse("linux/riscv64")}, }) - res, perfect, err := r.resolve(context.TODO(), []specs.Platform{platforms.MustParse("linux/riscv64")}, nil, platforms.Only, nil) + res, perfect, err := r.resolve(context.TODO(), []ocispecs.Platform{platforms.MustParse("linux/riscv64")}, nil, platforms.Only, nil) require.NoError(t, err) require.True(t, perfect) require.Len(t, res, 1) @@ -205,12 +205,12 @@ func TestSelectNodePreferStart(t *testing.T) { } func TestSelectNodePreferExact(t *testing.T) { - r := makeTestResolver(map[string][]specs.Platform{ + r := makeTestResolver(map[string][]ocispecs.Platform{ "aaa": {platforms.MustParse("linux/arm/v8")}, "bbb": {platforms.MustParse("linux/arm/v7")}, }) - res, perfect, err := r.resolve(context.TODO(), []specs.Platform{platforms.MustParse("linux/arm/v7")}, nil, platforms.Only, nil) + res, perfect, err := r.resolve(context.TODO(), []ocispecs.Platform{platforms.MustParse("linux/arm/v7")}, nil, platforms.Only, nil) require.NoError(t, err) require.True(t, perfect) require.Len(t, res, 1) @@ -218,12 +218,12 @@ func TestSelectNodePreferExact(t *testing.T) { } func TestSelectNodeNoPlatform(t *testing.T) { - r := makeTestResolver(map[string][]specs.Platform{ + r := makeTestResolver(map[string][]ocispecs.Platform{ "aaa": {platforms.MustParse("linux/foobar")}, "bbb": {platforms.DefaultSpec()}, }) - res, perfect, err := r.resolve(context.TODO(), []specs.Platform{}, nil, platforms.Only, nil) + res, perfect, err := r.resolve(context.TODO(), []ocispecs.Platform{}, nil, platforms.Only, nil) require.NoError(t, err) require.True(t, perfect) require.Len(t, res, 1) @@ -232,20 +232,20 @@ func TestSelectNodeNoPlatform(t *testing.T) { } func TestSelectNodeAdditionalPlatforms(t *testing.T) { - r := makeTestResolver(map[string][]specs.Platform{ + r := makeTestResolver(map[string][]ocispecs.Platform{ "aaa": {platforms.MustParse("linux/amd64")}, "bbb": {platforms.MustParse("linux/arm/v8")}, }) - res, perfect, err := r.resolve(context.TODO(), []specs.Platform{platforms.MustParse("linux/arm/v7")}, nil, platforms.Only, nil) + res, perfect, err := r.resolve(context.TODO(), []ocispecs.Platform{platforms.MustParse("linux/arm/v7")}, nil, platforms.Only, nil) require.NoError(t, err) require.True(t, perfect) require.Len(t, res, 1) require.Equal(t, "bbb", res[0].Node().Builder) - res, perfect, err = r.resolve(context.TODO(), []specs.Platform{platforms.MustParse("linux/arm/v7")}, nil, platforms.Only, func(idx int, n builder.Node) []specs.Platform { + res, perfect, err = r.resolve(context.TODO(), []ocispecs.Platform{platforms.MustParse("linux/arm/v7")}, nil, platforms.Only, func(idx int, n builder.Node) []ocispecs.Platform { if n.Builder == "aaa" { - return []specs.Platform{platforms.MustParse("linux/arm/v7")} + return []ocispecs.Platform{platforms.MustParse("linux/arm/v7")} } return nil }) @@ -256,12 +256,12 @@ func TestSelectNodeAdditionalPlatforms(t *testing.T) { } func TestSplitNodeMultiPlatform(t *testing.T) { - r := makeTestResolver(map[string][]specs.Platform{ + r := makeTestResolver(map[string][]ocispecs.Platform{ "aaa": {platforms.MustParse("linux/amd64"), platforms.MustParse("linux/arm64")}, "bbb": {platforms.MustParse("linux/riscv64")}, }) - res, perfect, err := r.resolve(context.TODO(), []specs.Platform{ + res, perfect, err := r.resolve(context.TODO(), []ocispecs.Platform{ platforms.MustParse("linux/amd64"), platforms.MustParse("linux/arm64"), }, nil, platforms.Only, nil) @@ -270,7 +270,7 @@ func TestSplitNodeMultiPlatform(t *testing.T) { require.Len(t, res, 1) require.Equal(t, "aaa", res[0].Node().Builder) - res, perfect, err = r.resolve(context.TODO(), []specs.Platform{ + res, perfect, err = r.resolve(context.TODO(), []ocispecs.Platform{ platforms.MustParse("linux/amd64"), platforms.MustParse("linux/riscv64"), }, nil, platforms.Only, nil) @@ -282,14 +282,14 @@ func TestSplitNodeMultiPlatform(t *testing.T) { } func TestSplitNodeMultiPlatformNoUnify(t *testing.T) { - r := makeTestResolver(map[string][]specs.Platform{ + r := makeTestResolver(map[string][]ocispecs.Platform{ "aaa": {platforms.MustParse("linux/amd64")}, "bbb": {platforms.MustParse("linux/amd64"), platforms.MustParse("linux/riscv64")}, }) // the "best" choice would be the node with both platforms, but we're using // a naive algorithm that doesn't try to unify the platforms - res, perfect, err := r.resolve(context.TODO(), []specs.Platform{ + res, perfect, err := r.resolve(context.TODO(), []ocispecs.Platform{ platforms.MustParse("linux/amd64"), platforms.MustParse("linux/riscv64"), }, nil, platforms.Only, nil) @@ -300,7 +300,7 @@ func TestSplitNodeMultiPlatformNoUnify(t *testing.T) { require.Equal(t, "bbb", res[1].Node().Builder) } -func makeTestResolver(nodes map[string][]specs.Platform) *nodeResolver { +func makeTestResolver(nodes map[string][]ocispecs.Platform) *nodeResolver { var ns []builder.Node for name, platforms := range nodes { ns = append(ns, builder.Node{ diff --git a/build/git.go b/build/git.go index 4672860ce..de30c5108 100644 --- a/build/git.go +++ b/build/git.go @@ -12,7 +12,7 @@ import ( "github.com/docker/buildx/util/gitutil" "github.com/docker/buildx/util/osutil" "github.com/moby/buildkit/client" - specs "github.com/opencontainers/image-spec/specs-go/v1" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" ) @@ -96,7 +96,7 @@ func getGitAttributes(ctx context.Context, contextPath, dockerfilePath string) ( sha += "-dirty" } if setGitLabels { - res["label:"+specs.AnnotationRevision] = sha + res["label:"+ocispecs.AnnotationRevision] = sha } if setGitInfo { res["vcs:revision"] = sha @@ -105,7 +105,7 @@ func getGitAttributes(ctx context.Context, contextPath, dockerfilePath string) ( if rurl, err := gitc.RemoteURL(); err == nil && rurl != "" { if setGitLabels { - res["label:"+specs.AnnotationSource] = rurl + res["label:"+ocispecs.AnnotationSource] = rurl } if setGitInfo { res["vcs:source"] = rurl diff --git a/build/git_test.go b/build/git_test.go index 1da16fb2a..9a9668bf0 100644 --- a/build/git_test.go +++ b/build/git_test.go @@ -11,7 +11,7 @@ import ( "github.com/docker/buildx/util/gitutil" "github.com/docker/buildx/util/gitutil/gittestutil" "github.com/moby/buildkit/client" - specs "github.com/opencontainers/image-spec/specs-go/v1" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -91,8 +91,8 @@ func TestGetGitAttributes(t *testing.T) { envGitInfo: "false", expected: []string{ "label:" + DockerfileLabel, - "label:" + specs.AnnotationRevision, - "label:" + specs.AnnotationSource, + "label:" + ocispecs.AnnotationRevision, + "label:" + ocispecs.AnnotationSource, }, }, { @@ -101,8 +101,8 @@ func TestGetGitAttributes(t *testing.T) { envGitInfo: "", expected: []string{ "label:" + DockerfileLabel, - "label:" + specs.AnnotationRevision, - "label:" + specs.AnnotationSource, + "label:" + ocispecs.AnnotationRevision, + "label:" + ocispecs.AnnotationSource, "vcs:revision", "vcs:source", }, @@ -125,9 +125,10 @@ func TestGetGitAttributes(t *testing.T) { for _, e := range tt.expected { assert.Contains(t, so.FrontendAttrs, e) assert.NotEmpty(t, so.FrontendAttrs[e]) - if e == "label:"+DockerfileLabel { + switch e { + case "label:" + DockerfileLabel: assert.Equal(t, "Dockerfile", so.FrontendAttrs[e]) - } else if e == "label:"+specs.AnnotationSource || e == "vcs:source" { + case "label:" + ocispecs.AnnotationSource, "vcs:source": assert.Equal(t, "git@github.com:docker/buildx.git", so.FrontendAttrs[e]) } } @@ -155,10 +156,10 @@ func TestGetGitAttributesDirty(t *testing.T) { assert.Contains(t, so.FrontendAttrs, "label:"+DockerfileLabel) assert.Equal(t, "Dockerfile", so.FrontendAttrs["label:"+DockerfileLabel]) - assert.Contains(t, so.FrontendAttrs, "label:"+specs.AnnotationSource) - assert.Equal(t, "git@github.com:docker/buildx.git", so.FrontendAttrs["label:"+specs.AnnotationSource]) - assert.Contains(t, so.FrontendAttrs, "label:"+specs.AnnotationRevision) - assert.True(t, strings.HasSuffix(so.FrontendAttrs["label:"+specs.AnnotationRevision], "-dirty")) + assert.Contains(t, so.FrontendAttrs, "label:"+ocispecs.AnnotationSource) + assert.Equal(t, "git@github.com:docker/buildx.git", so.FrontendAttrs["label:"+ocispecs.AnnotationSource]) + assert.Contains(t, so.FrontendAttrs, "label:"+ocispecs.AnnotationRevision) + assert.True(t, strings.HasSuffix(so.FrontendAttrs["label:"+ocispecs.AnnotationRevision], "-dirty")) assert.Contains(t, so.FrontendAttrs, "vcs:source") assert.Equal(t, "git@github.com:docker/buildx.git", so.FrontendAttrs["vcs:source"]) diff --git a/build/opt.go b/build/opt.go index 74fcdb381..ade779661 100644 --- a/build/opt.go +++ b/build/opt.go @@ -394,7 +394,7 @@ func loadInputs(ctx context.Context, d *driver.DriverHandle, inp *Inputs, pw pro if err != nil && err != io.EOF { return nil, errors.Wrap(err, "failed to peek context header from STDIN") } - if !(err == io.EOF && len(magic) == 0) { + if err != io.EOF || len(magic) != 0 { if isArchive(magic) { // stdin is context up := uploadprovider.New() diff --git a/build/result.go b/build/result.go index cb38fdcfa..904907cea 100644 --- a/build/result.go +++ b/build/result.go @@ -14,7 +14,7 @@ import ( "github.com/moby/buildkit/solver/errdefs" "github.com/moby/buildkit/solver/pb" "github.com/moby/buildkit/solver/result" - specs "github.com/opencontainers/image-spec/specs-go/v1" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" "github.com/sirupsen/logrus" "golang.org/x/sync/errgroup" @@ -354,9 +354,9 @@ func containerConfigFromResult(res *gateway.Result, cfg *controllerapi.InvokeCon func populateProcessConfigFromResult(req *gateway.StartRequest, res *gateway.Result, cfg *controllerapi.InvokeConfig) error { imgData := res.Metadata[exptypes.ExporterImageConfigKey] - var img *specs.Image + var img *ocispecs.Image if len(imgData) > 0 { - img = &specs.Image{} + img = &ocispecs.Image{} if err := json.Unmarshal(imgData, img); err != nil { return err } @@ -410,9 +410,9 @@ func containerConfigFromError(solveErr *errdefs.SolveError, cfg *controllerapi.I } var mounts []gateway.Mount for i, mnt := range exec.Mounts { - rid := solveErr.Solve.MountIDs[i] + rid := solveErr.MountIDs[i] if cfg.Initial { - rid = solveErr.Solve.InputIDs[i] + rid = solveErr.InputIDs[i] } mounts = append(mounts, gateway.Mount{ Selector: mnt.Selector, @@ -477,7 +477,7 @@ func execOpFromError(solveErr *errdefs.SolveError) (*pb.ExecOp, error) { if solveErr == nil { return nil, errors.Errorf("no error is available") } - switch op := solveErr.Solve.Op.GetOp().(type) { + switch op := solveErr.Op.GetOp().(type) { case *pb.Op_Exec: return op.Exec, nil default: diff --git a/builder/builder.go b/builder/builder.go index d82af2109..d26c42379 100644 --- a/builder/builder.go +++ b/builder/builder.go @@ -122,7 +122,7 @@ func New(dockerCli command.Cli, opts ...Option) (_ *Builder, err error) { // Validate validates builder context func (b *Builder) Validate() error { - if b.NodeGroup != nil && b.NodeGroup.DockerContext { + if b.NodeGroup != nil && b.DockerContext { list, err := b.opts.dockerCli.ContextStore().List() if err != nil { return err @@ -144,7 +144,7 @@ func (b *Builder) ContextName() string { return "" } for _, cb := range ctxbuilders { - if b.NodeGroup.Driver == "docker" && len(b.NodeGroup.Nodes) == 1 && b.NodeGroup.Nodes[0].Endpoint == cb.Name { + if b.Driver == "docker" && len(b.NodeGroup.Nodes) == 1 && b.NodeGroup.Nodes[0].Endpoint == cb.Name { return cb.Name } } @@ -254,7 +254,7 @@ func (b *Builder) Factory(ctx context.Context, dialMeta map[string][]string) (_ if err != nil { return } - b.Driver = b.driverFactory.Factory.Name() + b.Driver = b.driverFactory.Name() } }) return b.driverFactory.Factory, err @@ -309,7 +309,7 @@ func GetBuilders(dockerCli command.Cli, txn *store.Txn) ([]*Builder, error) { return nil, err } builders[i] = b - seen[b.NodeGroup.Name] = struct{}{} + seen[b.Name] = struct{}{} } for _, c := range contexts { @@ -524,7 +524,7 @@ func Create(ctx context.Context, txn *store.Txn, dockerCli command.Cli, opts Cre } cancelCtx, cancel := context.WithCancelCause(ctx) - timeoutCtx, _ := context.WithTimeoutCause(cancelCtx, 20*time.Second, errors.WithStack(context.DeadlineExceeded)) //nolint:govet,lostcancel // no need to manually cancel this context as we already rely on parent + timeoutCtx, _ := context.WithTimeoutCause(cancelCtx, 20*time.Second, errors.WithStack(context.DeadlineExceeded)) //nolint:govet // no need to manually cancel this context as we already rely on parent defer func() { cancel(errors.WithStack(context.Canceled)) }() nodes, err := b.LoadNodes(timeoutCtx, WithData()) diff --git a/builder/node.go b/builder/node.go index b582503bb..b1bccbf77 100644 --- a/builder/node.go +++ b/builder/node.go @@ -183,7 +183,7 @@ func (b *Builder) LoadNodes(ctx context.Context, opts ...LoadNodesOption) (_ []N // not append (remove the static nodes in the store) b.NodeGroup.Nodes = dynamicNodes b.nodes = nodes - b.NodeGroup.Dynamic = true + b.Dynamic = true } } diff --git a/commands/bake.go b/commands/bake.go index 49a23c673..e34dbb843 100644 --- a/commands/bake.go +++ b/commands/bake.go @@ -136,7 +136,7 @@ func runBake(ctx context.Context, dockerCli command.Cli, targets []string, in ba // instance only needed for reading remote bake files or building var driverType string - if url != "" || !(in.print || in.list != "") { + if url != "" || (!in.print && in.list == "") { b, err := builder.New(dockerCli, builder.WithName(in.builder), builder.WithContextPathHash(contextPathHash), diff --git a/commands/dial_stdio.go b/commands/dial_stdio.go index 42c0e365a..92024955f 100644 --- a/commands/dial_stdio.go +++ b/commands/dial_stdio.go @@ -12,7 +12,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/moby/buildkit/util/appcontext" "github.com/moby/buildkit/util/progress/progressui" - v1 "github.com/opencontainers/image-spec/specs-go/v1" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" "github.com/spf13/cobra" "golang.org/x/sync/errgroup" @@ -49,7 +49,7 @@ func runDialStdio(dockerCli command.Cli, opts stdioOptions) error { return err } - var p *v1.Platform + var p *ocispecs.Platform if opts.platform != "" { pp, err := platforms.Parse(opts.platform) if err != nil { diff --git a/commands/history/inspect.go b/commands/history/inspect.go index 0704e2f6a..bbce952a9 100644 --- a/commands/history/inspect.go +++ b/commands/history/inspect.go @@ -335,9 +335,9 @@ workers0: out.Error.Sources = errsources.Bytes() var ve *errdefs.VertexError if errors.As(retErr, &ve) { - dgst, err := digest.Parse(ve.Vertex.Digest) + dgst, err := digest.Parse(ve.Digest) if err != nil { - return errors.Wrapf(err, "failed to parse vertex digest %s", ve.Vertex.Digest) + return errors.Wrapf(err, "failed to parse vertex digest %s", ve.Digest) } name, logs, err := loadVertexLogs(ctx, c, rec.Ref, dgst, 16) if err != nil { @@ -525,9 +525,10 @@ workers0: } fmt.Fprintf(tw, "Duration:\t%s%s\n", formatDuration(out.Duration), statusStr) - if out.Status == statusError { + switch out.Status { + case statusError: fmt.Fprintf(tw, "Error:\t%s %s\n", codes.Code(rec.Error.Code).String(), rec.Error.Message) - } else if out.Status == statusCanceled { + case statusCanceled: fmt.Fprintf(tw, "Status:\tCanceled\n") } diff --git a/commands/history/logs.go b/commands/history/logs.go index bd58ba9e6..1c52d5260 100644 --- a/commands/history/logs.go +++ b/commands/history/logs.go @@ -63,7 +63,7 @@ func runLogs(ctx context.Context, dockerCli command.Cli, opts logsOptions) error return err } - var mode progressui.DisplayMode = progressui.DisplayMode(opts.progress) + mode := progressui.DisplayMode(opts.progress) if mode == progressui.AutoMode { mode = progressui.PlainMode } diff --git a/commands/imagetools/create.go b/commands/imagetools/create.go index fee838c64..2f08436d2 100644 --- a/commands/imagetools/create.go +++ b/commands/imagetools/create.go @@ -16,7 +16,7 @@ import ( "github.com/docker/cli/cli/command" "github.com/moby/buildkit/util/progress/progressui" "github.com/opencontainers/go-digest" - ocispec "github.com/opencontainers/image-spec/specs-go/v1" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" "github.com/spf13/cobra" "golang.org/x/sync/errgroup" @@ -246,7 +246,7 @@ func parseSource(in string) (*imagetools.Source, error) { dgst, err := digest.Parse(in) if err == nil { return &imagetools.Source{ - Desc: ocispec.Descriptor{ + Desc: ocispecs.Descriptor{ Digest: dgst, }, }, nil @@ -295,9 +295,9 @@ func createCmd(dockerCli command.Cli, opts RootOptions) *cobra.Command { return cmd } -func mergeDesc(d1, d2 ocispec.Descriptor) (ocispec.Descriptor, error) { +func mergeDesc(d1, d2 ocispecs.Descriptor) (ocispecs.Descriptor, error) { if d2.Size != 0 && d1.Size != d2.Size { - return ocispec.Descriptor{}, errors.Errorf("invalid size mismatch for %s, %d != %d", d1.Digest, d2.Size, d1.Size) + return ocispecs.Descriptor{}, errors.Errorf("invalid size mismatch for %s, %d != %d", d1.Digest, d2.Size, d1.Size) } if d2.MediaType != "" { d1.MediaType = d2.MediaType diff --git a/commands/inspect.go b/commands/inspect.go index eeae99ea1..06c0da4e2 100644 --- a/commands/inspect.go +++ b/commands/inspect.go @@ -36,7 +36,7 @@ func runInspect(ctx context.Context, dockerCli command.Cli, in inspectOptions) e } timeoutCtx, cancel := context.WithCancelCause(ctx) - timeoutCtx, _ = context.WithTimeoutCause(timeoutCtx, 20*time.Second, errors.WithStack(context.DeadlineExceeded)) //nolint:govet,lostcancel // no need to manually cancel this context as we already rely on parent + timeoutCtx, _ = context.WithTimeoutCause(timeoutCtx, 20*time.Second, errors.WithStack(context.DeadlineExceeded)) //nolint:govet // no need to manually cancel this context as we already rely on parent defer func() { cancel(errors.WithStack(context.Canceled)) }() nodes, err := b.LoadNodes(timeoutCtx, builder.WithData()) @@ -54,8 +54,8 @@ func runInspect(ctx context.Context, dockerCli command.Cli, in inspectOptions) e w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0) fmt.Fprintf(w, "Name:\t%s\n", b.Name) fmt.Fprintf(w, "Driver:\t%s\n", b.Driver) - if !b.NodeGroup.LastActivity.IsZero() { - fmt.Fprintf(w, "Last Activity:\t%v\n", b.NodeGroup.LastActivity) + if !b.LastActivity.IsZero() { + fmt.Fprintf(w, "Last Activity:\t%v\n", b.LastActivity) } if err != nil { diff --git a/commands/ls.go b/commands/ls.go index 8c247679d..c5a27bd2c 100644 --- a/commands/ls.go +++ b/commands/ls.go @@ -60,7 +60,7 @@ func runLs(ctx context.Context, dockerCli command.Cli, in lsOptions) error { } timeoutCtx, cancel := context.WithCancelCause(ctx) - timeoutCtx, _ = context.WithTimeoutCause(timeoutCtx, 20*time.Second, errors.WithStack(context.DeadlineExceeded)) //nolint:govet,lostcancel // no need to manually cancel this context as we already rely on parent + timeoutCtx, _ = context.WithTimeoutCause(timeoutCtx, 20*time.Second, errors.WithStack(context.DeadlineExceeded)) //nolint:govet // no need to manually cancel this context as we already rely on parent defer func() { cancel(errors.WithStack(context.Canceled)) }() eg, _ := errgroup.WithContext(timeoutCtx) diff --git a/commands/rm.go b/commands/rm.go index cabbe9aa5..81ddd11d7 100644 --- a/commands/rm.go +++ b/commands/rm.go @@ -151,7 +151,7 @@ func rmAllInactive(ctx context.Context, txn *store.Txn, dockerCli command.Cli, i } timeoutCtx, cancel := context.WithCancelCause(ctx) - timeoutCtx, _ = context.WithTimeoutCause(timeoutCtx, 20*time.Second, errors.WithStack(context.DeadlineExceeded)) //nolint:govet,lostcancel // no need to manually cancel this context as we already rely on parent + timeoutCtx, _ = context.WithTimeoutCause(timeoutCtx, 20*time.Second, errors.WithStack(context.DeadlineExceeded)) //nolint:govet // no need to manually cancel this context as we already rely on parent defer func() { cancel(errors.WithStack(context.Canceled)) }() eg, _ := errgroup.WithContext(timeoutCtx) diff --git a/docker-bake.hcl b/docker-bake.hcl index a65973faf..a3576c73e 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -38,6 +38,9 @@ target "lint" { inherits = ["_common"] dockerfile = "./hack/dockerfiles/lint.Dockerfile" output = ["type=cacheonly"] + args = { + GOLANGCI_FROM_SOURCE = "true" + } platforms = GOLANGCI_LINT_MULTIPLATFORM != "" ? [ "darwin/amd64", "darwin/arm64", diff --git a/driver/docker-container/driver.go b/driver/docker-container/driver.go index cfcdf67cc..fc964dd99 100644 --- a/driver/docker-container/driver.go +++ b/driver/docker-container/driver.go @@ -138,28 +138,28 @@ func (d *Driver) create(ctx context.Context, l progress.SubLogger) error { hc.NetworkMode = container.NetworkMode(d.netMode) } if d.memory != 0 { - hc.Resources.Memory = int64(d.memory) + hc.Memory = int64(d.memory) } if d.memorySwap != 0 { - hc.Resources.MemorySwap = int64(d.memorySwap) + hc.MemorySwap = int64(d.memorySwap) } if d.cpuQuota != 0 { - hc.Resources.CPUQuota = d.cpuQuota + hc.CPUQuota = d.cpuQuota } if d.cpuPeriod != 0 { - hc.Resources.CPUPeriod = d.cpuPeriod + hc.CPUPeriod = d.cpuPeriod } if d.cpuShares != 0 { - hc.Resources.CPUShares = d.cpuShares + hc.CPUShares = d.cpuShares } if d.cpusetCpus != "" { - hc.Resources.CpusetCpus = d.cpusetCpus + hc.CpusetCpus = d.cpusetCpus } if d.cpusetMems != "" { - hc.Resources.CpusetMems = d.cpusetMems + hc.CpusetMems = d.cpusetMems } if len(d.gpus) > 0 && d.hasGPUCapability(ctx, cfg.Image, d.gpus) { - hc.Resources.DeviceRequests = d.gpus + hc.DeviceRequests = d.gpus } if info, err := d.DockerAPI.Info(ctx); err == nil { if info.CgroupDriver == "cgroupfs" { @@ -187,7 +187,7 @@ func (d *Driver) create(ctx context.Context, l progress.SubLogger) error { return err } if err == nil { - if err := d.copyToContainer(ctx, d.InitConfig.Files); err != nil { + if err := d.copyToContainer(ctx, d.Files); err != nil { return err } if err := d.start(ctx); err != nil { diff --git a/driver/kubernetes/manifest/manifest.go b/driver/kubernetes/manifest/manifest.go index 1137badb7..dfc51bbd9 100644 --- a/driver/kubernetes/manifest/manifest.go +++ b/driver/kubernetes/manifest/manifest.go @@ -6,7 +6,7 @@ import ( "strings" "github.com/docker/buildx/util/platformutil" - v1 "github.com/opencontainers/image-spec/specs-go/v1" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/resource" @@ -43,7 +43,7 @@ type DeploymentOpt struct { LimitsCPU string LimitsMemory string LimitsEphemeralStorage string - Platforms []v1.Platform + Platforms []ocispecs.Platform } const ( @@ -260,10 +260,10 @@ func toRootless(d *appsv1.Deployment) error { Type: corev1.SeccompProfileTypeUnconfined, }, } - if d.Spec.Template.ObjectMeta.Annotations == nil { - d.Spec.Template.ObjectMeta.Annotations = make(map[string]string, 1) + if d.Spec.Template.Annotations == nil { + d.Spec.Template.Annotations = make(map[string]string, 1) } - d.Spec.Template.ObjectMeta.Annotations["container.apparmor.security.beta.kubernetes.io/"+containerName] = "unconfined" + d.Spec.Template.Annotations["container.apparmor.security.beta.kubernetes.io/"+containerName] = "unconfined" // Dockerfile has `VOLUME /home/user/.local/share/buildkit` by default too, // but the default VOLUME does not work with rootless on Google's Container-Optimized OS diff --git a/driver/manager.go b/driver/manager.go index 400a0cdd7..fcc94c728 100644 --- a/driver/manager.go +++ b/driver/manager.go @@ -9,7 +9,7 @@ import ( dockerclient "github.com/docker/docker/client" "github.com/moby/buildkit/client" "github.com/moby/buildkit/util/tracing/delegated" - specs "github.com/opencontainers/image-spec/specs-go/v1" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" ) @@ -35,7 +35,7 @@ type InitConfig struct { Files map[string][]byte DriverOpts map[string]string Auth Auth - Platforms []specs.Platform + Platforms []ocispecs.Platform ContextPathHash string DialMeta map[string][]string } diff --git a/driver/remote/driver.go b/driver/remote/driver.go index 22145dd62..495a487e0 100644 --- a/driver/remote/driver.go +++ b/driver/remote/driver.go @@ -48,7 +48,7 @@ func (d *Driver) Bootstrap(ctx context.Context, l progress.Logger) error { } return progress.Wrap("[internal] waiting for connection", l, func(_ progress.SubLogger) error { cancelCtx, cancel := context.WithCancelCause(ctx) - ctx, _ := context.WithTimeoutCause(cancelCtx, 20*time.Second, errors.WithStack(context.DeadlineExceeded)) //nolint:govet,lostcancel // no need to manually cancel this context as we already rely on parent + ctx, _ := context.WithTimeoutCause(cancelCtx, 20*time.Second, errors.WithStack(context.DeadlineExceeded)) //nolint:govet // no need to manually cancel this context as we already rely on parent defer func() { cancel(errors.WithStack(context.Canceled)) }() return c.Wait(ctx) }) @@ -101,7 +101,7 @@ func (d *Driver) Client(ctx context.Context, opts ...client.ClientOpt) (*client. } func (d *Driver) Dial(ctx context.Context) (net.Conn, error) { - addr := d.InitConfig.EndpointAddr + addr := d.EndpointAddr ch, err := connhelper.GetConnectionHelper(addr) if err != nil { return nil, err @@ -112,7 +112,7 @@ func (d *Driver) Dial(ctx context.Context) (net.Conn, error) { network, addr, ok := strings.Cut(addr, "://") if !ok { - return nil, errors.Errorf("invalid endpoint address: %s", d.InitConfig.EndpointAddr) + return nil, errors.Errorf("invalid endpoint address: %s", d.EndpointAddr) } conn, err := util.DialContext(ctx, network, addr) diff --git a/hack/dockerfiles/lint.Dockerfile b/hack/dockerfiles/lint.Dockerfile index b94657be9..14e8a5bcc 100644 --- a/hack/dockerfiles/lint.Dockerfile +++ b/hack/dockerfiles/lint.Dockerfile @@ -4,7 +4,7 @@ ARG GO_VERSION=1.23 ARG ALPINE_VERSION=3.21 ARG XX_VERSION=1.6.1 -ARG GOLANGCI_LINT_VERSION=v1.62.0 +ARG GOLANGCI_LINT_VERSION=v2.1.5 ARG GOLANGCI_FROM_SOURCE=false # v0.31 requires go1.24 ARG GOPLS_VERSION=v0.30.0 diff --git a/store/nodegroup.go b/store/nodegroup.go index 9d986d17b..8c78acc1c 100644 --- a/store/nodegroup.go +++ b/store/nodegroup.go @@ -9,7 +9,7 @@ import ( "github.com/containerd/platforms" "github.com/docker/buildx/util/confutil" "github.com/docker/buildx/util/platformutil" - specs "github.com/opencontainers/image-spec/specs-go/v1" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" "github.com/sirupsen/logrus" ) @@ -28,7 +28,7 @@ type NodeGroup struct { type Node struct { Name string Endpoint string - Platforms []specs.Platform + Platforms []ocispecs.Platform DriverOpts map[string]string BuildkitdFlags []string `json:"Flags"` // keep the field name for backward compatibility @@ -141,7 +141,7 @@ func (ng *NodeGroup) Copy() *NodeGroup { } func (n *Node) Copy() *Node { - platforms := []specs.Platform{} + platforms := []ocispecs.Platform{} copy(platforms, n.Platforms) buildkitdFlags := []string{} copy(buildkitdFlags, n.BuildkitdFlags) @@ -210,8 +210,8 @@ func (ng *NodeGroup) nextNodeName() string { } } -func filterPlatforms(in []specs.Platform, m map[string]struct{}) []specs.Platform { - out := make([]specs.Platform, 0, len(in)) +func filterPlatforms(in []ocispecs.Platform, m map[string]struct{}) []ocispecs.Platform { + out := make([]ocispecs.Platform, 0, len(in)) for _, p := range in { if _, ok := m[platforms.Format(p)]; !ok { out = append(out, p) diff --git a/util/imagetools/create.go b/util/imagetools/create.go index 9b1ca6b48..91afce356 100644 --- a/util/imagetools/create.go +++ b/util/imagetools/create.go @@ -18,17 +18,17 @@ import ( "github.com/moby/buildkit/util/contentutil" "github.com/opencontainers/go-digest" "github.com/opencontainers/image-spec/specs-go" - ocispec "github.com/opencontainers/image-spec/specs-go/v1" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" "golang.org/x/sync/errgroup" ) type Source struct { - Desc ocispec.Descriptor + Desc ocispecs.Descriptor Ref reference.Named } -func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann map[exptypes.AnnotationKey]string, preferIndex bool) ([]byte, ocispec.Descriptor, error) { +func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann map[exptypes.AnnotationKey]string, preferIndex bool) ([]byte, ocispecs.Descriptor, error) { eg, ctx := errgroup.WithContext(ctx) dts := make([][]byte, len(srcs)) @@ -52,10 +52,10 @@ func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann map[exptypes mt := srcs[i].Desc.MediaType switch mt { - case images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest: + case images.MediaTypeDockerSchema2Manifest, ocispecs.MediaTypeImageManifest: p := srcs[i].Desc.Platform if srcs[i].Desc.Platform == nil { - p = &ocispec.Platform{} + p = &ocispecs.Platform{} } if p.OS == "" || p.Architecture == "" { if err := r.loadPlatform(ctx, p, srcs[i].Ref.String(), dt); err != nil { @@ -73,7 +73,7 @@ func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann map[exptypes } if err := eg.Wait(); err != nil { - return nil, ocispec.Descriptor{}, err + return nil, ocispecs.Descriptor{}, err } // on single source, return original bytes @@ -82,7 +82,7 @@ func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann map[exptypes // if the source is already an image index or manifest list, there is no need to consider the value // of preferIndex since if set to true then the source is already in the preferred format, and if false // it doesn't matter since we're not going to split it into separate manifests - case images.MediaTypeDockerSchema2ManifestList, ocispec.MediaTypeImageIndex: + case images.MediaTypeDockerSchema2ManifestList, ocispecs.MediaTypeImageIndex: return dts[0], srcs[0].Desc, nil default: if !preferIndex { @@ -92,9 +92,9 @@ func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann map[exptypes } m := map[digest.Digest]int{} - newDescs := make([]ocispec.Descriptor, 0, len(srcs)) + newDescs := make([]ocispecs.Descriptor, 0, len(srcs)) - addDesc := func(d ocispec.Descriptor) { + addDesc := func(d ocispecs.Descriptor) { idx, ok := m[d.Digest] if ok { old := newDescs[idx] @@ -117,10 +117,10 @@ func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann map[exptypes for i, src := range srcs { switch src.Desc.MediaType { - case images.MediaTypeDockerSchema2ManifestList, ocispec.MediaTypeImageIndex: - var mfst ocispec.Index + case images.MediaTypeDockerSchema2ManifestList, ocispecs.MediaTypeImageIndex: + var mfst ocispecs.Index if err := json.Unmarshal(dts[i], &mfst); err != nil { - return nil, ocispec.Descriptor{}, errors.WithStack(err) + return nil, ocispecs.Descriptor{}, errors.WithStack(err) } for _, d := range mfst.Manifests { addDesc(d) @@ -143,12 +143,12 @@ func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann map[exptypes mt = images.MediaTypeDockerSchema2ManifestList } else { // otherwise, use OCI index - mt = ocispec.MediaTypeImageIndex + mt = ocispecs.MediaTypeImageIndex } // annotations are only allowed on OCI indexes indexAnnotation := make(map[string]string) - if mt == ocispec.MediaTypeImageIndex { + if mt == ocispecs.MediaTypeImageIndex { for k, v := range ann { switch k.Type { case exptypes.AnnotationIndex: @@ -163,14 +163,14 @@ func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann map[exptypes } } case exptypes.AnnotationManifest, "": - return nil, ocispec.Descriptor{}, errors.Errorf("%q annotations are not supported yet", k.Type) + return nil, ocispecs.Descriptor{}, errors.Errorf("%q annotations are not supported yet", k.Type) case exptypes.AnnotationIndexDescriptor: - return nil, ocispec.Descriptor{}, errors.Errorf("%q annotations are invalid while creating an image", k.Type) + return nil, ocispecs.Descriptor{}, errors.Errorf("%q annotations are invalid while creating an image", k.Type) } } } - idxBytes, err := json.MarshalIndent(ocispec.Index{ + idxBytes, err := json.MarshalIndent(ocispecs.Index{ MediaType: mt, Versioned: specs.Versioned{ SchemaVersion: 2, @@ -179,17 +179,17 @@ func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann map[exptypes Annotations: indexAnnotation, }, "", " ") if err != nil { - return nil, ocispec.Descriptor{}, errors.Wrap(err, "failed to marshal index") + return nil, ocispecs.Descriptor{}, errors.Wrap(err, "failed to marshal index") } - return idxBytes, ocispec.Descriptor{ + return idxBytes, ocispecs.Descriptor{ MediaType: mt, Size: int64(len(idxBytes)), Digest: digest.FromBytes(idxBytes), }, nil } -func (r *Resolver) Push(ctx context.Context, ref reference.Named, desc ocispec.Descriptor, dt []byte) error { +func (r *Resolver) Push(ctx context.Context, ref reference.Named, desc ocispecs.Descriptor, dt []byte) error { ctx = remotes.WithMediaTypeKeyPrefix(ctx, "application/vnd.in-toto+json", "intoto") fullRef, err := reference.WithDigest(reference.TagNameOnly(ref), desc.Digest) @@ -252,8 +252,8 @@ func (r *Resolver) Copy(ctx context.Context, src *Source, dest reference.Named) return nil } -func (r *Resolver) loadPlatform(ctx context.Context, p2 *ocispec.Platform, in string, dt []byte) error { - var manifest ocispec.Manifest +func (r *Resolver) loadPlatform(ctx context.Context, p2 *ocispecs.Platform, in string, dt []byte) error { + var manifest ocispecs.Manifest if err := json.Unmarshal(dt, &manifest); err != nil { return errors.WithStack(err) } @@ -263,7 +263,7 @@ func (r *Resolver) loadPlatform(ctx context.Context, p2 *ocispec.Platform, in st return err } - var p ocispec.Platform + var p ocispecs.Platform if err := json.Unmarshal(dt, &p); err != nil { return errors.WithStack(err) } diff --git a/util/imagetools/imagetools_helpers_test.go b/util/imagetools/imagetools_helpers_test.go index 925b9e700..8ac639c1e 100644 --- a/util/imagetools/imagetools_helpers_test.go +++ b/util/imagetools/imagetools_helpers_test.go @@ -12,8 +12,7 @@ import ( intoto "github.com/in-toto/in-toto-golang/in_toto" slsa02 "github.com/in-toto/in-toto-golang/in_toto/slsa_provenance/v0.2" "github.com/opencontainers/go-digest" - ocispec "github.com/opencontainers/image-spec/specs-go/v1" - v1 "github.com/opencontainers/image-spec/specs-go/v1" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" ) type attestationType int @@ -35,12 +34,12 @@ type mockResolver struct { var manifests = make(map[digest.Digest]manifest) var indexes = make(map[digest.Digest]index) -func (f mockFetcher) Fetch(ctx context.Context, desc ocispec.Descriptor) (io.ReadCloser, error) { +func (f mockFetcher) Fetch(ctx context.Context, desc ocispecs.Descriptor) (io.ReadCloser, error) { switch desc.MediaType { - case ocispec.MediaTypeImageIndex: + case ocispecs.MediaTypeImageIndex: reader := io.NopCloser(strings.NewReader(indexes[desc.Digest].desc.Annotations["test_content"])) return reader, nil - case ocispec.MediaTypeImageManifest: + case ocispecs.MediaTypeImageManifest: reader := io.NopCloser(strings.NewReader(manifests[desc.Digest].desc.Annotations["test_content"])) return reader, nil default: @@ -49,7 +48,7 @@ func (f mockFetcher) Fetch(ctx context.Context, desc ocispec.Descriptor) (io.Rea } } -func (r mockResolver) Resolve(ctx context.Context, ref string) (name string, desc ocispec.Descriptor, err error) { +func (r mockResolver) Resolve(ctx context.Context, ref string) (name string, desc ocispecs.Descriptor, err error) { d := digest.Digest(strings.ReplaceAll(ref, "docker.io/library/test@", "")) return string(d), indexes[d].desc, nil } @@ -77,8 +76,8 @@ func getImageNoAttestation() *result { func getImageWithAttestation(t attestationType) *result { manifestList := getBaseManifests() - objManifest := ocispec.Manifest{ - MediaType: v1.MediaTypeImageManifest, + objManifest := ocispecs.Manifest{ + MediaType: ocispecs.MediaTypeImageManifest, Layers: getAttestationLayers(t), Annotations: map[string]string{ "platform": "linux/amd64", @@ -89,8 +88,8 @@ func getImageWithAttestation(t attestationType) *result { d := digest.FromString(jsonString) manifestList[d] = manifest{ - desc: ocispec.Descriptor{ - MediaType: v1.MediaTypeImageManifest, + desc: ocispecs.Descriptor{ + MediaType: ocispecs.MediaTypeImageManifest, Digest: d, Size: int64(len(jsonString)), Annotations: map[string]string{ @@ -98,7 +97,7 @@ func getImageWithAttestation(t attestationType) *result { "vnd.docker.reference.type": "attestation-manifest", "test_content": jsonString, }, - Platform: &v1.Platform{ + Platform: &ocispecs.Platform{ Architecture: "unknown", OS: "unknown", }, @@ -106,8 +105,8 @@ func getImageWithAttestation(t attestationType) *result { manifest: objManifest, } - objManifest = ocispec.Manifest{ - MediaType: v1.MediaTypeImageManifest, + objManifest = ocispecs.Manifest{ + MediaType: ocispecs.MediaTypeImageManifest, Layers: getAttestationLayers(t), Annotations: map[string]string{ "platform": "linux/arm64", @@ -117,8 +116,8 @@ func getImageWithAttestation(t attestationType) *result { jsonString = string(jsonContent) d = digest.FromString(jsonString) manifestList[d] = manifest{ - desc: ocispec.Descriptor{ - MediaType: v1.MediaTypeImageManifest, + desc: ocispecs.Descriptor{ + MediaType: ocispecs.MediaTypeImageManifest, Digest: d, Size: int64(len(jsonString)), Annotations: map[string]string{ @@ -126,7 +125,7 @@ func getImageWithAttestation(t attestationType) *result { "vnd.docker.reference.type": "attestation-manifest", "test_content": jsonString, }, - Platform: &v1.Platform{ + Platform: &ocispecs.Platform{ Architecture: "unknown", OS: "unknown", }, @@ -148,13 +147,13 @@ func getImageFromManifests(manifests map[digest.Digest]manifest) *result { r.images["linux/amd64"] = getManifestDigestForArch(manifests, "linux", "amd64") r.images["linux/arm64"] = getManifestDigestForArch(manifests, "linux", "arm64") - manifestsDesc := []v1.Descriptor{} + manifestsDesc := []ocispecs.Descriptor{} for _, val := range manifests { manifestsDesc = append(manifestsDesc, val.desc) } - objIndex := v1.Index{ - MediaType: v1.MediaTypeImageIndex, + objIndex := ocispecs.Index{ + MediaType: ocispecs.MediaTypeImageIndex, Manifests: manifestsDesc, } jsonContent, _ := json.Marshal(objIndex) @@ -163,8 +162,8 @@ func getImageFromManifests(manifests map[digest.Digest]manifest) *result { if _, ok := indexes[d]; !ok { indexes[d] = index{ - desc: ocispec.Descriptor{ - MediaType: v1.MediaTypeImageIndex, + desc: ocispecs.Descriptor{ + MediaType: ocispecs.MediaTypeImageIndex, Digest: d, Size: int64(len(jsonString)), Annotations: map[string]string{ @@ -193,12 +192,12 @@ func getBaseManifests() map[digest.Digest]manifest { if len(manifests) == 0 { config := getConfig() content := "amd64-content" - objManifest := ocispec.Manifest{ - MediaType: v1.MediaTypeImageManifest, + objManifest := ocispecs.Manifest{ + MediaType: ocispecs.MediaTypeImageManifest, Config: config, - Layers: []v1.Descriptor{ + Layers: []ocispecs.Descriptor{ { - MediaType: v1.MediaTypeImageLayerGzip, + MediaType: ocispecs.MediaTypeImageLayerGzip, Digest: digest.FromString(content), Size: int64(len(content)), }, @@ -209,11 +208,11 @@ func getBaseManifests() map[digest.Digest]manifest { d := digest.FromString(jsonString) manifests[d] = manifest{ - desc: ocispec.Descriptor{ - MediaType: v1.MediaTypeImageManifest, + desc: ocispecs.Descriptor{ + MediaType: ocispecs.MediaTypeImageManifest, Digest: d, Size: int64(len(jsonString)), - Platform: &v1.Platform{ + Platform: &ocispecs.Platform{ Architecture: "amd64", OS: "linux", }, @@ -225,12 +224,12 @@ func getBaseManifests() map[digest.Digest]manifest { } content = "arm64-content" - objManifest = ocispec.Manifest{ - MediaType: v1.MediaTypeImageManifest, + objManifest = ocispecs.Manifest{ + MediaType: ocispecs.MediaTypeImageManifest, Config: config, - Layers: []v1.Descriptor{ + Layers: []ocispecs.Descriptor{ { - MediaType: v1.MediaTypeImageLayerGzip, + MediaType: ocispecs.MediaTypeImageLayerGzip, Digest: digest.FromString(content), Size: int64(len(content)), }, @@ -241,11 +240,11 @@ func getBaseManifests() map[digest.Digest]manifest { d = digest.FromString(jsonString) manifests[d] = manifest{ - desc: ocispec.Descriptor{ - MediaType: v1.MediaTypeImageManifest, + desc: ocispecs.Descriptor{ + MediaType: ocispecs.MediaTypeImageManifest, Digest: d, Size: int64(len(jsonString)), - Platform: &v1.Platform{ + Platform: &ocispecs.Platform{ Architecture: "arm64", OS: "linux", }, @@ -260,8 +259,8 @@ func getBaseManifests() map[digest.Digest]manifest { return manifests } -func getConfig() v1.Descriptor { - config := v1.ImageConfig{ +func getConfig() ocispecs.Descriptor { + config := ocispecs.ImageConfig{ Env: []string{ "config", }, @@ -270,8 +269,8 @@ func getConfig() v1.Descriptor { jsonString := string(jsonContent) d := digest.FromString(jsonString) - return v1.Descriptor{ - MediaType: ocispec.MediaTypeImageConfig, + return ocispecs.Descriptor{ + MediaType: ocispecs.MediaTypeImageConfig, Digest: d, Size: int64(len(jsonString)), Annotations: map[string]string{ @@ -280,11 +279,11 @@ func getConfig() v1.Descriptor { } } -func getAttestationLayers(t attestationType) []v1.Descriptor { - layers := []v1.Descriptor{} +func getAttestationLayers(t attestationType) []ocispecs.Descriptor { + layers := []ocispecs.Descriptor{} if t == plainSpdx || t == plainSpdxAndDSSEEmbed { - layers = append(layers, v1.Descriptor{ + layers = append(layers, ocispecs.Descriptor{ MediaType: inTotoGenericMime, Digest: digest.FromString(attestationContent), Size: int64(len(attestationContent)), @@ -293,7 +292,7 @@ func getAttestationLayers(t attestationType) []v1.Descriptor { "test_content": attestationContent, }, }) - layers = append(layers, v1.Descriptor{ + layers = append(layers, ocispecs.Descriptor{ MediaType: inTotoGenericMime, Digest: digest.FromString(provenanceContent), Size: int64(len(provenanceContent)), @@ -307,7 +306,7 @@ func getAttestationLayers(t attestationType) []v1.Descriptor { if t == dsseEmbeded || t == plainSpdxAndDSSEEmbed { dsseAttestation := fmt.Sprintf("{\"payload\":\"%s\"}", base64.StdEncoding.EncodeToString([]byte(attestationContent))) dsseProvenance := fmt.Sprintf("{\"payload\":\"%s\"}", base64.StdEncoding.EncodeToString([]byte(provenanceContent))) - layers = append(layers, v1.Descriptor{ + layers = append(layers, ocispecs.Descriptor{ MediaType: inTotoSPDXDSSEMime, Digest: digest.FromString(dsseAttestation), Size: int64(len(dsseAttestation)), @@ -316,7 +315,7 @@ func getAttestationLayers(t attestationType) []v1.Descriptor { "test_content": dsseAttestation, }, }) - layers = append(layers, v1.Descriptor{ + layers = append(layers, ocispecs.Descriptor{ MediaType: inTotoProvenanceDSSEMime, Digest: digest.FromString(dsseProvenance), Size: int64(len(dsseProvenance)), diff --git a/util/imagetools/inspect.go b/util/imagetools/inspect.go index 8af09c483..28f86f5be 100644 --- a/util/imagetools/inspect.go +++ b/util/imagetools/inspect.go @@ -16,7 +16,7 @@ import ( clitypes "github.com/docker/cli/cli/config/types" "github.com/moby/buildkit/util/contentutil" "github.com/moby/buildkit/util/tracing" - ocispec "github.com/opencontainers/image-spec/specs-go/v1" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/sirupsen/logrus" ) @@ -59,7 +59,7 @@ func (r *Resolver) resolver() remotes.Resolver { }) } -func (r *Resolver) Resolve(ctx context.Context, in string) (string, ocispec.Descriptor, error) { +func (r *Resolver) Resolve(ctx context.Context, in string) (string, ocispecs.Descriptor, error) { // discard containerd logger to avoid printing unnecessary info during image reference resolution. // https://github.com/containerd/containerd/blob/1a88cf5242445657258e0c744def5017d7cfb492/remotes/docker/resolver.go#L288 logger := logrus.New() @@ -68,31 +68,31 @@ func (r *Resolver) Resolve(ctx context.Context, in string) (string, ocispec.Desc ref, err := parseRef(in) if err != nil { - return "", ocispec.Descriptor{}, err + return "", ocispecs.Descriptor{}, err } in, desc, err := r.resolver().Resolve(ctx, ref.String()) if err != nil { - return "", ocispec.Descriptor{}, err + return "", ocispecs.Descriptor{}, err } return in, desc, nil } -func (r *Resolver) Get(ctx context.Context, in string) ([]byte, ocispec.Descriptor, error) { +func (r *Resolver) Get(ctx context.Context, in string) ([]byte, ocispecs.Descriptor, error) { in, desc, err := r.Resolve(ctx, in) if err != nil { - return nil, ocispec.Descriptor{}, err + return nil, ocispecs.Descriptor{}, err } dt, err := r.GetDescriptor(ctx, in, desc) if err != nil { - return nil, ocispec.Descriptor{}, err + return nil, ocispecs.Descriptor{}, err } return dt, desc, nil } -func (r *Resolver) GetDescriptor(ctx context.Context, in string, desc ocispec.Descriptor) ([]byte, error) { +func (r *Resolver) GetDescriptor(ctx context.Context, in string, desc ocispecs.Descriptor) ([]byte, error) { fetcher, err := r.resolver().Fetcher(ctx, in) if err != nil { return nil, err diff --git a/util/imagetools/loader.go b/util/imagetools/loader.go index eaba4d11e..d7753b564 100644 --- a/util/imagetools/loader.go +++ b/util/imagetools/loader.go @@ -20,7 +20,7 @@ import ( intoto "github.com/in-toto/in-toto-golang/in_toto" "github.com/moby/buildkit/util/contentutil" "github.com/opencontainers/go-digest" - ocispec "github.com/opencontainers/image-spec/specs-go/v1" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" "github.com/pkg/errors" "golang.org/x/sync/errgroup" ) @@ -49,17 +49,17 @@ type loader struct { } type manifest struct { - desc ocispec.Descriptor - manifest ocispec.Manifest + desc ocispecs.Descriptor + manifest ocispecs.Manifest } type index struct { - desc ocispec.Descriptor - index ocispec.Index + desc ocispecs.Descriptor + index ocispecs.Index } type asset struct { - config *ocispec.Image + config *ocispecs.Image sbom *sbomStub provenance *provenanceStub @@ -153,15 +153,15 @@ func (l *loader) Load(ctx context.Context, ref string) (*result, error) { return r, nil } -func (l *loader) fetch(ctx context.Context, fetcher remotes.Fetcher, desc ocispec.Descriptor, r *result) error { +func (l *loader) fetch(ctx context.Context, fetcher remotes.Fetcher, desc ocispecs.Descriptor, r *result) error { _, err := remotes.FetchHandler(l.cache, fetcher)(ctx, desc) if err != nil { return err } switch desc.MediaType { - case images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest: - var mfst ocispec.Manifest + case images.MediaTypeDockerSchema2Manifest, ocispecs.MediaTypeImageManifest: + var mfst ocispecs.Manifest dt, err := content.ReadBlob(ctx, l.cache, desc) if err != nil { return err @@ -205,8 +205,8 @@ func (l *loader) fetch(ctx context.Context, fetcher remotes.Fetcher, desc ocispe r.images[platforms.Format(platforms.Normalize(*p))] = desc.Digest r.mu.Unlock() } - case images.MediaTypeDockerSchema2ManifestList, ocispec.MediaTypeImageIndex: - var idx ocispec.Index + case images.MediaTypeDockerSchema2ManifestList, ocispecs.MediaTypeImageIndex: + var idx ocispecs.Index dt, err := content.ReadBlob(ctx, l.cache, desc) if err != nil { return err @@ -239,7 +239,7 @@ func (l *loader) fetch(ctx context.Context, fetcher remotes.Fetcher, desc ocispe return nil } -func (l *loader) readPlatformFromConfig(ctx context.Context, fetcher remotes.Fetcher, desc ocispec.Descriptor) (*ocispec.Platform, error) { +func (l *loader) readPlatformFromConfig(ctx context.Context, fetcher remotes.Fetcher, desc ocispecs.Descriptor) (*ocispecs.Platform, error) { _, err := remotes.FetchHandler(l.cache, fetcher)(ctx, desc) if err != nil { return nil, err @@ -250,19 +250,19 @@ func (l *loader) readPlatformFromConfig(ctx context.Context, fetcher remotes.Fet return nil, err } - var config ocispec.Image + var config ocispecs.Image if err := json.Unmarshal(dt, &config); err != nil { return nil, err } - return &ocispec.Platform{ + return &ocispecs.Platform{ OS: config.OS, Architecture: config.Architecture, Variant: config.Variant, }, nil } -func (l *loader) scanConfig(ctx context.Context, fetcher remotes.Fetcher, desc ocispec.Descriptor, as *asset) error { +func (l *loader) scanConfig(ctx context.Context, fetcher remotes.Fetcher, desc ocispecs.Descriptor, as *asset) error { _, err := remotes.FetchHandler(l.cache, fetcher)(ctx, desc) if err != nil { return err @@ -374,11 +374,11 @@ func (l *loader) scanProvenance(ctx context.Context, fetcher remotes.Fetcher, r return nil } -func (r *result) Configs() map[string]*ocispec.Image { +func (r *result) Configs() map[string]*ocispecs.Image { if len(r.assets) == 0 { return nil } - res := make(map[string]*ocispec.Image) + res := make(map[string]*ocispecs.Image) for p, a := range r.assets { if a.config == nil { continue diff --git a/util/imagetools/printers.go b/util/imagetools/printers.go index ab6fef1ba..2d3e795a4 100644 --- a/util/imagetools/printers.go +++ b/util/imagetools/printers.go @@ -114,7 +114,7 @@ func (p *Printer) Print(raw bool, out io.Writer) error { Manifests []ocispecs.Descriptor `json:"manifests"` Annotations map[string]string `json:"annotations,omitempty"` }{ - SchemaVersion: p.index.Versioned.SchemaVersion, + SchemaVersion: p.index.SchemaVersion, MediaType: p.index.MediaType, Digest: p.manifest.Digest, Size: p.manifest.Size, diff --git a/util/platformutil/parse.go b/util/platformutil/parse.go index 608fb3ee4..b95855ffa 100644 --- a/util/platformutil/parse.go +++ b/util/platformutil/parse.go @@ -4,14 +4,14 @@ import ( "strings" "github.com/containerd/platforms" - specs "github.com/opencontainers/image-spec/specs-go/v1" + ocispecs "github.com/opencontainers/image-spec/specs-go/v1" ) -func Parse(platformsStr []string) ([]specs.Platform, error) { +func Parse(platformsStr []string) ([]ocispecs.Platform, error) { if len(platformsStr) == 0 { return nil, nil } - out := make([]specs.Platform, 0, len(platformsStr)) + out := make([]ocispecs.Platform, 0, len(platformsStr)) for _, s := range platformsStr { parts := strings.Split(s, ",") if len(parts) > 1 { @@ -31,16 +31,16 @@ func Parse(platformsStr []string) ([]specs.Platform, error) { return out, nil } -func parse(in string) (specs.Platform, error) { +func parse(in string) (ocispecs.Platform, error) { if strings.EqualFold(in, "local") { return platforms.DefaultSpec(), nil } return platforms.Parse(in) } -func Dedupe(in []specs.Platform) []specs.Platform { +func Dedupe(in []ocispecs.Platform) []ocispecs.Platform { m := map[string]struct{}{} - out := make([]specs.Platform, 0, len(in)) + out := make([]ocispecs.Platform, 0, len(in)) for _, p := range in { p := platforms.Normalize(p) key := platforms.Format(p) @@ -53,7 +53,7 @@ func Dedupe(in []specs.Platform) []specs.Platform { return out } -func FormatInGroups(gg ...[]specs.Platform) []string { +func FormatInGroups(gg ...[]ocispecs.Platform) []string { m := map[string]struct{}{} out := make([]string, 0, len(gg)) for i, g := range gg { @@ -74,7 +74,7 @@ func FormatInGroups(gg ...[]specs.Platform) []string { return out } -func Format(in []specs.Platform) []string { +func Format(in []ocispecs.Platform) []string { if len(in) == 0 { return nil }