Skip to content

Commit 513ee76

Browse files
Merge pull request #6593 from thaJeztah/bump_modules
vendor: github.com/moby/moby/api master, moby/client master
2 parents 03fb1df + 8767904 commit 513ee76

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+370
-205
lines changed

cli-plugins/plugin/plugin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func withPluginClientConn(name string) command.CLIOption {
139139
if err != nil {
140140
return err
141141
}
142-
apiClient, err := client.NewClientWithOpts(client.WithDialContext(helper.Dialer))
142+
apiClient, err := client.New(client.WithDialContext(helper.Dialer))
143143
if err != nil {
144144
return err
145145
}

cli/command/cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -316,7 +316,7 @@ func newAPIClientFromEndpoint(ep docker.Endpoint, configFile *configfile.ConfigF
316316
opts = append(opts, withCustomHeaders)
317317
}
318318
opts = append(opts, extraOpts...)
319-
return client.NewClientWithOpts(opts...)
319+
return client.New(opts...)
320320
}
321321

322322
func resolveDockerEndpoint(s store.Reader, contextName string) (docker.Endpoint, error) {

cli/command/cli_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func TestNewDockerCliAndOperators(t *testing.T) {
292292
func TestInitializeShouldAlwaysCreateTheContextStore(t *testing.T) {
293293
cli, err := NewDockerCli()
294294
assert.NilError(t, err)
295-
apiClient, err := client.NewClientWithOpts()
295+
apiClient, err := client.New()
296296
assert.NilError(t, err)
297297
assert.NilError(t, cli.Initialize(flags.NewClientOptions(), WithAPIClient(apiClient)))
298298
assert.Check(t, cli.ContextStore() != nil)

cli/command/container/create.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,14 @@ func pullImage(ctx context.Context, dockerCli command.Cli, img string, options *
135135
return err
136136
}
137137

138+
var ociPlatforms []ocispec.Platform
139+
if options.platform != "" {
140+
// Already validated.
141+
ociPlatforms = append(ociPlatforms, platforms.MustParse(options.platform))
142+
}
138143
resp, err := dockerCli.Client().ImageCreate(ctx, img, client.ImageCreateOptions{
139144
RegistryAuth: encodedAuth,
140-
Platform: options.platform,
145+
Platforms: ociPlatforms,
141146
})
142147
if err != nil {
143148
return err
@@ -213,6 +218,14 @@ func createContainer(ctx context.Context, dockerCli command.Cli, containerCfg *c
213218
namedRef reference.Named
214219
)
215220

221+
// TODO(thaJeztah): add a platform option-type / flag-type.
222+
if options.platform != "" {
223+
_, err = platforms.Parse(options.platform)
224+
if err != nil {
225+
return "", err
226+
}
227+
}
228+
216229
containerIDFile, err := newCIDFile(hostConfig.ContainerIDFile)
217230
if err != nil {
218231
return "", err

cli/command/container/opts.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -885,10 +885,11 @@ func parseNetworkAttachmentOpt(ep opts.NetworkAttachmentOpts) (*network.Endpoint
885885
}
886886
}
887887
if ep.MacAddress != "" {
888-
if _, err := net.ParseMAC(strings.TrimSpace(ep.MacAddress)); err != nil {
888+
ma, err := net.ParseMAC(strings.TrimSpace(ep.MacAddress))
889+
if err != nil {
889890
return nil, fmt.Errorf("%s is not a valid mac address", ep.MacAddress)
890891
}
891-
epConfig.MacAddress = ep.MacAddress
892+
epConfig.MacAddress = network.HardwareAddr(ma)
892893
}
893894
return epConfig, nil
894895
}

cli/command/container/opts_test.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"errors"
55
"fmt"
66
"io"
7+
"net"
78
"net/netip"
89
"os"
910
"runtime"
@@ -20,6 +21,14 @@ import (
2021
"gotest.tools/v3/skip"
2122
)
2223

24+
func mustParseMAC(s string) networktypes.HardwareAddr {
25+
mac, err := net.ParseMAC(s)
26+
if err != nil {
27+
panic(err)
28+
}
29+
return networktypes.HardwareAddr(mac)
30+
}
31+
2332
func TestValidateAttach(t *testing.T) {
2433
valid := []string{
2534
"stdin",
@@ -353,7 +362,7 @@ func TestParseWithMacAddress(t *testing.T) {
353362
}
354363
_, hostConfig, nwConfig := mustParse(t, validMacAddress)
355364
defaultNw := hostConfig.NetworkMode.NetworkName()
356-
if nwConfig.EndpointsConfig[defaultNw].MacAddress != "92:d0:c6:0a:29:33" {
365+
if nwConfig.EndpointsConfig[defaultNw].MacAddress.String() != "92:d0:c6:0a:29:33" {
357366
t.Fatalf("Expected the default endpoint to have the MacAddress '92:d0:c6:0a:29:33' set, got '%v'", nwConfig.EndpointsConfig[defaultNw].MacAddress)
358367
}
359368
}
@@ -650,7 +659,7 @@ func TestParseNetworkConfig(t *testing.T) {
650659
Aliases: []string{"web3"},
651660
},
652661
"net4": {
653-
MacAddress: "02:32:1c:23:00:04",
662+
MacAddress: mustParseMAC("02:32:1c:23:00:04"),
654663
IPAMConfig: &networktypes.EndpointIPAMConfig{
655664
LinkLocalIPs: []netip.Addr{netip.MustParseAddr("169.254.169.254")},
656665
},
@@ -672,7 +681,7 @@ func TestParseNetworkConfig(t *testing.T) {
672681
IPv6Address: netip.MustParseAddr("2001:db8::8822"),
673682
},
674683
Aliases: []string{"web1", "web2"},
675-
MacAddress: "02:32:1c:23:00:04",
684+
MacAddress: mustParseMAC("02:32:1c:23:00:04"),
676685
},
677686
},
678687
expectedHostCfg: container.HostConfig{NetworkMode: "net1"},
@@ -689,7 +698,7 @@ func TestParseNetworkConfig(t *testing.T) {
689698
expected: map[string]*networktypes.EndpointSettings{
690699
"net1": {
691700
Aliases: []string{"foobar"},
692-
MacAddress: "52:0f:f3:dc:50:10",
701+
MacAddress: mustParseMAC("52:0f:f3:dc:50:10"),
693702
},
694703
},
695704
expectedHostCfg: container.HostConfig{NetworkMode: "net1"},

cli/command/context/options.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ func getDockerEndpoint(contextStore store.Reader, config map[string]string) (doc
123123
return docker.Endpoint{}, fmt.Errorf("invalid docker endpoint options: %w", err)
124124
}
125125
// FIXME(thaJeztah): this creates a new client (but discards it) only to validate the options; are the validation steps above not enough?
126-
if _, err := client.NewClientWithOpts(opts...); err != nil {
126+
if _, err := client.New(opts...); err != nil {
127127
return docker.Endpoint{}, fmt.Errorf("unable to apply docker endpoint options: %w", err)
128128
}
129129
return ep, nil

cli/command/image/build.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"path/filepath"
1212
"strings"
1313

14+
"github.com/containerd/platforms"
1415
"github.com/distribution/reference"
1516
"github.com/docker/cli-docs-tool/annotation"
1617
"github.com/docker/cli/cli"
@@ -27,6 +28,7 @@ import (
2728
"github.com/moby/moby/client"
2829
"github.com/moby/moby/client/pkg/progress"
2930
"github.com/moby/moby/client/pkg/streamformatter"
31+
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
3032
"github.com/spf13/cobra"
3133
)
3234

@@ -190,6 +192,13 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions)
190192
remote string
191193
)
192194

195+
if options.platform != "" {
196+
_, err := platforms.Parse(options.platform)
197+
if err != nil {
198+
return err
199+
}
200+
}
201+
193202
contextType, err := build.DetectContextType(options.context)
194203
if err != nil {
195204
return err
@@ -399,6 +408,12 @@ func validateTag(rawRepo string) (string, error) {
399408

400409
func imageBuildOptions(dockerCli command.Cli, options buildOptions) client.ImageBuildOptions {
401410
configFile := dockerCli.ConfigFile()
411+
412+
var buildPlatforms []ocispec.Platform
413+
if options.platform != "" {
414+
// Already validated.
415+
buildPlatforms = append(buildPlatforms, platforms.MustParse(options.platform))
416+
}
402417
return client.ImageBuildOptions{
403418
Version: buildtypes.BuilderV1,
404419
Memory: options.memory.Value(),
@@ -426,6 +441,6 @@ func imageBuildOptions(dockerCli command.Cli, options buildOptions) client.Image
426441
Squash: options.squash,
427442
ExtraHosts: options.extraHosts.GetSlice(),
428443
Target: options.target,
429-
Platform: options.platform,
444+
Platforms: buildPlatforms,
430445
}
431446
}

cli/command/image/import.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ import (
55
"os"
66
"strings"
77

8+
"github.com/containerd/platforms"
89
"github.com/docker/cli/cli"
910
"github.com/docker/cli/cli/command"
1011
"github.com/docker/cli/cli/command/completion"
1112
"github.com/docker/cli/internal/jsonstream"
1213
dockeropts "github.com/docker/cli/opts"
1314
"github.com/moby/moby/client"
15+
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
1416
"github.com/spf13/cobra"
1517
)
1618

@@ -82,10 +84,20 @@ func runImport(ctx context.Context, dockerCli command.Cli, options importOptions
8284
}
8385
}
8486

87+
// TODO(thaJeztah): add a platform option-type / flag-type.
88+
var ociPlatform ocispec.Platform
89+
if options.platform != "" {
90+
var err error
91+
ociPlatform, err = platforms.Parse(options.platform)
92+
if err != nil {
93+
return err
94+
}
95+
}
96+
8597
responseBody, err := dockerCli.Client().ImageImport(ctx, source, options.reference, client.ImageImportOptions{
8698
Message: options.message,
8799
Changes: options.changes.GetSlice(),
88-
Platform: options.platform,
100+
Platform: ociPlatform,
89101
})
90102
if err != nil {
91103
return err

cli/command/image/pull.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"io"
88
"os"
99

10+
"github.com/containerd/platforms"
1011
"github.com/distribution/reference"
1112
"github.com/docker/cli/cli"
1213
"github.com/docker/cli/cli/command"
@@ -17,6 +18,7 @@ import (
1718
"github.com/moby/moby/api/pkg/authconfig"
1819
registrytypes "github.com/moby/moby/api/types/registry"
1920
"github.com/moby/moby/client"
21+
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
2022
"github.com/spf13/cobra"
2123
)
2224

@@ -78,6 +80,13 @@ func runPull(ctx context.Context, dockerCLI command.Cli, opts pullOptions) error
7880
}
7981
}
8082

83+
if opts.platform != "" {
84+
// TODO(thaJeztah): add a platform option-type / flag-type.
85+
if _, err = platforms.Parse(opts.platform); err != nil {
86+
return err
87+
}
88+
}
89+
8190
imgRefAndAuth, err := trust.GetImageReferencesAndAuth(ctx, authResolver(dockerCLI), distributionRef.String())
8291
if err != nil {
8392
return err
@@ -104,11 +113,17 @@ func imagePullPrivileged(ctx context.Context, dockerCLI command.Cli, ref referen
104113
if err != nil {
105114
return err
106115
}
116+
var ociPlatforms []ocispec.Platform
117+
if opts.platform != "" {
118+
// Already validated.
119+
ociPlatforms = append(ociPlatforms, platforms.MustParse(opts.platform))
120+
}
121+
107122
responseBody, err := dockerCLI.Client().ImagePull(ctx, reference.FamiliarString(ref), client.ImagePullOptions{
108123
RegistryAuth: encodedAuth,
109124
PrivilegeFunc: nil,
110125
All: opts.all,
111-
Platform: opts.platform,
126+
Platforms: ociPlatforms,
112127
})
113128
if err != nil {
114129
return err

0 commit comments

Comments
 (0)