vendor: github.com/docker/docker 5cc3f1dab895 (master, v28.0.0-rc.2)

full diff: b570831cc3...5cc3f1dab8

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn
2025-02-14 17:23:37 +01:00
parent 591fcb273a
commit 1d3eb6f95b
90 changed files with 566 additions and 396 deletions

View File

@ -16,17 +16,17 @@ import (
type fakeClient struct {
client.Client
imageTagFunc func(string, string) error
imageSaveFunc func(images []string, options image.SaveOptions) (io.ReadCloser, error)
imageSaveFunc func(images []string, options ...client.ImageSaveOption) (io.ReadCloser, error)
imageRemoveFunc func(image string, options image.RemoveOptions) ([]image.DeleteResponse, error)
imagePushFunc func(ref string, options image.PushOptions) (io.ReadCloser, error)
infoFunc func() (system.Info, error)
imagePullFunc func(ref string, options image.PullOptions) (io.ReadCloser, error)
imagesPruneFunc func(pruneFilter filters.Args) (image.PruneReport, error)
imageLoadFunc func(input io.Reader, options image.LoadOptions) (image.LoadResponse, error)
imageLoadFunc func(input io.Reader, options ...client.ImageLoadOption) (image.LoadResponse, error)
imageListFunc func(options image.ListOptions) ([]image.Summary, error)
imageInspectFunc func(img string) (image.InspectResponse, error)
imageImportFunc func(source image.ImportSource, ref string, options image.ImportOptions) (io.ReadCloser, error)
imageHistoryFunc func(img string, options image.HistoryOptions) ([]image.HistoryResponseItem, error)
imageHistoryFunc func(img string, options ...client.ImageHistoryOption) ([]image.HistoryResponseItem, error)
imageBuildFunc func(context.Context, io.Reader, types.ImageBuildOptions) (types.ImageBuildResponse, error)
}
@ -37,9 +37,9 @@ func (cli *fakeClient) ImageTag(_ context.Context, img, ref string) error {
return nil
}
func (cli *fakeClient) ImageSave(_ context.Context, images []string, options image.SaveOptions) (io.ReadCloser, error) {
func (cli *fakeClient) ImageSave(_ context.Context, images []string, options ...client.ImageSaveOption) (io.ReadCloser, error) {
if cli.imageSaveFunc != nil {
return cli.imageSaveFunc(images, options)
return cli.imageSaveFunc(images, options...)
}
return io.NopCloser(strings.NewReader("")), nil
}
@ -81,9 +81,9 @@ func (cli *fakeClient) ImagesPrune(_ context.Context, pruneFilter filters.Args)
return image.PruneReport{}, nil
}
func (cli *fakeClient) ImageLoad(_ context.Context, input io.Reader, options image.LoadOptions) (image.LoadResponse, error) {
func (cli *fakeClient) ImageLoad(_ context.Context, input io.Reader, options ...client.ImageLoadOption) (image.LoadResponse, error) {
if cli.imageLoadFunc != nil {
return cli.imageLoadFunc(input, options)
return cli.imageLoadFunc(input, options...)
}
return image.LoadResponse{}, nil
}
@ -111,9 +111,9 @@ func (cli *fakeClient) ImageImport(_ context.Context, source image.ImportSource,
return io.NopCloser(strings.NewReader("")), nil
}
func (cli *fakeClient) ImageHistory(_ context.Context, img string, options image.HistoryOptions) ([]image.HistoryResponseItem, error) {
func (cli *fakeClient) ImageHistory(_ context.Context, img string, options ...client.ImageHistoryOption) ([]image.HistoryResponseItem, error) {
if cli.imageHistoryFunc != nil {
return cli.imageHistoryFunc(img, options)
return cli.imageHistoryFunc(img, options...)
}
return []image.HistoryResponseItem{{ID: img, Created: time.Now().Unix()}}, nil
}

View File

@ -9,7 +9,7 @@ import (
"github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/cli/command/formatter"
flagsHelper "github.com/docker/cli/cli/flags"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/client"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@ -56,16 +56,16 @@ func NewHistoryCommand(dockerCli command.Cli) *cobra.Command {
}
func runHistory(ctx context.Context, dockerCli command.Cli, opts historyOptions) error {
var options image.HistoryOptions
var options []client.ImageHistoryOption
if opts.platform != "" {
p, err := platforms.Parse(opts.platform)
if err != nil {
return errors.Wrap(err, "invalid platform")
}
options.Platform = &p
options = append(options, client.ImageHistoryWithPlatform(p))
}
history, err := dockerCli.Client().ImageHistory(ctx, opts.image, options)
history, err := dockerCli.Client().ImageHistory(ctx, opts.image, options...)
if err != nil {
return err
}

View File

@ -9,9 +9,8 @@ import (
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/image"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/docker/docker/client"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/golden"
)
@ -20,7 +19,7 @@ func TestNewHistoryCommandErrors(t *testing.T) {
name string
args []string
expectedError string
imageHistoryFunc func(img string, options image.HistoryOptions) ([]image.HistoryResponseItem, error)
imageHistoryFunc func(img string, options ...client.ImageHistoryOption) ([]image.HistoryResponseItem, error)
}{
{
name: "wrong-args",
@ -31,7 +30,7 @@ func TestNewHistoryCommandErrors(t *testing.T) {
name: "client-error",
args: []string{"image:tag"},
expectedError: "something went wrong",
imageHistoryFunc: func(img string, options image.HistoryOptions) ([]image.HistoryResponseItem, error) {
imageHistoryFunc: func(string, ...client.ImageHistoryOption) ([]image.HistoryResponseItem, error) {
return []image.HistoryResponseItem{{}}, errors.New("something went wrong")
},
},
@ -56,12 +55,12 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
testCases := []struct {
name string
args []string
imageHistoryFunc func(img string, options image.HistoryOptions) ([]image.HistoryResponseItem, error)
imageHistoryFunc func(img string, options ...client.ImageHistoryOption) ([]image.HistoryResponseItem, error)
}{
{
name: "simple",
args: []string{"image:tag"},
imageHistoryFunc: func(img string, options image.HistoryOptions) ([]image.HistoryResponseItem, error) {
imageHistoryFunc: func(string, ...client.ImageHistoryOption) ([]image.HistoryResponseItem, error) {
return []image.HistoryResponseItem{{
ID: "1234567890123456789",
Created: time.Now().Unix(),
@ -76,7 +75,7 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
{
name: "non-human",
args: []string{"--human=false", "image:tag"},
imageHistoryFunc: func(img string, options image.HistoryOptions) ([]image.HistoryResponseItem, error) {
imageHistoryFunc: func(string, ...client.ImageHistoryOption) ([]image.HistoryResponseItem, error) {
return []image.HistoryResponseItem{{
ID: "abcdef",
Created: time.Date(2017, 1, 1, 12, 0, 3, 0, time.UTC).Unix(),
@ -88,7 +87,7 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
{
name: "quiet-no-trunc",
args: []string{"--quiet", "--no-trunc", "image:tag"},
imageHistoryFunc: func(img string, options image.HistoryOptions) ([]image.HistoryResponseItem, error) {
imageHistoryFunc: func(string, ...client.ImageHistoryOption) ([]image.HistoryResponseItem, error) {
return []image.HistoryResponseItem{{
ID: "1234567890123456789",
Created: time.Now().Unix(),
@ -98,8 +97,10 @@ func TestNewHistoryCommandSuccess(t *testing.T) {
{
name: "platform",
args: []string{"--platform", "linux/amd64", "image:tag"},
imageHistoryFunc: func(img string, options image.HistoryOptions) ([]image.HistoryResponseItem, error) {
assert.Check(t, is.DeepEqual(ocispec.Platform{OS: "linux", Architecture: "amd64"}, *options.Platform))
imageHistoryFunc: func(img string, options ...client.ImageHistoryOption) ([]image.HistoryResponseItem, error) {
// FIXME(thaJeztah): need to find appropriate way to test the result of "ImageHistoryWithPlatform" being applied
assert.Check(t, len(options) > 0) // can be 1 or two depending on whether a terminal is attached :/
// assert.Check(t, is.Contains(options, client.ImageHistoryWithPlatform(ocispec.Platform{OS: "linux", Architecture: "amd64"})))
return []image.HistoryResponseItem{{
ID: "1234567890123456789",
Created: time.Now().Unix(),

View File

@ -9,7 +9,7 @@ import (
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/cli/cli/internal/jsonstream"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/client"
"github.com/moby/sys/sequential"
"github.com/pkg/errors"
"github.com/spf13/cobra"
@ -68,9 +68,9 @@ func runLoad(ctx context.Context, dockerCli command.Cli, opts loadOptions) error
return errors.Errorf("requested load from stdin, but stdin is empty")
}
var options image.LoadOptions
var options []client.ImageLoadOption
if opts.quiet || !dockerCli.Out().IsTerminal() {
options.Quiet = true
options = append(options, client.ImageLoadWithQuiet(true))
}
if opts.platform != "" {
@ -79,10 +79,10 @@ func runLoad(ctx context.Context, dockerCli command.Cli, opts loadOptions) error
return errors.Wrap(err, "invalid platform")
}
// TODO(thaJeztah): change flag-type to support multiple platforms.
options.Platforms = append(options.Platforms, p)
options = append(options, client.ImageLoadWithPlatforms(p))
}
response, err := dockerCli.Client().ImageLoad(ctx, input, options)
response, err := dockerCli.Client().ImageLoad(ctx, input, options...)
if err != nil {
return err
}

View File

@ -9,9 +9,8 @@ import (
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/image"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/docker/docker/client"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
"gotest.tools/v3/golden"
)
@ -21,7 +20,7 @@ func TestNewLoadCommandErrors(t *testing.T) {
args []string
isTerminalIn bool
expectedError string
imageLoadFunc func(input io.Reader, options image.LoadOptions) (image.LoadResponse, error)
imageLoadFunc func(input io.Reader, options ...client.ImageLoadOption) (image.LoadResponse, error)
}{
{
name: "wrong-args",
@ -38,7 +37,7 @@ func TestNewLoadCommandErrors(t *testing.T) {
name: "pull-error",
args: []string{},
expectedError: "something went wrong",
imageLoadFunc: func(input io.Reader, options image.LoadOptions) (image.LoadResponse, error) {
imageLoadFunc: func(io.Reader, ...client.ImageLoadOption) (image.LoadResponse, error) {
return image.LoadResponse{}, errors.New("something went wrong")
},
},
@ -46,7 +45,7 @@ func TestNewLoadCommandErrors(t *testing.T) {
name: "invalid platform",
args: []string{"--platform", "<invalid>"},
expectedError: `invalid platform`,
imageLoadFunc: func(input io.Reader, options image.LoadOptions) (image.LoadResponse, error) {
imageLoadFunc: func(io.Reader, ...client.ImageLoadOption) (image.LoadResponse, error) {
return image.LoadResponse{}, nil
},
},
@ -78,22 +77,21 @@ func TestNewLoadCommandSuccess(t *testing.T) {
testCases := []struct {
name string
args []string
imageLoadFunc func(input io.Reader, options image.LoadOptions) (image.LoadResponse, error)
imageLoadFunc func(input io.Reader, options ...client.ImageLoadOption) (image.LoadResponse, error)
}{
{
name: "simple",
args: []string{},
imageLoadFunc: func(input io.Reader, options image.LoadOptions) (image.LoadResponse, error) {
imageLoadFunc: func(io.Reader, ...client.ImageLoadOption) (image.LoadResponse, error) {
return image.LoadResponse{Body: io.NopCloser(strings.NewReader("Success"))}, nil
},
},
{
name: "json",
args: []string{},
imageLoadFunc: func(input io.Reader, options image.LoadOptions) (image.LoadResponse, error) {
json := "{\"ID\": \"1\"}"
imageLoadFunc: func(io.Reader, ...client.ImageLoadOption) (image.LoadResponse, error) {
return image.LoadResponse{
Body: io.NopCloser(strings.NewReader(json)),
Body: io.NopCloser(strings.NewReader(`{"ID": "1"}`)),
JSON: true,
}, nil
},
@ -101,15 +99,17 @@ func TestNewLoadCommandSuccess(t *testing.T) {
{
name: "input-file",
args: []string{"--input", "testdata/load-command-success.input.txt"},
imageLoadFunc: func(input io.Reader, options image.LoadOptions) (image.LoadResponse, error) {
imageLoadFunc: func(input io.Reader, options ...client.ImageLoadOption) (image.LoadResponse, error) {
return image.LoadResponse{Body: io.NopCloser(strings.NewReader("Success"))}, nil
},
},
{
name: "with platform",
args: []string{"--platform", "linux/amd64"},
imageLoadFunc: func(input io.Reader, options image.LoadOptions) (image.LoadResponse, error) {
assert.Check(t, is.DeepEqual([]ocispec.Platform{{OS: "linux", Architecture: "amd64"}}, options.Platforms))
imageLoadFunc: func(input io.Reader, options ...client.ImageLoadOption) (image.LoadResponse, error) {
// FIXME(thaJeztah): need to find appropriate way to test the result of "ImageHistoryWithPlatform" being applied
assert.Check(t, len(options) > 0) // can be 1 or two depending on whether a terminal is attached :/
// assert.Check(t, is.Contains(options, client.ImageHistoryWithPlatform(ocispec.Platform{OS: "linux", Architecture: "amd64"})))
return image.LoadResponse{Body: io.NopCloser(strings.NewReader("Success"))}, nil
},
},

View File

@ -8,7 +8,7 @@ import (
"github.com/docker/cli/cli"
"github.com/docker/cli/cli/command"
"github.com/docker/cli/cli/command/completion"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/client"
"github.com/pkg/errors"
"github.com/spf13/cobra"
)
@ -57,17 +57,17 @@ func RunSave(ctx context.Context, dockerCli command.Cli, opts saveOptions) error
return errors.Wrap(err, "failed to save image")
}
var options image.SaveOptions
var options []client.ImageSaveOption
if opts.platform != "" {
p, err := platforms.Parse(opts.platform)
if err != nil {
return errors.Wrap(err, "invalid platform")
}
// TODO(thaJeztah): change flag-type to support multiple platforms.
options.Platforms = append(options.Platforms, p)
options = append(options, client.ImageSaveWithPlatforms(p))
}
responseBody, err := dockerCli.Client().ImageSave(ctx, opts.images, options)
responseBody, err := dockerCli.Client().ImageSave(ctx, opts.images, options...)
if err != nil {
return err
}

View File

@ -8,8 +8,7 @@ import (
"testing"
"github.com/docker/cli/internal/test"
"github.com/docker/docker/api/types/image"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/docker/docker/client"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
@ -20,7 +19,7 @@ func TestNewSaveCommandErrors(t *testing.T) {
args []string
isTerminal bool
expectedError string
imageSaveFunc func(images []string, options image.SaveOptions) (io.ReadCloser, error)
imageSaveFunc func(images []string, options ...client.ImageSaveOption) (io.ReadCloser, error)
}{
{
name: "wrong args",
@ -38,7 +37,7 @@ func TestNewSaveCommandErrors(t *testing.T) {
args: []string{"arg1"},
isTerminal: false,
expectedError: "error saving image",
imageSaveFunc: func(images []string, options image.SaveOptions) (io.ReadCloser, error) {
imageSaveFunc: func([]string, ...client.ImageSaveOption) (io.ReadCloser, error) {
return io.NopCloser(strings.NewReader("")), errors.New("error saving image")
},
},
@ -75,13 +74,13 @@ func TestNewSaveCommandSuccess(t *testing.T) {
testCases := []struct {
args []string
isTerminal bool
imageSaveFunc func(images []string, options image.SaveOptions) (io.ReadCloser, error)
imageSaveFunc func(images []string, options ...client.ImageSaveOption) (io.ReadCloser, error)
deferredFunc func()
}{
{
args: []string{"-o", "save_tmp_file", "arg1"},
isTerminal: true,
imageSaveFunc: func(images []string, _ image.SaveOptions) (io.ReadCloser, error) {
imageSaveFunc: func(images []string, _ ...client.ImageSaveOption) (io.ReadCloser, error) {
assert.Assert(t, is.Len(images, 1))
assert.Check(t, is.Equal("arg1", images[0]))
return io.NopCloser(strings.NewReader("")), nil
@ -93,7 +92,7 @@ func TestNewSaveCommandSuccess(t *testing.T) {
{
args: []string{"arg1", "arg2"},
isTerminal: false,
imageSaveFunc: func(images []string, _ image.SaveOptions) (io.ReadCloser, error) {
imageSaveFunc: func(images []string, _ ...client.ImageSaveOption) (io.ReadCloser, error) {
assert.Assert(t, is.Len(images, 2))
assert.Check(t, is.Equal("arg1", images[0]))
assert.Check(t, is.Equal("arg2", images[1]))
@ -103,10 +102,12 @@ func TestNewSaveCommandSuccess(t *testing.T) {
{
args: []string{"--platform", "linux/amd64", "arg1"},
isTerminal: false,
imageSaveFunc: func(images []string, options image.SaveOptions) (io.ReadCloser, error) {
imageSaveFunc: func(images []string, options ...client.ImageSaveOption) (io.ReadCloser, error) {
assert.Assert(t, is.Len(images, 1))
assert.Check(t, is.Equal("arg1", images[0]))
assert.Check(t, is.DeepEqual([]ocispec.Platform{{OS: "linux", Architecture: "amd64"}}, options.Platforms))
// FIXME(thaJeztah): need to find appropriate way to test the result of "ImageHistoryWithPlatform" being applied
assert.Check(t, len(options) > 0) // can be 1 or two depending on whether a terminal is attached :/
// assert.Check(t, is.Contains(options, client.ImageHistoryWithPlatform(ocispec.Platform{OS: "linux", Architecture: "amd64"})))
return io.NopCloser(strings.NewReader("")), nil
},
},