update golangci-lint to v2.1.5
Signed-off-by: CrazyMax <1951866+crazy-max@users.noreply.github.com>
This commit is contained in:
+93
-92
@@ -1,17 +1,16 @@
|
|||||||
|
version: "2"
|
||||||
|
|
||||||
run:
|
run:
|
||||||
timeout: 30m
|
|
||||||
modules-download-mode: vendor
|
modules-download-mode: vendor
|
||||||
|
|
||||||
linters:
|
linters:
|
||||||
|
default: none
|
||||||
enable:
|
enable:
|
||||||
- bodyclose
|
- bodyclose
|
||||||
- depguard
|
- depguard
|
||||||
- forbidigo
|
- forbidigo
|
||||||
- gocritic
|
- gocritic
|
||||||
- gofmt
|
|
||||||
- goimports
|
|
||||||
- gosec
|
- gosec
|
||||||
- gosimple
|
|
||||||
- govet
|
- govet
|
||||||
- ineffassign
|
- ineffassign
|
||||||
- makezero
|
- makezero
|
||||||
@@ -21,99 +20,101 @@ linters:
|
|||||||
- revive
|
- revive
|
||||||
- staticcheck
|
- staticcheck
|
||||||
- testifylint
|
- testifylint
|
||||||
- typecheck
|
|
||||||
- unused
|
- unused
|
||||||
- whitespace
|
- whitespace
|
||||||
disable-all: true
|
settings:
|
||||||
|
depguard:
|
||||||
linters-settings:
|
rules:
|
||||||
gocritic:
|
main:
|
||||||
disabled-checks:
|
deny:
|
||||||
- "ifElseChain"
|
- pkg: "github.com/containerd/containerd/errdefs"
|
||||||
- "assignOp"
|
desc: The containerd errdefs package was migrated to a separate module. Use github.com/containerd/errdefs instead.
|
||||||
- "appendAssign"
|
- pkg: "github.com/containerd/containerd/log"
|
||||||
- "singleCaseSwitch"
|
desc: The containerd log package was migrated to a separate module. Use github.com/containerd/log instead.
|
||||||
- "exitAfterDefer" # FIXME
|
- pkg: "github.com/containerd/containerd/platforms"
|
||||||
importas:
|
desc: The containerd platforms package was migrated to a separate module. Use github.com/containerd/platforms instead.
|
||||||
alias:
|
- pkg: "io/ioutil"
|
||||||
# Enforce alias to prevent it accidentally being used instead of
|
desc: The io/ioutil package has been deprecated.
|
||||||
# buildkit errdefs package (or vice-versa).
|
forbidigo:
|
||||||
- pkg: "github.com/containerd/errdefs"
|
forbid:
|
||||||
alias: "cerrdefs"
|
- pattern: ^context\.WithCancel(# use context\.WithCancelCause instead)?$
|
||||||
# Use a consistent alias to prevent confusion with "github.com/moby/buildkit/client"
|
- pattern: ^context\.WithDeadline(# use context\.WithDeadline instead)?$
|
||||||
- pkg: "github.com/docker/docker/client"
|
- pattern: ^context\.WithTimeout(# use context\.WithTimeoutCause instead)?$
|
||||||
alias: "dockerclient"
|
- pattern: ^ctx\.Err(# use context\.Cause instead)?$
|
||||||
- pkg: "github.com/opencontainers/image-spec/specs-go/v1"
|
- pattern: ^fmt\.Errorf(# use errors\.Errorf instead)?$
|
||||||
alias: "ocispecs"
|
- pattern: ^platforms\.DefaultString(# use platforms\.Format(platforms\.DefaultSpec()) instead\.)?$
|
||||||
- pkg: "github.com/opencontainers/go-digest"
|
gocritic:
|
||||||
alias: "digest"
|
disabled-checks:
|
||||||
govet:
|
- "ifElseChain"
|
||||||
enable:
|
- "assignOp"
|
||||||
- nilness
|
- "appendAssign"
|
||||||
- unusedwrite
|
- "singleCaseSwitch"
|
||||||
# enable-all: true
|
- "exitAfterDefer" # FIXME
|
||||||
# disable:
|
gosec:
|
||||||
# - fieldalignment
|
excludes:
|
||||||
# - shadow
|
- G204
|
||||||
depguard:
|
- 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:
|
rules:
|
||||||
main:
|
- linters:
|
||||||
deny:
|
- revive
|
||||||
- pkg: "github.com/containerd/containerd/errdefs"
|
text: stutters
|
||||||
desc: The containerd errdefs package was migrated to a separate module. Use github.com/containerd/errdefs instead.
|
- linters:
|
||||||
- pkg: "github.com/containerd/containerd/log"
|
- revive
|
||||||
desc: The containerd log package was migrated to a separate module. Use github.com/containerd/log instead.
|
text: empty-block
|
||||||
- pkg: "github.com/containerd/containerd/platforms"
|
- linters:
|
||||||
desc: The containerd platforms package was migrated to a separate module. Use github.com/containerd/platforms instead.
|
- revive
|
||||||
- pkg: "io/ioutil"
|
text: superfluous-else
|
||||||
desc: The io/ioutil package has been deprecated.
|
- linters:
|
||||||
forbidigo:
|
- revive
|
||||||
forbid:
|
text: unused-parameter
|
||||||
- '^context\.WithCancel(# use context\.WithCancelCause instead)?$'
|
- linters:
|
||||||
- '^context\.WithDeadline(# use context\.WithDeadline instead)?$'
|
- revive
|
||||||
- '^context\.WithTimeout(# use context\.WithTimeoutCause instead)?$'
|
text: redefines-builtin-id
|
||||||
- '^ctx\.Err(# use context\.Cause instead)?$'
|
- linters:
|
||||||
- '^fmt\.Errorf(# use errors\.Errorf instead)?$'
|
- revive
|
||||||
- '^platforms\.DefaultString(# use platforms\.Format(platforms\.DefaultSpec()) instead\.)?$'
|
text: if-return
|
||||||
gosec:
|
paths:
|
||||||
excludes:
|
- .*\.pb\.go$
|
||||||
- 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"
|
|
||||||
|
|
||||||
|
formatters:
|
||||||
|
enable:
|
||||||
|
- gofmt
|
||||||
|
- goimports
|
||||||
|
exclusions:
|
||||||
|
generated: lax
|
||||||
|
paths:
|
||||||
|
- .*\.pb\.go$
|
||||||
|
|
||||||
issues:
|
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-issues-per-linter: 0
|
||||||
max-same-issues: 0
|
max-same-issues: 0
|
||||||
|
|||||||
@@ -936,7 +936,7 @@ func Parse(b hcl.Body, opt Opt, val any) (*ParseMeta, hcl.Diagnostics) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if exists {
|
if exists {
|
||||||
if m := oldValue.Value.MethodByName("Merge"); m.IsValid() {
|
if m := oldValue.MethodByName("Merge"); m.IsValid() {
|
||||||
m.Call([]reflect.Value{vv})
|
m.Call([]reflect.Value{vv})
|
||||||
} else {
|
} else {
|
||||||
v.Elem().Field(t.idx).Index(oldValue.idx).Set(vv)
|
v.Elem().Field(t.idx).Index(oldValue.idx).Set(vv)
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ func indexOfFunc() function.Function {
|
|||||||
},
|
},
|
||||||
Type: function.StaticReturnType(cty.Number),
|
Type: function.StaticReturnType(cty.Number),
|
||||||
Impl: func(args []cty.Value, retType cty.Type) (ret cty.Value, err error) {
|
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")
|
return cty.NilVal, errors.New("argument must be a list or tuple")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-5
@@ -44,7 +44,7 @@ import (
|
|||||||
"github.com/moby/buildkit/util/progress/progresswriter"
|
"github.com/moby/buildkit/util/progress/progresswriter"
|
||||||
"github.com/moby/buildkit/util/tracing"
|
"github.com/moby/buildkit/util/tracing"
|
||||||
"github.com/opencontainers/go-digest"
|
"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/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/tonistiigi/fsutil"
|
"github.com/tonistiigi/fsutil"
|
||||||
@@ -76,7 +76,7 @@ type Options struct {
|
|||||||
NetworkMode string
|
NetworkMode string
|
||||||
NoCache bool
|
NoCache bool
|
||||||
NoCacheFilter []string
|
NoCacheFilter []string
|
||||||
Platforms []specs.Platform
|
Platforms []ocispecs.Platform
|
||||||
Pull bool
|
Pull bool
|
||||||
SecretSpecs []*controllerapi.Secret
|
SecretSpecs []*controllerapi.Secret
|
||||||
SSHSpecs []*controllerapi.SSH
|
SSHSpecs []*controllerapi.SSH
|
||||||
@@ -600,7 +600,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opts map[
|
|||||||
|
|
||||||
if pushNames != "" {
|
if pushNames != "" {
|
||||||
err := progress.Write(pw, fmt.Sprintf("merging manifest list %s", pushNames), func() error {
|
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 {
|
for _, r := range res {
|
||||||
s, ok := r.ExporterResponse[exptypes.ExporterImageDescriptorKey]
|
s, ok := r.ExporterResponse[exptypes.ExporterImageDescriptorKey]
|
||||||
@@ -609,7 +609,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opts map[
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
var desc specs.Descriptor
|
var desc ocispecs.Descriptor
|
||||||
if err := json.Unmarshal(dt, &desc); err != nil {
|
if err := json.Unmarshal(dt, &desc); err != nil {
|
||||||
return errors.Wrapf(err, "failed to unmarshal descriptor %s", s)
|
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.
|
// mediatype value in the Accept header does not seem to matter.
|
||||||
s, ok = r.ExporterResponse[exptypes.ExporterImageDigestKey]
|
s, ok = r.ExporterResponse[exptypes.ExporterImageDigestKey]
|
||||||
if ok {
|
if ok {
|
||||||
descs = append(descs, specs.Descriptor{
|
descs = append(descs, ocispecs.Descriptor{
|
||||||
Digest: digest.Digest(s),
|
Digest: digest.Digest(s),
|
||||||
MediaType: images.MediaTypeDockerSchema2ManifestList,
|
MediaType: images.MediaTypeDockerSchema2ManifestList,
|
||||||
Size: -1,
|
Size: -1,
|
||||||
|
|||||||
+4
-4
@@ -9,11 +9,11 @@ import (
|
|||||||
"github.com/containerd/platforms"
|
"github.com/containerd/platforms"
|
||||||
"github.com/docker/buildx/builder"
|
"github.com/docker/buildx/builder"
|
||||||
"github.com/docker/buildx/util/progress"
|
"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"
|
"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)
|
nodes, err := filterAvailableNodes(nodes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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")
|
return nil, errors.New("no nodes available")
|
||||||
}
|
}
|
||||||
|
|
||||||
var pls []v1.Platform
|
var pls []ocispecs.Platform
|
||||||
if platform != nil {
|
if platform != nil {
|
||||||
pls = []v1.Platform{*platform}
|
pls = []ocispecs.Platform{*platform}
|
||||||
}
|
}
|
||||||
|
|
||||||
opts := map[string]Options{"default": {Platforms: pls}}
|
opts := map[string]Options{"default": {Platforms: pls}}
|
||||||
|
|||||||
+10
-10
@@ -14,7 +14,7 @@ import (
|
|||||||
gateway "github.com/moby/buildkit/frontend/gateway/client"
|
gateway "github.com/moby/buildkit/frontend/gateway/client"
|
||||||
"github.com/moby/buildkit/util/flightcontrol"
|
"github.com/moby/buildkit/util/flightcontrol"
|
||||||
"github.com/moby/buildkit/util/tracing"
|
"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"
|
"github.com/pkg/errors"
|
||||||
"go.opentelemetry.io/otel/trace"
|
"go.opentelemetry.io/otel/trace"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
@@ -23,7 +23,7 @@ import (
|
|||||||
type resolvedNode struct {
|
type resolvedNode struct {
|
||||||
resolver *nodeResolver
|
resolver *nodeResolver
|
||||||
driverIndex int
|
driverIndex int
|
||||||
platforms []specs.Platform
|
platforms []ocispecs.Platform
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dp resolvedNode) Node() builder.Node {
|
func (dp resolvedNode) Node() builder.Node {
|
||||||
@@ -46,7 +46,7 @@ func (dp resolvedNode) BuildOpts(ctx context.Context) (gateway.BuildOpts, error)
|
|||||||
return opts[0], nil
|
return opts[0], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
type matchMaker func(specs.Platform) platforms.MatchComparer
|
type matchMaker func(ocispecs.Platform) platforms.MatchComparer
|
||||||
|
|
||||||
type cachedGroup[T any] struct {
|
type cachedGroup[T any] struct {
|
||||||
g flightcontrol.Group[T]
|
g flightcontrol.Group[T]
|
||||||
@@ -112,7 +112,7 @@ func (r *nodeResolver) Resolve(ctx context.Context, opt map[string]Options, pw p
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
eg, egCtx := errgroup.WithContext(ctx)
|
eg, egCtx := errgroup.WithContext(ctx)
|
||||||
workers := make([][]specs.Platform, len(clients))
|
workers := make([][]ocispecs.Platform, len(clients))
|
||||||
for i, c := range clients {
|
for i, c := range clients {
|
||||||
i, c := i, c
|
i, c := i, c
|
||||||
if c == nil {
|
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")
|
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 _, w := range ww {
|
||||||
for _, p := range w.Platforms {
|
for _, p := range w.Platforms {
|
||||||
pk := platforms.Format(platforms.Normalize(p))
|
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)
|
// (this time we don't care about imperfect matches)
|
||||||
nodes = map[string][]*resolvedNode{}
|
nodes = map[string][]*resolvedNode{}
|
||||||
for k, opt := range opt {
|
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]
|
return workers[idx]
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -173,7 +173,7 @@ func (r *nodeResolver) Resolve(ctx context.Context, opt map[string]Options, pw p
|
|||||||
return nodes, nil
|
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 {
|
if len(r.nodes) == 0 {
|
||||||
return nil, true, nil
|
return nil, true, nil
|
||||||
}
|
}
|
||||||
@@ -203,7 +203,7 @@ func (r *nodeResolver) resolve(ctx context.Context, ps []specs.Platform, pw prog
|
|||||||
driverIndex: idx,
|
driverIndex: idx,
|
||||||
}
|
}
|
||||||
if len(ps) > 0 {
|
if len(ps) > 0 {
|
||||||
node.platforms = []specs.Platform{ps[i]}
|
node.platforms = []ocispecs.Platform{ps[i]}
|
||||||
}
|
}
|
||||||
nodes = append(nodes, node)
|
nodes = append(nodes, node)
|
||||||
}
|
}
|
||||||
@@ -216,9 +216,9 @@ func (r *nodeResolver) resolve(ctx context.Context, ps []specs.Platform, pw prog
|
|||||||
return nodes, perfect, nil
|
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
|
best := -1
|
||||||
bestPlatform := specs.Platform{}
|
bestPlatform := ocispecs.Platform{}
|
||||||
for i, node := range r.nodes {
|
for i, node := range r.nodes {
|
||||||
platforms := node.Platforms
|
platforms := node.Platforms
|
||||||
if additionalPlatforms != nil {
|
if additionalPlatforms != nil {
|
||||||
|
|||||||
+43
-43
@@ -7,41 +7,41 @@ import (
|
|||||||
|
|
||||||
"github.com/containerd/platforms"
|
"github.com/containerd/platforms"
|
||||||
"github.com/docker/buildx/builder"
|
"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"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestFindDriverSanity(t *testing.T) {
|
func TestFindDriverSanity(t *testing.T) {
|
||||||
r := makeTestResolver(map[string][]specs.Platform{
|
r := makeTestResolver(map[string][]ocispecs.Platform{
|
||||||
"aaa": {platforms.DefaultSpec()},
|
"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.NoError(t, err)
|
||||||
require.True(t, perfect)
|
require.True(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
require.Equal(t, 0, res[0].driverIndex)
|
require.Equal(t, 0, res[0].driverIndex)
|
||||||
require.Equal(t, "aaa", res[0].Node().Builder)
|
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) {
|
func TestFindDriverEmpty(t *testing.T) {
|
||||||
r := makeTestResolver(nil)
|
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.NoError(t, err)
|
||||||
require.True(t, perfect)
|
require.True(t, perfect)
|
||||||
require.Nil(t, res)
|
require.Nil(t, res)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFindDriverWeirdName(t *testing.T) {
|
func TestFindDriverWeirdName(t *testing.T) {
|
||||||
r := makeTestResolver(map[string][]specs.Platform{
|
r := makeTestResolver(map[string][]ocispecs.Platform{
|
||||||
"aaa": {platforms.MustParse("linux/amd64")},
|
"aaa": {platforms.MustParse("linux/amd64")},
|
||||||
"bbb": {platforms.MustParse("linux/foobar")},
|
"bbb": {platforms.MustParse("linux/foobar")},
|
||||||
})
|
})
|
||||||
|
|
||||||
// find first platform
|
// 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.NoError(t, err)
|
||||||
require.True(t, perfect)
|
require.True(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
@@ -50,11 +50,11 @@ func TestFindDriverWeirdName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestFindDriverUnknown(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")},
|
"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.NoError(t, err)
|
||||||
require.False(t, perfect)
|
require.False(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
@@ -63,13 +63,13 @@ func TestFindDriverUnknown(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSelectNodeSinglePlatform(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")},
|
"aaa": {platforms.MustParse("linux/amd64")},
|
||||||
"bbb": {platforms.MustParse("linux/riscv64")},
|
"bbb": {platforms.MustParse("linux/riscv64")},
|
||||||
})
|
})
|
||||||
|
|
||||||
// find first platform
|
// 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.NoError(t, err)
|
||||||
require.True(t, perfect)
|
require.True(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
@@ -77,7 +77,7 @@ func TestSelectNodeSinglePlatform(t *testing.T) {
|
|||||||
require.Equal(t, "aaa", res[0].Node().Builder)
|
require.Equal(t, "aaa", res[0].Node().Builder)
|
||||||
|
|
||||||
// find second platform
|
// 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.NoError(t, err)
|
||||||
require.True(t, perfect)
|
require.True(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
@@ -85,7 +85,7 @@ func TestSelectNodeSinglePlatform(t *testing.T) {
|
|||||||
require.Equal(t, "bbb", res[0].Node().Builder)
|
require.Equal(t, "bbb", res[0].Node().Builder)
|
||||||
|
|
||||||
// find an unknown platform, should match the first driver
|
// 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.NoError(t, err)
|
||||||
require.False(t, perfect)
|
require.False(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
@@ -94,26 +94,26 @@ func TestSelectNodeSinglePlatform(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSelectNodeMultiPlatform(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")},
|
"aaa": {platforms.MustParse("linux/amd64"), platforms.MustParse("linux/arm64")},
|
||||||
"bbb": {platforms.MustParse("linux/riscv64")},
|
"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.NoError(t, err)
|
||||||
require.True(t, perfect)
|
require.True(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
require.Equal(t, 0, res[0].driverIndex)
|
require.Equal(t, 0, res[0].driverIndex)
|
||||||
require.Equal(t, "aaa", res[0].Node().Builder)
|
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.NoError(t, err)
|
||||||
require.True(t, perfect)
|
require.True(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
require.Equal(t, 0, res[0].driverIndex)
|
require.Equal(t, 0, res[0].driverIndex)
|
||||||
require.Equal(t, "aaa", res[0].Node().Builder)
|
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.NoError(t, err)
|
||||||
require.True(t, perfect)
|
require.True(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
@@ -122,27 +122,27 @@ func TestSelectNodeMultiPlatform(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSelectNodeNonStrict(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")},
|
"aaa": {platforms.MustParse("linux/amd64")},
|
||||||
"bbb": {platforms.MustParse("linux/arm64")},
|
"bbb": {platforms.MustParse("linux/arm64")},
|
||||||
})
|
})
|
||||||
|
|
||||||
// arm64 should match itself
|
// 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.NoError(t, err)
|
||||||
require.True(t, perfect)
|
require.True(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
require.Equal(t, "bbb", res[0].Node().Builder)
|
require.Equal(t, "bbb", res[0].Node().Builder)
|
||||||
|
|
||||||
// arm64 may support arm/v8
|
// 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.NoError(t, err)
|
||||||
require.True(t, perfect)
|
require.True(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
require.Equal(t, "bbb", res[0].Node().Builder)
|
require.Equal(t, "bbb", res[0].Node().Builder)
|
||||||
|
|
||||||
// arm64 may support arm/v7
|
// 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.NoError(t, err)
|
||||||
require.True(t, perfect)
|
require.True(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
@@ -150,19 +150,19 @@ func TestSelectNodeNonStrict(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSelectNodeNonStrictARM(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")},
|
"aaa": {platforms.MustParse("linux/amd64")},
|
||||||
"bbb": {platforms.MustParse("linux/arm64")},
|
"bbb": {platforms.MustParse("linux/arm64")},
|
||||||
"ccc": {platforms.MustParse("linux/arm/v8")},
|
"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.NoError(t, err)
|
||||||
require.True(t, perfect)
|
require.True(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
require.Equal(t, "ccc", res[0].Node().Builder)
|
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.NoError(t, err)
|
||||||
require.True(t, perfect)
|
require.True(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
@@ -170,20 +170,20 @@ func TestSelectNodeNonStrictARM(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSelectNodeNonStrictLower(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")},
|
"aaa": {platforms.MustParse("linux/amd64")},
|
||||||
"bbb": {platforms.MustParse("linux/arm/v7")},
|
"bbb": {platforms.MustParse("linux/arm/v7")},
|
||||||
})
|
})
|
||||||
|
|
||||||
// v8 can't be built on v7 (so we should select the default)...
|
// 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.NoError(t, err)
|
||||||
require.False(t, perfect)
|
require.False(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
require.Equal(t, "aaa", res[0].Node().Builder)
|
require.Equal(t, "aaa", res[0].Node().Builder)
|
||||||
|
|
||||||
// ...but v6 can be built on v8
|
// ...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.NoError(t, err)
|
||||||
require.True(t, perfect)
|
require.True(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
@@ -191,13 +191,13 @@ func TestSelectNodeNonStrictLower(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSelectNodePreferStart(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")},
|
"aaa": {platforms.MustParse("linux/amd64")},
|
||||||
"bbb": {platforms.MustParse("linux/riscv64")},
|
"bbb": {platforms.MustParse("linux/riscv64")},
|
||||||
"ccc": {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.NoError(t, err)
|
||||||
require.True(t, perfect)
|
require.True(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
@@ -205,12 +205,12 @@ func TestSelectNodePreferStart(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSelectNodePreferExact(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")},
|
"aaa": {platforms.MustParse("linux/arm/v8")},
|
||||||
"bbb": {platforms.MustParse("linux/arm/v7")},
|
"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.NoError(t, err)
|
||||||
require.True(t, perfect)
|
require.True(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
@@ -218,12 +218,12 @@ func TestSelectNodePreferExact(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSelectNodeNoPlatform(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")},
|
"aaa": {platforms.MustParse("linux/foobar")},
|
||||||
"bbb": {platforms.DefaultSpec()},
|
"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.NoError(t, err)
|
||||||
require.True(t, perfect)
|
require.True(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
@@ -232,20 +232,20 @@ func TestSelectNodeNoPlatform(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSelectNodeAdditionalPlatforms(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")},
|
"aaa": {platforms.MustParse("linux/amd64")},
|
||||||
"bbb": {platforms.MustParse("linux/arm/v8")},
|
"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.NoError(t, err)
|
||||||
require.True(t, perfect)
|
require.True(t, perfect)
|
||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
require.Equal(t, "bbb", res[0].Node().Builder)
|
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" {
|
if n.Builder == "aaa" {
|
||||||
return []specs.Platform{platforms.MustParse("linux/arm/v7")}
|
return []ocispecs.Platform{platforms.MustParse("linux/arm/v7")}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@@ -256,12 +256,12 @@ func TestSelectNodeAdditionalPlatforms(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSplitNodeMultiPlatform(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")},
|
"aaa": {platforms.MustParse("linux/amd64"), platforms.MustParse("linux/arm64")},
|
||||||
"bbb": {platforms.MustParse("linux/riscv64")},
|
"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/amd64"),
|
||||||
platforms.MustParse("linux/arm64"),
|
platforms.MustParse("linux/arm64"),
|
||||||
}, nil, platforms.Only, nil)
|
}, nil, platforms.Only, nil)
|
||||||
@@ -270,7 +270,7 @@ func TestSplitNodeMultiPlatform(t *testing.T) {
|
|||||||
require.Len(t, res, 1)
|
require.Len(t, res, 1)
|
||||||
require.Equal(t, "aaa", res[0].Node().Builder)
|
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/amd64"),
|
||||||
platforms.MustParse("linux/riscv64"),
|
platforms.MustParse("linux/riscv64"),
|
||||||
}, nil, platforms.Only, nil)
|
}, nil, platforms.Only, nil)
|
||||||
@@ -282,14 +282,14 @@ func TestSplitNodeMultiPlatform(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestSplitNodeMultiPlatformNoUnify(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")},
|
"aaa": {platforms.MustParse("linux/amd64")},
|
||||||
"bbb": {platforms.MustParse("linux/amd64"), platforms.MustParse("linux/riscv64")},
|
"bbb": {platforms.MustParse("linux/amd64"), platforms.MustParse("linux/riscv64")},
|
||||||
})
|
})
|
||||||
|
|
||||||
// the "best" choice would be the node with both platforms, but we're using
|
// 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
|
// 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/amd64"),
|
||||||
platforms.MustParse("linux/riscv64"),
|
platforms.MustParse("linux/riscv64"),
|
||||||
}, nil, platforms.Only, nil)
|
}, nil, platforms.Only, nil)
|
||||||
@@ -300,7 +300,7 @@ func TestSplitNodeMultiPlatformNoUnify(t *testing.T) {
|
|||||||
require.Equal(t, "bbb", res[1].Node().Builder)
|
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
|
var ns []builder.Node
|
||||||
for name, platforms := range nodes {
|
for name, platforms := range nodes {
|
||||||
ns = append(ns, builder.Node{
|
ns = append(ns, builder.Node{
|
||||||
|
|||||||
+3
-3
@@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/docker/buildx/util/gitutil"
|
"github.com/docker/buildx/util/gitutil"
|
||||||
"github.com/docker/buildx/util/osutil"
|
"github.com/docker/buildx/util/osutil"
|
||||||
"github.com/moby/buildkit/client"
|
"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"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ func getGitAttributes(ctx context.Context, contextPath, dockerfilePath string) (
|
|||||||
sha += "-dirty"
|
sha += "-dirty"
|
||||||
}
|
}
|
||||||
if setGitLabels {
|
if setGitLabels {
|
||||||
res["label:"+specs.AnnotationRevision] = sha
|
res["label:"+ocispecs.AnnotationRevision] = sha
|
||||||
}
|
}
|
||||||
if setGitInfo {
|
if setGitInfo {
|
||||||
res["vcs:revision"] = sha
|
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 rurl, err := gitc.RemoteURL(); err == nil && rurl != "" {
|
||||||
if setGitLabels {
|
if setGitLabels {
|
||||||
res["label:"+specs.AnnotationSource] = rurl
|
res["label:"+ocispecs.AnnotationSource] = rurl
|
||||||
}
|
}
|
||||||
if setGitInfo {
|
if setGitInfo {
|
||||||
res["vcs:source"] = rurl
|
res["vcs:source"] = rurl
|
||||||
|
|||||||
+12
-11
@@ -11,7 +11,7 @@ import (
|
|||||||
"github.com/docker/buildx/util/gitutil"
|
"github.com/docker/buildx/util/gitutil"
|
||||||
"github.com/docker/buildx/util/gitutil/gittestutil"
|
"github.com/docker/buildx/util/gitutil/gittestutil"
|
||||||
"github.com/moby/buildkit/client"
|
"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/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
@@ -91,8 +91,8 @@ func TestGetGitAttributes(t *testing.T) {
|
|||||||
envGitInfo: "false",
|
envGitInfo: "false",
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"label:" + DockerfileLabel,
|
"label:" + DockerfileLabel,
|
||||||
"label:" + specs.AnnotationRevision,
|
"label:" + ocispecs.AnnotationRevision,
|
||||||
"label:" + specs.AnnotationSource,
|
"label:" + ocispecs.AnnotationSource,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -101,8 +101,8 @@ func TestGetGitAttributes(t *testing.T) {
|
|||||||
envGitInfo: "",
|
envGitInfo: "",
|
||||||
expected: []string{
|
expected: []string{
|
||||||
"label:" + DockerfileLabel,
|
"label:" + DockerfileLabel,
|
||||||
"label:" + specs.AnnotationRevision,
|
"label:" + ocispecs.AnnotationRevision,
|
||||||
"label:" + specs.AnnotationSource,
|
"label:" + ocispecs.AnnotationSource,
|
||||||
"vcs:revision",
|
"vcs:revision",
|
||||||
"vcs:source",
|
"vcs:source",
|
||||||
},
|
},
|
||||||
@@ -125,9 +125,10 @@ func TestGetGitAttributes(t *testing.T) {
|
|||||||
for _, e := range tt.expected {
|
for _, e := range tt.expected {
|
||||||
assert.Contains(t, so.FrontendAttrs, e)
|
assert.Contains(t, so.FrontendAttrs, e)
|
||||||
assert.NotEmpty(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])
|
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])
|
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.Contains(t, so.FrontendAttrs, "label:"+DockerfileLabel)
|
||||||
assert.Equal(t, "Dockerfile", so.FrontendAttrs["label:"+DockerfileLabel])
|
assert.Equal(t, "Dockerfile", so.FrontendAttrs["label:"+DockerfileLabel])
|
||||||
assert.Contains(t, so.FrontendAttrs, "label:"+specs.AnnotationSource)
|
assert.Contains(t, so.FrontendAttrs, "label:"+ocispecs.AnnotationSource)
|
||||||
assert.Equal(t, "git@github.com:docker/buildx.git", so.FrontendAttrs["label:"+specs.AnnotationSource])
|
assert.Equal(t, "git@github.com:docker/buildx.git", so.FrontendAttrs["label:"+ocispecs.AnnotationSource])
|
||||||
assert.Contains(t, so.FrontendAttrs, "label:"+specs.AnnotationRevision)
|
assert.Contains(t, so.FrontendAttrs, "label:"+ocispecs.AnnotationRevision)
|
||||||
assert.True(t, strings.HasSuffix(so.FrontendAttrs["label:"+specs.AnnotationRevision], "-dirty"))
|
assert.True(t, strings.HasSuffix(so.FrontendAttrs["label:"+ocispecs.AnnotationRevision], "-dirty"))
|
||||||
|
|
||||||
assert.Contains(t, so.FrontendAttrs, "vcs:source")
|
assert.Contains(t, so.FrontendAttrs, "vcs:source")
|
||||||
assert.Equal(t, "git@github.com:docker/buildx.git", so.FrontendAttrs["vcs:source"])
|
assert.Equal(t, "git@github.com:docker/buildx.git", so.FrontendAttrs["vcs:source"])
|
||||||
|
|||||||
+1
-1
@@ -394,7 +394,7 @@ func loadInputs(ctx context.Context, d *driver.DriverHandle, inp *Inputs, pw pro
|
|||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
return nil, errors.Wrap(err, "failed to peek context header from STDIN")
|
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) {
|
if isArchive(magic) {
|
||||||
// stdin is context
|
// stdin is context
|
||||||
up := uploadprovider.New()
|
up := uploadprovider.New()
|
||||||
|
|||||||
+6
-6
@@ -14,7 +14,7 @@ import (
|
|||||||
"github.com/moby/buildkit/solver/errdefs"
|
"github.com/moby/buildkit/solver/errdefs"
|
||||||
"github.com/moby/buildkit/solver/pb"
|
"github.com/moby/buildkit/solver/pb"
|
||||||
"github.com/moby/buildkit/solver/result"
|
"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/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"golang.org/x/sync/errgroup"
|
"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 {
|
func populateProcessConfigFromResult(req *gateway.StartRequest, res *gateway.Result, cfg *controllerapi.InvokeConfig) error {
|
||||||
imgData := res.Metadata[exptypes.ExporterImageConfigKey]
|
imgData := res.Metadata[exptypes.ExporterImageConfigKey]
|
||||||
var img *specs.Image
|
var img *ocispecs.Image
|
||||||
if len(imgData) > 0 {
|
if len(imgData) > 0 {
|
||||||
img = &specs.Image{}
|
img = &ocispecs.Image{}
|
||||||
if err := json.Unmarshal(imgData, img); err != nil {
|
if err := json.Unmarshal(imgData, img); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -410,9 +410,9 @@ func containerConfigFromError(solveErr *errdefs.SolveError, cfg *controllerapi.I
|
|||||||
}
|
}
|
||||||
var mounts []gateway.Mount
|
var mounts []gateway.Mount
|
||||||
for i, mnt := range exec.Mounts {
|
for i, mnt := range exec.Mounts {
|
||||||
rid := solveErr.Solve.MountIDs[i]
|
rid := solveErr.MountIDs[i]
|
||||||
if cfg.Initial {
|
if cfg.Initial {
|
||||||
rid = solveErr.Solve.InputIDs[i]
|
rid = solveErr.InputIDs[i]
|
||||||
}
|
}
|
||||||
mounts = append(mounts, gateway.Mount{
|
mounts = append(mounts, gateway.Mount{
|
||||||
Selector: mnt.Selector,
|
Selector: mnt.Selector,
|
||||||
@@ -477,7 +477,7 @@ func execOpFromError(solveErr *errdefs.SolveError) (*pb.ExecOp, error) {
|
|||||||
if solveErr == nil {
|
if solveErr == nil {
|
||||||
return nil, errors.Errorf("no error is available")
|
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:
|
case *pb.Op_Exec:
|
||||||
return op.Exec, nil
|
return op.Exec, nil
|
||||||
default:
|
default:
|
||||||
|
|||||||
+5
-5
@@ -122,7 +122,7 @@ func New(dockerCli command.Cli, opts ...Option) (_ *Builder, err error) {
|
|||||||
|
|
||||||
// Validate validates builder context
|
// Validate validates builder context
|
||||||
func (b *Builder) Validate() error {
|
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()
|
list, err := b.opts.dockerCli.ContextStore().List()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -144,7 +144,7 @@ func (b *Builder) ContextName() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
for _, cb := range ctxbuilders {
|
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
|
return cb.Name
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -254,7 +254,7 @@ func (b *Builder) Factory(ctx context.Context, dialMeta map[string][]string) (_
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
b.Driver = b.driverFactory.Factory.Name()
|
b.Driver = b.driverFactory.Name()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return b.driverFactory.Factory, err
|
return b.driverFactory.Factory, err
|
||||||
@@ -309,7 +309,7 @@ func GetBuilders(dockerCli command.Cli, txn *store.Txn) ([]*Builder, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
builders[i] = b
|
builders[i] = b
|
||||||
seen[b.NodeGroup.Name] = struct{}{}
|
seen[b.Name] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, c := range contexts {
|
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)
|
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)) }()
|
defer func() { cancel(errors.WithStack(context.Canceled)) }()
|
||||||
|
|
||||||
nodes, err := b.LoadNodes(timeoutCtx, WithData())
|
nodes, err := b.LoadNodes(timeoutCtx, WithData())
|
||||||
|
|||||||
+1
-1
@@ -183,7 +183,7 @@ func (b *Builder) LoadNodes(ctx context.Context, opts ...LoadNodesOption) (_ []N
|
|||||||
// not append (remove the static nodes in the store)
|
// not append (remove the static nodes in the store)
|
||||||
b.NodeGroup.Nodes = dynamicNodes
|
b.NodeGroup.Nodes = dynamicNodes
|
||||||
b.nodes = nodes
|
b.nodes = nodes
|
||||||
b.NodeGroup.Dynamic = true
|
b.Dynamic = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -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
|
// instance only needed for reading remote bake files or building
|
||||||
var driverType string
|
var driverType string
|
||||||
if url != "" || !(in.print || in.list != "") {
|
if url != "" || (!in.print && in.list == "") {
|
||||||
b, err := builder.New(dockerCli,
|
b, err := builder.New(dockerCli,
|
||||||
builder.WithName(in.builder),
|
builder.WithName(in.builder),
|
||||||
builder.WithContextPathHash(contextPathHash),
|
builder.WithContextPathHash(contextPathHash),
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import (
|
|||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/moby/buildkit/util/appcontext"
|
"github.com/moby/buildkit/util/appcontext"
|
||||||
"github.com/moby/buildkit/util/progress/progressui"
|
"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/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
@@ -49,7 +49,7 @@ func runDialStdio(dockerCli command.Cli, opts stdioOptions) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var p *v1.Platform
|
var p *ocispecs.Platform
|
||||||
if opts.platform != "" {
|
if opts.platform != "" {
|
||||||
pp, err := platforms.Parse(opts.platform)
|
pp, err := platforms.Parse(opts.platform)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -335,9 +335,9 @@ workers0:
|
|||||||
out.Error.Sources = errsources.Bytes()
|
out.Error.Sources = errsources.Bytes()
|
||||||
var ve *errdefs.VertexError
|
var ve *errdefs.VertexError
|
||||||
if errors.As(retErr, &ve) {
|
if errors.As(retErr, &ve) {
|
||||||
dgst, err := digest.Parse(ve.Vertex.Digest)
|
dgst, err := digest.Parse(ve.Digest)
|
||||||
if err != nil {
|
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)
|
name, logs, err := loadVertexLogs(ctx, c, rec.Ref, dgst, 16)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -525,9 +525,10 @@ workers0:
|
|||||||
}
|
}
|
||||||
fmt.Fprintf(tw, "Duration:\t%s%s\n", formatDuration(out.Duration), statusStr)
|
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)
|
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")
|
fmt.Fprintf(tw, "Status:\tCanceled\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ func runLogs(ctx context.Context, dockerCli command.Cli, opts logsOptions) error
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var mode progressui.DisplayMode = progressui.DisplayMode(opts.progress)
|
mode := progressui.DisplayMode(opts.progress)
|
||||||
if mode == progressui.AutoMode {
|
if mode == progressui.AutoMode {
|
||||||
mode = progressui.PlainMode
|
mode = progressui.PlainMode
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
"github.com/docker/cli/cli/command"
|
"github.com/docker/cli/cli/command"
|
||||||
"github.com/moby/buildkit/util/progress/progressui"
|
"github.com/moby/buildkit/util/progress/progressui"
|
||||||
"github.com/opencontainers/go-digest"
|
"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/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
@@ -246,7 +246,7 @@ func parseSource(in string) (*imagetools.Source, error) {
|
|||||||
dgst, err := digest.Parse(in)
|
dgst, err := digest.Parse(in)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return &imagetools.Source{
|
return &imagetools.Source{
|
||||||
Desc: ocispec.Descriptor{
|
Desc: ocispecs.Descriptor{
|
||||||
Digest: dgst,
|
Digest: dgst,
|
||||||
},
|
},
|
||||||
}, nil
|
}, nil
|
||||||
@@ -295,9 +295,9 @@ func createCmd(dockerCli command.Cli, opts RootOptions) *cobra.Command {
|
|||||||
return cmd
|
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 {
|
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 != "" {
|
if d2.MediaType != "" {
|
||||||
d1.MediaType = d2.MediaType
|
d1.MediaType = d2.MediaType
|
||||||
|
|||||||
+3
-3
@@ -36,7 +36,7 @@ func runInspect(ctx context.Context, dockerCli command.Cli, in inspectOptions) e
|
|||||||
}
|
}
|
||||||
|
|
||||||
timeoutCtx, cancel := context.WithCancelCause(ctx)
|
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)) }()
|
defer func() { cancel(errors.WithStack(context.Canceled)) }()
|
||||||
|
|
||||||
nodes, err := b.LoadNodes(timeoutCtx, builder.WithData())
|
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)
|
w := tabwriter.NewWriter(os.Stdout, 0, 0, 1, ' ', 0)
|
||||||
fmt.Fprintf(w, "Name:\t%s\n", b.Name)
|
fmt.Fprintf(w, "Name:\t%s\n", b.Name)
|
||||||
fmt.Fprintf(w, "Driver:\t%s\n", b.Driver)
|
fmt.Fprintf(w, "Driver:\t%s\n", b.Driver)
|
||||||
if !b.NodeGroup.LastActivity.IsZero() {
|
if !b.LastActivity.IsZero() {
|
||||||
fmt.Fprintf(w, "Last Activity:\t%v\n", b.NodeGroup.LastActivity)
|
fmt.Fprintf(w, "Last Activity:\t%v\n", b.LastActivity)
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+1
-1
@@ -60,7 +60,7 @@ func runLs(ctx context.Context, dockerCli command.Cli, in lsOptions) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
timeoutCtx, cancel := context.WithCancelCause(ctx)
|
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)) }()
|
defer func() { cancel(errors.WithStack(context.Canceled)) }()
|
||||||
|
|
||||||
eg, _ := errgroup.WithContext(timeoutCtx)
|
eg, _ := errgroup.WithContext(timeoutCtx)
|
||||||
|
|||||||
+1
-1
@@ -151,7 +151,7 @@ func rmAllInactive(ctx context.Context, txn *store.Txn, dockerCli command.Cli, i
|
|||||||
}
|
}
|
||||||
|
|
||||||
timeoutCtx, cancel := context.WithCancelCause(ctx)
|
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)) }()
|
defer func() { cancel(errors.WithStack(context.Canceled)) }()
|
||||||
|
|
||||||
eg, _ := errgroup.WithContext(timeoutCtx)
|
eg, _ := errgroup.WithContext(timeoutCtx)
|
||||||
|
|||||||
@@ -38,6 +38,9 @@ target "lint" {
|
|||||||
inherits = ["_common"]
|
inherits = ["_common"]
|
||||||
dockerfile = "./hack/dockerfiles/lint.Dockerfile"
|
dockerfile = "./hack/dockerfiles/lint.Dockerfile"
|
||||||
output = ["type=cacheonly"]
|
output = ["type=cacheonly"]
|
||||||
|
args = {
|
||||||
|
GOLANGCI_FROM_SOURCE = "true"
|
||||||
|
}
|
||||||
platforms = GOLANGCI_LINT_MULTIPLATFORM != "" ? [
|
platforms = GOLANGCI_LINT_MULTIPLATFORM != "" ? [
|
||||||
"darwin/amd64",
|
"darwin/amd64",
|
||||||
"darwin/arm64",
|
"darwin/arm64",
|
||||||
|
|||||||
@@ -138,28 +138,28 @@ func (d *Driver) create(ctx context.Context, l progress.SubLogger) error {
|
|||||||
hc.NetworkMode = container.NetworkMode(d.netMode)
|
hc.NetworkMode = container.NetworkMode(d.netMode)
|
||||||
}
|
}
|
||||||
if d.memory != 0 {
|
if d.memory != 0 {
|
||||||
hc.Resources.Memory = int64(d.memory)
|
hc.Memory = int64(d.memory)
|
||||||
}
|
}
|
||||||
if d.memorySwap != 0 {
|
if d.memorySwap != 0 {
|
||||||
hc.Resources.MemorySwap = int64(d.memorySwap)
|
hc.MemorySwap = int64(d.memorySwap)
|
||||||
}
|
}
|
||||||
if d.cpuQuota != 0 {
|
if d.cpuQuota != 0 {
|
||||||
hc.Resources.CPUQuota = d.cpuQuota
|
hc.CPUQuota = d.cpuQuota
|
||||||
}
|
}
|
||||||
if d.cpuPeriod != 0 {
|
if d.cpuPeriod != 0 {
|
||||||
hc.Resources.CPUPeriod = d.cpuPeriod
|
hc.CPUPeriod = d.cpuPeriod
|
||||||
}
|
}
|
||||||
if d.cpuShares != 0 {
|
if d.cpuShares != 0 {
|
||||||
hc.Resources.CPUShares = d.cpuShares
|
hc.CPUShares = d.cpuShares
|
||||||
}
|
}
|
||||||
if d.cpusetCpus != "" {
|
if d.cpusetCpus != "" {
|
||||||
hc.Resources.CpusetCpus = d.cpusetCpus
|
hc.CpusetCpus = d.cpusetCpus
|
||||||
}
|
}
|
||||||
if d.cpusetMems != "" {
|
if d.cpusetMems != "" {
|
||||||
hc.Resources.CpusetMems = d.cpusetMems
|
hc.CpusetMems = d.cpusetMems
|
||||||
}
|
}
|
||||||
if len(d.gpus) > 0 && d.hasGPUCapability(ctx, cfg.Image, d.gpus) {
|
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, err := d.DockerAPI.Info(ctx); err == nil {
|
||||||
if info.CgroupDriver == "cgroupfs" {
|
if info.CgroupDriver == "cgroupfs" {
|
||||||
@@ -187,7 +187,7 @@ func (d *Driver) create(ctx context.Context, l progress.SubLogger) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if err := d.copyToContainer(ctx, d.InitConfig.Files); err != nil {
|
if err := d.copyToContainer(ctx, d.Files); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if err := d.start(ctx); err != nil {
|
if err := d.start(ctx); err != nil {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/docker/buildx/util/platformutil"
|
"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"
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/resource"
|
"k8s.io/apimachinery/pkg/api/resource"
|
||||||
@@ -43,7 +43,7 @@ type DeploymentOpt struct {
|
|||||||
LimitsCPU string
|
LimitsCPU string
|
||||||
LimitsMemory string
|
LimitsMemory string
|
||||||
LimitsEphemeralStorage string
|
LimitsEphemeralStorage string
|
||||||
Platforms []v1.Platform
|
Platforms []ocispecs.Platform
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -260,10 +260,10 @@ func toRootless(d *appsv1.Deployment) error {
|
|||||||
Type: corev1.SeccompProfileTypeUnconfined,
|
Type: corev1.SeccompProfileTypeUnconfined,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if d.Spec.Template.ObjectMeta.Annotations == nil {
|
if d.Spec.Template.Annotations == nil {
|
||||||
d.Spec.Template.ObjectMeta.Annotations = make(map[string]string, 1)
|
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,
|
// 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
|
// but the default VOLUME does not work with rootless on Google's Container-Optimized OS
|
||||||
|
|||||||
+2
-2
@@ -9,7 +9,7 @@ import (
|
|||||||
dockerclient "github.com/docker/docker/client"
|
dockerclient "github.com/docker/docker/client"
|
||||||
"github.com/moby/buildkit/client"
|
"github.com/moby/buildkit/client"
|
||||||
"github.com/moby/buildkit/util/tracing/delegated"
|
"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"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ type InitConfig struct {
|
|||||||
Files map[string][]byte
|
Files map[string][]byte
|
||||||
DriverOpts map[string]string
|
DriverOpts map[string]string
|
||||||
Auth Auth
|
Auth Auth
|
||||||
Platforms []specs.Platform
|
Platforms []ocispecs.Platform
|
||||||
ContextPathHash string
|
ContextPathHash string
|
||||||
DialMeta map[string][]string
|
DialMeta map[string][]string
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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 {
|
return progress.Wrap("[internal] waiting for connection", l, func(_ progress.SubLogger) error {
|
||||||
cancelCtx, cancel := context.WithCancelCause(ctx)
|
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)) }()
|
defer func() { cancel(errors.WithStack(context.Canceled)) }()
|
||||||
return c.Wait(ctx)
|
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) {
|
func (d *Driver) Dial(ctx context.Context) (net.Conn, error) {
|
||||||
addr := d.InitConfig.EndpointAddr
|
addr := d.EndpointAddr
|
||||||
ch, err := connhelper.GetConnectionHelper(addr)
|
ch, err := connhelper.GetConnectionHelper(addr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -112,7 +112,7 @@ func (d *Driver) Dial(ctx context.Context) (net.Conn, error) {
|
|||||||
|
|
||||||
network, addr, ok := strings.Cut(addr, "://")
|
network, addr, ok := strings.Cut(addr, "://")
|
||||||
if !ok {
|
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)
|
conn, err := util.DialContext(ctx, network, addr)
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ ARG GO_VERSION=1.23
|
|||||||
ARG ALPINE_VERSION=3.21
|
ARG ALPINE_VERSION=3.21
|
||||||
ARG XX_VERSION=1.6.1
|
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
|
ARG GOLANGCI_FROM_SOURCE=false
|
||||||
# v0.31 requires go1.24
|
# v0.31 requires go1.24
|
||||||
ARG GOPLS_VERSION=v0.30.0
|
ARG GOPLS_VERSION=v0.30.0
|
||||||
|
|||||||
+5
-5
@@ -9,7 +9,7 @@ import (
|
|||||||
"github.com/containerd/platforms"
|
"github.com/containerd/platforms"
|
||||||
"github.com/docker/buildx/util/confutil"
|
"github.com/docker/buildx/util/confutil"
|
||||||
"github.com/docker/buildx/util/platformutil"
|
"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/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@@ -28,7 +28,7 @@ type NodeGroup struct {
|
|||||||
type Node struct {
|
type Node struct {
|
||||||
Name string
|
Name string
|
||||||
Endpoint string
|
Endpoint string
|
||||||
Platforms []specs.Platform
|
Platforms []ocispecs.Platform
|
||||||
DriverOpts map[string]string
|
DriverOpts map[string]string
|
||||||
BuildkitdFlags []string `json:"Flags"` // keep the field name for backward compatibility
|
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 {
|
func (n *Node) Copy() *Node {
|
||||||
platforms := []specs.Platform{}
|
platforms := []ocispecs.Platform{}
|
||||||
copy(platforms, n.Platforms)
|
copy(platforms, n.Platforms)
|
||||||
buildkitdFlags := []string{}
|
buildkitdFlags := []string{}
|
||||||
copy(buildkitdFlags, n.BuildkitdFlags)
|
copy(buildkitdFlags, n.BuildkitdFlags)
|
||||||
@@ -210,8 +210,8 @@ func (ng *NodeGroup) nextNodeName() string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func filterPlatforms(in []specs.Platform, m map[string]struct{}) []specs.Platform {
|
func filterPlatforms(in []ocispecs.Platform, m map[string]struct{}) []ocispecs.Platform {
|
||||||
out := make([]specs.Platform, 0, len(in))
|
out := make([]ocispecs.Platform, 0, len(in))
|
||||||
for _, p := range in {
|
for _, p := range in {
|
||||||
if _, ok := m[platforms.Format(p)]; !ok {
|
if _, ok := m[platforms.Format(p)]; !ok {
|
||||||
out = append(out, p)
|
out = append(out, p)
|
||||||
|
|||||||
+23
-23
@@ -18,17 +18,17 @@ import (
|
|||||||
"github.com/moby/buildkit/util/contentutil"
|
"github.com/moby/buildkit/util/contentutil"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
"github.com/opencontainers/image-spec/specs-go"
|
"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"
|
"github.com/pkg/errors"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Source struct {
|
type Source struct {
|
||||||
Desc ocispec.Descriptor
|
Desc ocispecs.Descriptor
|
||||||
Ref reference.Named
|
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)
|
eg, ctx := errgroup.WithContext(ctx)
|
||||||
|
|
||||||
dts := make([][]byte, len(srcs))
|
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
|
mt := srcs[i].Desc.MediaType
|
||||||
|
|
||||||
switch mt {
|
switch mt {
|
||||||
case images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest:
|
case images.MediaTypeDockerSchema2Manifest, ocispecs.MediaTypeImageManifest:
|
||||||
p := srcs[i].Desc.Platform
|
p := srcs[i].Desc.Platform
|
||||||
if srcs[i].Desc.Platform == nil {
|
if srcs[i].Desc.Platform == nil {
|
||||||
p = &ocispec.Platform{}
|
p = &ocispecs.Platform{}
|
||||||
}
|
}
|
||||||
if p.OS == "" || p.Architecture == "" {
|
if p.OS == "" || p.Architecture == "" {
|
||||||
if err := r.loadPlatform(ctx, p, srcs[i].Ref.String(), dt); err != nil {
|
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 {
|
if err := eg.Wait(); err != nil {
|
||||||
return nil, ocispec.Descriptor{}, err
|
return nil, ocispecs.Descriptor{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// on single source, return original bytes
|
// 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
|
// 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
|
// 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
|
// 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
|
return dts[0], srcs[0].Desc, nil
|
||||||
default:
|
default:
|
||||||
if !preferIndex {
|
if !preferIndex {
|
||||||
@@ -92,9 +92,9 @@ func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann map[exptypes
|
|||||||
}
|
}
|
||||||
|
|
||||||
m := map[digest.Digest]int{}
|
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]
|
idx, ok := m[d.Digest]
|
||||||
if ok {
|
if ok {
|
||||||
old := newDescs[idx]
|
old := newDescs[idx]
|
||||||
@@ -117,10 +117,10 @@ func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann map[exptypes
|
|||||||
|
|
||||||
for i, src := range srcs {
|
for i, src := range srcs {
|
||||||
switch src.Desc.MediaType {
|
switch src.Desc.MediaType {
|
||||||
case images.MediaTypeDockerSchema2ManifestList, ocispec.MediaTypeImageIndex:
|
case images.MediaTypeDockerSchema2ManifestList, ocispecs.MediaTypeImageIndex:
|
||||||
var mfst ocispec.Index
|
var mfst ocispecs.Index
|
||||||
if err := json.Unmarshal(dts[i], &mfst); err != nil {
|
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 {
|
for _, d := range mfst.Manifests {
|
||||||
addDesc(d)
|
addDesc(d)
|
||||||
@@ -143,12 +143,12 @@ func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann map[exptypes
|
|||||||
mt = images.MediaTypeDockerSchema2ManifestList
|
mt = images.MediaTypeDockerSchema2ManifestList
|
||||||
} else {
|
} else {
|
||||||
// otherwise, use OCI index
|
// otherwise, use OCI index
|
||||||
mt = ocispec.MediaTypeImageIndex
|
mt = ocispecs.MediaTypeImageIndex
|
||||||
}
|
}
|
||||||
|
|
||||||
// annotations are only allowed on OCI indexes
|
// annotations are only allowed on OCI indexes
|
||||||
indexAnnotation := make(map[string]string)
|
indexAnnotation := make(map[string]string)
|
||||||
if mt == ocispec.MediaTypeImageIndex {
|
if mt == ocispecs.MediaTypeImageIndex {
|
||||||
for k, v := range ann {
|
for k, v := range ann {
|
||||||
switch k.Type {
|
switch k.Type {
|
||||||
case exptypes.AnnotationIndex:
|
case exptypes.AnnotationIndex:
|
||||||
@@ -163,14 +163,14 @@ func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann map[exptypes
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
case exptypes.AnnotationManifest, "":
|
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:
|
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,
|
MediaType: mt,
|
||||||
Versioned: specs.Versioned{
|
Versioned: specs.Versioned{
|
||||||
SchemaVersion: 2,
|
SchemaVersion: 2,
|
||||||
@@ -179,17 +179,17 @@ func (r *Resolver) Combine(ctx context.Context, srcs []*Source, ann map[exptypes
|
|||||||
Annotations: indexAnnotation,
|
Annotations: indexAnnotation,
|
||||||
}, "", " ")
|
}, "", " ")
|
||||||
if err != nil {
|
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,
|
MediaType: mt,
|
||||||
Size: int64(len(idxBytes)),
|
Size: int64(len(idxBytes)),
|
||||||
Digest: digest.FromBytes(idxBytes),
|
Digest: digest.FromBytes(idxBytes),
|
||||||
}, nil
|
}, 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")
|
ctx = remotes.WithMediaTypeKeyPrefix(ctx, "application/vnd.in-toto+json", "intoto")
|
||||||
|
|
||||||
fullRef, err := reference.WithDigest(reference.TagNameOnly(ref), desc.Digest)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *Resolver) loadPlatform(ctx context.Context, p2 *ocispec.Platform, in string, dt []byte) error {
|
func (r *Resolver) loadPlatform(ctx context.Context, p2 *ocispecs.Platform, in string, dt []byte) error {
|
||||||
var manifest ocispec.Manifest
|
var manifest ocispecs.Manifest
|
||||||
if err := json.Unmarshal(dt, &manifest); err != nil {
|
if err := json.Unmarshal(dt, &manifest); err != nil {
|
||||||
return errors.WithStack(err)
|
return errors.WithStack(err)
|
||||||
}
|
}
|
||||||
@@ -263,7 +263,7 @@ func (r *Resolver) loadPlatform(ctx context.Context, p2 *ocispec.Platform, in st
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var p ocispec.Platform
|
var p ocispecs.Platform
|
||||||
if err := json.Unmarshal(dt, &p); err != nil {
|
if err := json.Unmarshal(dt, &p); err != nil {
|
||||||
return errors.WithStack(err)
|
return errors.WithStack(err)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,8 +12,7 @@ import (
|
|||||||
intoto "github.com/in-toto/in-toto-golang/in_toto"
|
intoto "github.com/in-toto/in-toto-golang/in_toto"
|
||||||
slsa02 "github.com/in-toto/in-toto-golang/in_toto/slsa_provenance/v0.2"
|
slsa02 "github.com/in-toto/in-toto-golang/in_toto/slsa_provenance/v0.2"
|
||||||
"github.com/opencontainers/go-digest"
|
"github.com/opencontainers/go-digest"
|
||||||
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
|
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
|
||||||
v1 "github.com/opencontainers/image-spec/specs-go/v1"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type attestationType int
|
type attestationType int
|
||||||
@@ -35,12 +34,12 @@ type mockResolver struct {
|
|||||||
var manifests = make(map[digest.Digest]manifest)
|
var manifests = make(map[digest.Digest]manifest)
|
||||||
var indexes = make(map[digest.Digest]index)
|
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 {
|
switch desc.MediaType {
|
||||||
case ocispec.MediaTypeImageIndex:
|
case ocispecs.MediaTypeImageIndex:
|
||||||
reader := io.NopCloser(strings.NewReader(indexes[desc.Digest].desc.Annotations["test_content"]))
|
reader := io.NopCloser(strings.NewReader(indexes[desc.Digest].desc.Annotations["test_content"]))
|
||||||
return reader, nil
|
return reader, nil
|
||||||
case ocispec.MediaTypeImageManifest:
|
case ocispecs.MediaTypeImageManifest:
|
||||||
reader := io.NopCloser(strings.NewReader(manifests[desc.Digest].desc.Annotations["test_content"]))
|
reader := io.NopCloser(strings.NewReader(manifests[desc.Digest].desc.Annotations["test_content"]))
|
||||||
return reader, nil
|
return reader, nil
|
||||||
default:
|
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@", ""))
|
d := digest.Digest(strings.ReplaceAll(ref, "docker.io/library/test@", ""))
|
||||||
return string(d), indexes[d].desc, nil
|
return string(d), indexes[d].desc, nil
|
||||||
}
|
}
|
||||||
@@ -77,8 +76,8 @@ func getImageNoAttestation() *result {
|
|||||||
func getImageWithAttestation(t attestationType) *result {
|
func getImageWithAttestation(t attestationType) *result {
|
||||||
manifestList := getBaseManifests()
|
manifestList := getBaseManifests()
|
||||||
|
|
||||||
objManifest := ocispec.Manifest{
|
objManifest := ocispecs.Manifest{
|
||||||
MediaType: v1.MediaTypeImageManifest,
|
MediaType: ocispecs.MediaTypeImageManifest,
|
||||||
Layers: getAttestationLayers(t),
|
Layers: getAttestationLayers(t),
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
"platform": "linux/amd64",
|
"platform": "linux/amd64",
|
||||||
@@ -89,8 +88,8 @@ func getImageWithAttestation(t attestationType) *result {
|
|||||||
d := digest.FromString(jsonString)
|
d := digest.FromString(jsonString)
|
||||||
|
|
||||||
manifestList[d] = manifest{
|
manifestList[d] = manifest{
|
||||||
desc: ocispec.Descriptor{
|
desc: ocispecs.Descriptor{
|
||||||
MediaType: v1.MediaTypeImageManifest,
|
MediaType: ocispecs.MediaTypeImageManifest,
|
||||||
Digest: d,
|
Digest: d,
|
||||||
Size: int64(len(jsonString)),
|
Size: int64(len(jsonString)),
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
@@ -98,7 +97,7 @@ func getImageWithAttestation(t attestationType) *result {
|
|||||||
"vnd.docker.reference.type": "attestation-manifest",
|
"vnd.docker.reference.type": "attestation-manifest",
|
||||||
"test_content": jsonString,
|
"test_content": jsonString,
|
||||||
},
|
},
|
||||||
Platform: &v1.Platform{
|
Platform: &ocispecs.Platform{
|
||||||
Architecture: "unknown",
|
Architecture: "unknown",
|
||||||
OS: "unknown",
|
OS: "unknown",
|
||||||
},
|
},
|
||||||
@@ -106,8 +105,8 @@ func getImageWithAttestation(t attestationType) *result {
|
|||||||
manifest: objManifest,
|
manifest: objManifest,
|
||||||
}
|
}
|
||||||
|
|
||||||
objManifest = ocispec.Manifest{
|
objManifest = ocispecs.Manifest{
|
||||||
MediaType: v1.MediaTypeImageManifest,
|
MediaType: ocispecs.MediaTypeImageManifest,
|
||||||
Layers: getAttestationLayers(t),
|
Layers: getAttestationLayers(t),
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
"platform": "linux/arm64",
|
"platform": "linux/arm64",
|
||||||
@@ -117,8 +116,8 @@ func getImageWithAttestation(t attestationType) *result {
|
|||||||
jsonString = string(jsonContent)
|
jsonString = string(jsonContent)
|
||||||
d = digest.FromString(jsonString)
|
d = digest.FromString(jsonString)
|
||||||
manifestList[d] = manifest{
|
manifestList[d] = manifest{
|
||||||
desc: ocispec.Descriptor{
|
desc: ocispecs.Descriptor{
|
||||||
MediaType: v1.MediaTypeImageManifest,
|
MediaType: ocispecs.MediaTypeImageManifest,
|
||||||
Digest: d,
|
Digest: d,
|
||||||
Size: int64(len(jsonString)),
|
Size: int64(len(jsonString)),
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
@@ -126,7 +125,7 @@ func getImageWithAttestation(t attestationType) *result {
|
|||||||
"vnd.docker.reference.type": "attestation-manifest",
|
"vnd.docker.reference.type": "attestation-manifest",
|
||||||
"test_content": jsonString,
|
"test_content": jsonString,
|
||||||
},
|
},
|
||||||
Platform: &v1.Platform{
|
Platform: &ocispecs.Platform{
|
||||||
Architecture: "unknown",
|
Architecture: "unknown",
|
||||||
OS: "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/amd64"] = getManifestDigestForArch(manifests, "linux", "amd64")
|
||||||
r.images["linux/arm64"] = getManifestDigestForArch(manifests, "linux", "arm64")
|
r.images["linux/arm64"] = getManifestDigestForArch(manifests, "linux", "arm64")
|
||||||
|
|
||||||
manifestsDesc := []v1.Descriptor{}
|
manifestsDesc := []ocispecs.Descriptor{}
|
||||||
for _, val := range manifests {
|
for _, val := range manifests {
|
||||||
manifestsDesc = append(manifestsDesc, val.desc)
|
manifestsDesc = append(manifestsDesc, val.desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
objIndex := v1.Index{
|
objIndex := ocispecs.Index{
|
||||||
MediaType: v1.MediaTypeImageIndex,
|
MediaType: ocispecs.MediaTypeImageIndex,
|
||||||
Manifests: manifestsDesc,
|
Manifests: manifestsDesc,
|
||||||
}
|
}
|
||||||
jsonContent, _ := json.Marshal(objIndex)
|
jsonContent, _ := json.Marshal(objIndex)
|
||||||
@@ -163,8 +162,8 @@ func getImageFromManifests(manifests map[digest.Digest]manifest) *result {
|
|||||||
|
|
||||||
if _, ok := indexes[d]; !ok {
|
if _, ok := indexes[d]; !ok {
|
||||||
indexes[d] = index{
|
indexes[d] = index{
|
||||||
desc: ocispec.Descriptor{
|
desc: ocispecs.Descriptor{
|
||||||
MediaType: v1.MediaTypeImageIndex,
|
MediaType: ocispecs.MediaTypeImageIndex,
|
||||||
Digest: d,
|
Digest: d,
|
||||||
Size: int64(len(jsonString)),
|
Size: int64(len(jsonString)),
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
@@ -193,12 +192,12 @@ func getBaseManifests() map[digest.Digest]manifest {
|
|||||||
if len(manifests) == 0 {
|
if len(manifests) == 0 {
|
||||||
config := getConfig()
|
config := getConfig()
|
||||||
content := "amd64-content"
|
content := "amd64-content"
|
||||||
objManifest := ocispec.Manifest{
|
objManifest := ocispecs.Manifest{
|
||||||
MediaType: v1.MediaTypeImageManifest,
|
MediaType: ocispecs.MediaTypeImageManifest,
|
||||||
Config: config,
|
Config: config,
|
||||||
Layers: []v1.Descriptor{
|
Layers: []ocispecs.Descriptor{
|
||||||
{
|
{
|
||||||
MediaType: v1.MediaTypeImageLayerGzip,
|
MediaType: ocispecs.MediaTypeImageLayerGzip,
|
||||||
Digest: digest.FromString(content),
|
Digest: digest.FromString(content),
|
||||||
Size: int64(len(content)),
|
Size: int64(len(content)),
|
||||||
},
|
},
|
||||||
@@ -209,11 +208,11 @@ func getBaseManifests() map[digest.Digest]manifest {
|
|||||||
d := digest.FromString(jsonString)
|
d := digest.FromString(jsonString)
|
||||||
|
|
||||||
manifests[d] = manifest{
|
manifests[d] = manifest{
|
||||||
desc: ocispec.Descriptor{
|
desc: ocispecs.Descriptor{
|
||||||
MediaType: v1.MediaTypeImageManifest,
|
MediaType: ocispecs.MediaTypeImageManifest,
|
||||||
Digest: d,
|
Digest: d,
|
||||||
Size: int64(len(jsonString)),
|
Size: int64(len(jsonString)),
|
||||||
Platform: &v1.Platform{
|
Platform: &ocispecs.Platform{
|
||||||
Architecture: "amd64",
|
Architecture: "amd64",
|
||||||
OS: "linux",
|
OS: "linux",
|
||||||
},
|
},
|
||||||
@@ -225,12 +224,12 @@ func getBaseManifests() map[digest.Digest]manifest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
content = "arm64-content"
|
content = "arm64-content"
|
||||||
objManifest = ocispec.Manifest{
|
objManifest = ocispecs.Manifest{
|
||||||
MediaType: v1.MediaTypeImageManifest,
|
MediaType: ocispecs.MediaTypeImageManifest,
|
||||||
Config: config,
|
Config: config,
|
||||||
Layers: []v1.Descriptor{
|
Layers: []ocispecs.Descriptor{
|
||||||
{
|
{
|
||||||
MediaType: v1.MediaTypeImageLayerGzip,
|
MediaType: ocispecs.MediaTypeImageLayerGzip,
|
||||||
Digest: digest.FromString(content),
|
Digest: digest.FromString(content),
|
||||||
Size: int64(len(content)),
|
Size: int64(len(content)),
|
||||||
},
|
},
|
||||||
@@ -241,11 +240,11 @@ func getBaseManifests() map[digest.Digest]manifest {
|
|||||||
d = digest.FromString(jsonString)
|
d = digest.FromString(jsonString)
|
||||||
|
|
||||||
manifests[d] = manifest{
|
manifests[d] = manifest{
|
||||||
desc: ocispec.Descriptor{
|
desc: ocispecs.Descriptor{
|
||||||
MediaType: v1.MediaTypeImageManifest,
|
MediaType: ocispecs.MediaTypeImageManifest,
|
||||||
Digest: d,
|
Digest: d,
|
||||||
Size: int64(len(jsonString)),
|
Size: int64(len(jsonString)),
|
||||||
Platform: &v1.Platform{
|
Platform: &ocispecs.Platform{
|
||||||
Architecture: "arm64",
|
Architecture: "arm64",
|
||||||
OS: "linux",
|
OS: "linux",
|
||||||
},
|
},
|
||||||
@@ -260,8 +259,8 @@ func getBaseManifests() map[digest.Digest]manifest {
|
|||||||
return manifests
|
return manifests
|
||||||
}
|
}
|
||||||
|
|
||||||
func getConfig() v1.Descriptor {
|
func getConfig() ocispecs.Descriptor {
|
||||||
config := v1.ImageConfig{
|
config := ocispecs.ImageConfig{
|
||||||
Env: []string{
|
Env: []string{
|
||||||
"config",
|
"config",
|
||||||
},
|
},
|
||||||
@@ -270,8 +269,8 @@ func getConfig() v1.Descriptor {
|
|||||||
jsonString := string(jsonContent)
|
jsonString := string(jsonContent)
|
||||||
d := digest.FromString(jsonString)
|
d := digest.FromString(jsonString)
|
||||||
|
|
||||||
return v1.Descriptor{
|
return ocispecs.Descriptor{
|
||||||
MediaType: ocispec.MediaTypeImageConfig,
|
MediaType: ocispecs.MediaTypeImageConfig,
|
||||||
Digest: d,
|
Digest: d,
|
||||||
Size: int64(len(jsonString)),
|
Size: int64(len(jsonString)),
|
||||||
Annotations: map[string]string{
|
Annotations: map[string]string{
|
||||||
@@ -280,11 +279,11 @@ func getConfig() v1.Descriptor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func getAttestationLayers(t attestationType) []v1.Descriptor {
|
func getAttestationLayers(t attestationType) []ocispecs.Descriptor {
|
||||||
layers := []v1.Descriptor{}
|
layers := []ocispecs.Descriptor{}
|
||||||
|
|
||||||
if t == plainSpdx || t == plainSpdxAndDSSEEmbed {
|
if t == plainSpdx || t == plainSpdxAndDSSEEmbed {
|
||||||
layers = append(layers, v1.Descriptor{
|
layers = append(layers, ocispecs.Descriptor{
|
||||||
MediaType: inTotoGenericMime,
|
MediaType: inTotoGenericMime,
|
||||||
Digest: digest.FromString(attestationContent),
|
Digest: digest.FromString(attestationContent),
|
||||||
Size: int64(len(attestationContent)),
|
Size: int64(len(attestationContent)),
|
||||||
@@ -293,7 +292,7 @@ func getAttestationLayers(t attestationType) []v1.Descriptor {
|
|||||||
"test_content": attestationContent,
|
"test_content": attestationContent,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
layers = append(layers, v1.Descriptor{
|
layers = append(layers, ocispecs.Descriptor{
|
||||||
MediaType: inTotoGenericMime,
|
MediaType: inTotoGenericMime,
|
||||||
Digest: digest.FromString(provenanceContent),
|
Digest: digest.FromString(provenanceContent),
|
||||||
Size: int64(len(provenanceContent)),
|
Size: int64(len(provenanceContent)),
|
||||||
@@ -307,7 +306,7 @@ func getAttestationLayers(t attestationType) []v1.Descriptor {
|
|||||||
if t == dsseEmbeded || t == plainSpdxAndDSSEEmbed {
|
if t == dsseEmbeded || t == plainSpdxAndDSSEEmbed {
|
||||||
dsseAttestation := fmt.Sprintf("{\"payload\":\"%s\"}", base64.StdEncoding.EncodeToString([]byte(attestationContent)))
|
dsseAttestation := fmt.Sprintf("{\"payload\":\"%s\"}", base64.StdEncoding.EncodeToString([]byte(attestationContent)))
|
||||||
dsseProvenance := fmt.Sprintf("{\"payload\":\"%s\"}", base64.StdEncoding.EncodeToString([]byte(provenanceContent)))
|
dsseProvenance := fmt.Sprintf("{\"payload\":\"%s\"}", base64.StdEncoding.EncodeToString([]byte(provenanceContent)))
|
||||||
layers = append(layers, v1.Descriptor{
|
layers = append(layers, ocispecs.Descriptor{
|
||||||
MediaType: inTotoSPDXDSSEMime,
|
MediaType: inTotoSPDXDSSEMime,
|
||||||
Digest: digest.FromString(dsseAttestation),
|
Digest: digest.FromString(dsseAttestation),
|
||||||
Size: int64(len(dsseAttestation)),
|
Size: int64(len(dsseAttestation)),
|
||||||
@@ -316,7 +315,7 @@ func getAttestationLayers(t attestationType) []v1.Descriptor {
|
|||||||
"test_content": dsseAttestation,
|
"test_content": dsseAttestation,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
layers = append(layers, v1.Descriptor{
|
layers = append(layers, ocispecs.Descriptor{
|
||||||
MediaType: inTotoProvenanceDSSEMime,
|
MediaType: inTotoProvenanceDSSEMime,
|
||||||
Digest: digest.FromString(dsseProvenance),
|
Digest: digest.FromString(dsseProvenance),
|
||||||
Size: int64(len(dsseProvenance)),
|
Size: int64(len(dsseProvenance)),
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import (
|
|||||||
clitypes "github.com/docker/cli/cli/config/types"
|
clitypes "github.com/docker/cli/cli/config/types"
|
||||||
"github.com/moby/buildkit/util/contentutil"
|
"github.com/moby/buildkit/util/contentutil"
|
||||||
"github.com/moby/buildkit/util/tracing"
|
"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"
|
"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.
|
// discard containerd logger to avoid printing unnecessary info during image reference resolution.
|
||||||
// https://github.com/containerd/containerd/blob/1a88cf5242445657258e0c744def5017d7cfb492/remotes/docker/resolver.go#L288
|
// https://github.com/containerd/containerd/blob/1a88cf5242445657258e0c744def5017d7cfb492/remotes/docker/resolver.go#L288
|
||||||
logger := logrus.New()
|
logger := logrus.New()
|
||||||
@@ -68,31 +68,31 @@ func (r *Resolver) Resolve(ctx context.Context, in string) (string, ocispec.Desc
|
|||||||
|
|
||||||
ref, err := parseRef(in)
|
ref, err := parseRef(in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", ocispec.Descriptor{}, err
|
return "", ocispecs.Descriptor{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
in, desc, err := r.resolver().Resolve(ctx, ref.String())
|
in, desc, err := r.resolver().Resolve(ctx, ref.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", ocispec.Descriptor{}, err
|
return "", ocispecs.Descriptor{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return in, desc, nil
|
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)
|
in, desc, err := r.Resolve(ctx, in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ocispec.Descriptor{}, err
|
return nil, ocispecs.Descriptor{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
dt, err := r.GetDescriptor(ctx, in, desc)
|
dt, err := r.GetDescriptor(ctx, in, desc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ocispec.Descriptor{}, err
|
return nil, ocispecs.Descriptor{}, err
|
||||||
}
|
}
|
||||||
return dt, desc, nil
|
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)
|
fetcher, err := r.resolver().Fetcher(ctx, in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
+17
-17
@@ -20,7 +20,7 @@ import (
|
|||||||
intoto "github.com/in-toto/in-toto-golang/in_toto"
|
intoto "github.com/in-toto/in-toto-golang/in_toto"
|
||||||
"github.com/moby/buildkit/util/contentutil"
|
"github.com/moby/buildkit/util/contentutil"
|
||||||
"github.com/opencontainers/go-digest"
|
"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/pkg/errors"
|
||||||
"golang.org/x/sync/errgroup"
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
@@ -49,17 +49,17 @@ type loader struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type manifest struct {
|
type manifest struct {
|
||||||
desc ocispec.Descriptor
|
desc ocispecs.Descriptor
|
||||||
manifest ocispec.Manifest
|
manifest ocispecs.Manifest
|
||||||
}
|
}
|
||||||
|
|
||||||
type index struct {
|
type index struct {
|
||||||
desc ocispec.Descriptor
|
desc ocispecs.Descriptor
|
||||||
index ocispec.Index
|
index ocispecs.Index
|
||||||
}
|
}
|
||||||
|
|
||||||
type asset struct {
|
type asset struct {
|
||||||
config *ocispec.Image
|
config *ocispecs.Image
|
||||||
sbom *sbomStub
|
sbom *sbomStub
|
||||||
provenance *provenanceStub
|
provenance *provenanceStub
|
||||||
|
|
||||||
@@ -153,15 +153,15 @@ func (l *loader) Load(ctx context.Context, ref string) (*result, error) {
|
|||||||
return r, nil
|
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)
|
_, err := remotes.FetchHandler(l.cache, fetcher)(ctx, desc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch desc.MediaType {
|
switch desc.MediaType {
|
||||||
case images.MediaTypeDockerSchema2Manifest, ocispec.MediaTypeImageManifest:
|
case images.MediaTypeDockerSchema2Manifest, ocispecs.MediaTypeImageManifest:
|
||||||
var mfst ocispec.Manifest
|
var mfst ocispecs.Manifest
|
||||||
dt, err := content.ReadBlob(ctx, l.cache, desc)
|
dt, err := content.ReadBlob(ctx, l.cache, desc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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.images[platforms.Format(platforms.Normalize(*p))] = desc.Digest
|
||||||
r.mu.Unlock()
|
r.mu.Unlock()
|
||||||
}
|
}
|
||||||
case images.MediaTypeDockerSchema2ManifestList, ocispec.MediaTypeImageIndex:
|
case images.MediaTypeDockerSchema2ManifestList, ocispecs.MediaTypeImageIndex:
|
||||||
var idx ocispec.Index
|
var idx ocispecs.Index
|
||||||
dt, err := content.ReadBlob(ctx, l.cache, desc)
|
dt, err := content.ReadBlob(ctx, l.cache, desc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -239,7 +239,7 @@ func (l *loader) fetch(ctx context.Context, fetcher remotes.Fetcher, desc ocispe
|
|||||||
return nil
|
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)
|
_, err := remotes.FetchHandler(l.cache, fetcher)(ctx, desc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -250,19 +250,19 @@ func (l *loader) readPlatformFromConfig(ctx context.Context, fetcher remotes.Fet
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var config ocispec.Image
|
var config ocispecs.Image
|
||||||
if err := json.Unmarshal(dt, &config); err != nil {
|
if err := json.Unmarshal(dt, &config); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return &ocispec.Platform{
|
return &ocispecs.Platform{
|
||||||
OS: config.OS,
|
OS: config.OS,
|
||||||
Architecture: config.Architecture,
|
Architecture: config.Architecture,
|
||||||
Variant: config.Variant,
|
Variant: config.Variant,
|
||||||
}, nil
|
}, 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)
|
_, err := remotes.FetchHandler(l.cache, fetcher)(ctx, desc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -374,11 +374,11 @@ func (l *loader) scanProvenance(ctx context.Context, fetcher remotes.Fetcher, r
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *result) Configs() map[string]*ocispec.Image {
|
func (r *result) Configs() map[string]*ocispecs.Image {
|
||||||
if len(r.assets) == 0 {
|
if len(r.assets) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
res := make(map[string]*ocispec.Image)
|
res := make(map[string]*ocispecs.Image)
|
||||||
for p, a := range r.assets {
|
for p, a := range r.assets {
|
||||||
if a.config == nil {
|
if a.config == nil {
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ func (p *Printer) Print(raw bool, out io.Writer) error {
|
|||||||
Manifests []ocispecs.Descriptor `json:"manifests"`
|
Manifests []ocispecs.Descriptor `json:"manifests"`
|
||||||
Annotations map[string]string `json:"annotations,omitempty"`
|
Annotations map[string]string `json:"annotations,omitempty"`
|
||||||
}{
|
}{
|
||||||
SchemaVersion: p.index.Versioned.SchemaVersion,
|
SchemaVersion: p.index.SchemaVersion,
|
||||||
MediaType: p.index.MediaType,
|
MediaType: p.index.MediaType,
|
||||||
Digest: p.manifest.Digest,
|
Digest: p.manifest.Digest,
|
||||||
Size: p.manifest.Size,
|
Size: p.manifest.Size,
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/containerd/platforms"
|
"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 {
|
if len(platformsStr) == 0 {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
out := make([]specs.Platform, 0, len(platformsStr))
|
out := make([]ocispecs.Platform, 0, len(platformsStr))
|
||||||
for _, s := range platformsStr {
|
for _, s := range platformsStr {
|
||||||
parts := strings.Split(s, ",")
|
parts := strings.Split(s, ",")
|
||||||
if len(parts) > 1 {
|
if len(parts) > 1 {
|
||||||
@@ -31,16 +31,16 @@ func Parse(platformsStr []string) ([]specs.Platform, error) {
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func parse(in string) (specs.Platform, error) {
|
func parse(in string) (ocispecs.Platform, error) {
|
||||||
if strings.EqualFold(in, "local") {
|
if strings.EqualFold(in, "local") {
|
||||||
return platforms.DefaultSpec(), nil
|
return platforms.DefaultSpec(), nil
|
||||||
}
|
}
|
||||||
return platforms.Parse(in)
|
return platforms.Parse(in)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Dedupe(in []specs.Platform) []specs.Platform {
|
func Dedupe(in []ocispecs.Platform) []ocispecs.Platform {
|
||||||
m := map[string]struct{}{}
|
m := map[string]struct{}{}
|
||||||
out := make([]specs.Platform, 0, len(in))
|
out := make([]ocispecs.Platform, 0, len(in))
|
||||||
for _, p := range in {
|
for _, p := range in {
|
||||||
p := platforms.Normalize(p)
|
p := platforms.Normalize(p)
|
||||||
key := platforms.Format(p)
|
key := platforms.Format(p)
|
||||||
@@ -53,7 +53,7 @@ func Dedupe(in []specs.Platform) []specs.Platform {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func FormatInGroups(gg ...[]specs.Platform) []string {
|
func FormatInGroups(gg ...[]ocispecs.Platform) []string {
|
||||||
m := map[string]struct{}{}
|
m := map[string]struct{}{}
|
||||||
out := make([]string, 0, len(gg))
|
out := make([]string, 0, len(gg))
|
||||||
for i, g := range gg {
|
for i, g := range gg {
|
||||||
@@ -74,7 +74,7 @@ func FormatInGroups(gg ...[]specs.Platform) []string {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
func Format(in []specs.Platform) []string {
|
func Format(in []ocispecs.Platform) []string {
|
||||||
if len(in) == 0 {
|
if len(in) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user