Merge pull request #3181 from crazy-max/golangci-lint-v2

update golangci-lint to v2.1.5
This commit is contained in:
CrazyMax
2025-05-13 17:17:17 +02:00
committed by GitHub
34 changed files with 352 additions and 332 deletions
+74 -73
View File
@@ -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,40 +20,9 @@ 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
settings:
depguard:
rules:
main:
@@ -69,51 +37,84 @@ linters-settings:
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\.)?$'
- 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 # Audit use of command execution
- G402 # TLS MinVersion too low
- G115 # integer overflow conversion (TODO: verify these)
- 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:
# disable rules that reduce the test condition
- "empty"
- "bool-compare"
- "len"
- "negative-positive"
- empty
- bool-compare
- len
- negative-positive
exclusions:
generated: lax
presets:
- comments
- common-false-positives
- legacy
- std-error-handling
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
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
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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")
}
+5 -5
View File
@@ -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,
+4 -4
View File
@@ -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}}
+10 -10
View File
@@ -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 {
+43 -43
View File
@@ -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{
+3 -3
View File
@@ -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
+12 -11
View File
@@ -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"])
+1 -1
View File
@@ -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()
+6 -6
View File
@@ -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:
+5 -5
View File
@@ -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())
+1 -1
View File
@@ -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
}
}
+1 -1
View File
@@ -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),
+2 -2
View File
@@ -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 {
+5 -4
View File
@@ -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")
}
+1 -1
View File
@@ -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
}
+4 -4
View File
@@ -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
+3 -3
View File
@@ -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 {
+1 -1
View File
@@ -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)
+1 -1
View File
@@ -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)
+3
View File
@@ -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",
+9 -9
View File
@@ -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 {
+5 -5
View File
@@ -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
+2 -2
View File
@@ -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
}
+3 -3
View File
@@ -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)
+21 -6
View File
@@ -4,7 +4,8 @@ ARG GO_VERSION=1.23
ARG ALPINE_VERSION=3.21
ARG XX_VERSION=1.6.1
ARG GOLANGCI_LINT_VERSION=1.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
# disabled: deprecated unusedvariable simplifyrange
@@ -12,13 +13,27 @@ ARG GOPLS_ANALYZERS="embeddirective fillreturns hostport infertypeargs modernize
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS golang-base
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-alpine${ALPINE_VERSION} AS base
RUN apk add --no-cache git gcc musl-dev
FROM golang-base AS lint-base
FROM base AS golangci-build
WORKDIR /src
ARG GOLANGCI_LINT_VERSION
ADD https://github.com/golangci/golangci-lint.git#${GOLANGCI_LINT_VERSION} .
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/ go mod download
RUN --mount=type=cache,target=/go/pkg/mod --mount=type=cache,target=/root/.cache/ mkdir -p out && go build -o /out/golangci-lint ./cmd/golangci-lint
FROM scratch AS golangci-binary-false
FROM scratch AS golangci-binary-true
COPY --from=golangci-build /out/golangci-lint golangci-lint
FROM golangci-binary-${GOLANGCI_FROM_SOURCE} AS golangci-binary
FROM base AS lint-base
ENV GOFLAGS="-buildvcs=false"
ARG GOLANGCI_LINT_VERSION
RUN wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v${GOLANGCI_LINT_VERSION}
ARG GOLANGCI_FROM_SOURCE
COPY --link --from=golangci-binary / /usr/bin/
RUN [ "${GOLANGCI_FROM_SOURCE}" = "true" ] && exit 0; wget -O- -nv https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s ${GOLANGCI_LINT_VERSION}
COPY --link --from=xx / /
WORKDIR /go/src/github.com/docker/buildx
ARG TARGETPLATFORM
@@ -33,7 +48,7 @@ FROM lint-base AS validate-golangci
RUN --mount=target=/go/src/github.com/docker/buildx \
golangci-lint config verify
FROM golang-base AS gopls
FROM base AS gopls
RUN apk add --no-cache git
ARG GOPLS_VERSION
WORKDIR /src
@@ -61,7 +76,7 @@ eot
done
EOF
FROM golang-base AS gopls-analyze
FROM base AS gopls-analyze
COPY --link --from=xx / /
ARG GOPLS_ANALYZERS
ARG TARGETNAME
+5 -5
View File
@@ -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)
+23 -23
View File
@@ -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)
}
+44 -45
View File
@@ -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)),
+8 -8
View File
@@ -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
+17 -17
View File
@@ -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
+1 -1
View File
@@ -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,
+8 -8
View File
@@ -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
}