1
0
mirror of https://github.com/docker/cli.git synced 2026-01-06 05:41:44 +03:00

Merge pull request #6599 from vvoland/update-docker

vendor: github.com/moby/moby master
This commit is contained in:
Paweł Gronowski
2025-10-31 17:50:18 +01:00
committed by GitHub
12 changed files with 74 additions and 125 deletions

View File

@@ -3,13 +3,12 @@ package network
import (
"context"
"github.com/moby/moby/api/types/network"
"github.com/moby/moby/client"
)
type fakeClient struct {
client.Client
networkCreateFunc func(ctx context.Context, name string, options client.NetworkCreateOptions) (network.CreateResponse, error)
networkCreateFunc func(ctx context.Context, name string, options client.NetworkCreateOptions) (client.NetworkCreateResult, error)
networkConnectFunc func(ctx context.Context, networkID string, options client.NetworkConnectOptions) (client.NetworkConnectResult, error)
networkDisconnectFunc func(ctx context.Context, networkID string, options client.NetworkDisconnectOptions) (client.NetworkDisconnectResult, error)
networkRemoveFunc func(ctx context.Context, networkID string) error
@@ -18,11 +17,11 @@ type fakeClient struct {
networkInspectFunc func(ctx context.Context, networkID string, options client.NetworkInspectOptions) (client.NetworkInspectResult, error)
}
func (c *fakeClient) NetworkCreate(ctx context.Context, name string, options client.NetworkCreateOptions) (network.CreateResponse, error) {
func (c *fakeClient) NetworkCreate(ctx context.Context, name string, options client.NetworkCreateOptions) (client.NetworkCreateResult, error) {
if c.networkCreateFunc != nil {
return c.networkCreateFunc(ctx, name, options)
}
return network.CreateResponse{}, nil
return client.NetworkCreateResult{}, nil
}
func (c *fakeClient) NetworkConnect(ctx context.Context, networkID string, options client.NetworkConnectOptions) (client.NetworkConnectResult, error) {

View File

@@ -108,12 +108,6 @@ func runCreate(ctx context.Context, apiClient client.NetworkAPIClient, output io
return err
}
var configFrom *network.ConfigReference
if options.configFrom != "" {
configFrom = &network.ConfigReference{
Network: options.configFrom,
}
}
resp, err := apiClient.NetworkCreate(ctx, options.name, client.NetworkCreateOptions{
Driver: options.driver,
Options: options.driverOpts.GetAll(),
@@ -125,7 +119,7 @@ func runCreate(ctx context.Context, apiClient client.NetworkAPIClient, output io
Ingress: options.ingress,
Scope: options.scope,
ConfigOnly: options.configOnly,
ConfigFrom: configFrom,
ConfigFrom: options.configFrom,
Labels: opts.ConvertKVStringsToMap(options.labels.GetSlice()),
})
if err != nil {

View File

@@ -20,7 +20,7 @@ func TestNetworkCreateErrors(t *testing.T) {
testCases := []struct {
args []string
flags map[string]string
networkCreateFunc func(ctx context.Context, name string, options client.NetworkCreateOptions) (network.CreateResponse, error)
networkCreateFunc func(ctx context.Context, name string, options client.NetworkCreateOptions) (client.NetworkCreateResult, error)
expectedError string
}{
{
@@ -28,8 +28,8 @@ func TestNetworkCreateErrors(t *testing.T) {
},
{
args: []string{"toto"},
networkCreateFunc: func(ctx context.Context, name string, createBody client.NetworkCreateOptions) (network.CreateResponse, error) {
return network.CreateResponse{}, errors.New("error creating network")
networkCreateFunc: func(ctx context.Context, name string, createBody client.NetworkCreateOptions) (client.NetworkCreateResult, error) {
return client.NetworkCreateResult{}, errors.New("error creating network")
},
expectedError: "error creating network",
},
@@ -166,10 +166,10 @@ func TestNetworkCreateWithFlags(t *testing.T) {
},
}
cli := test.NewFakeCli(&fakeClient{
networkCreateFunc: func(ctx context.Context, name string, options client.NetworkCreateOptions) (network.CreateResponse, error) {
networkCreateFunc: func(ctx context.Context, name string, options client.NetworkCreateOptions) (client.NetworkCreateResult, error) {
assert.Check(t, is.Equal(expectedDriver, options.Driver), "not expected driver error")
assert.Check(t, is.DeepEqual(expectedOpts, options.IPAM.Config, cmpopts.EquateComparable(netip.Addr{}, netip.Prefix{})), "not expected driver error")
return network.CreateResponse{
return client.NetworkCreateResult{
ID: name,
}, nil
},
@@ -224,9 +224,9 @@ func TestNetworkCreateIPv4(t *testing.T) {
for _, tc := range tests {
t.Run(tc.doc, func(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
networkCreateFunc: func(ctx context.Context, name string, createBody client.NetworkCreateOptions) (network.CreateResponse, error) {
networkCreateFunc: func(ctx context.Context, name string, createBody client.NetworkCreateOptions) (client.NetworkCreateResult, error) {
assert.Check(t, is.DeepEqual(createBody.EnableIPv4, tc.expected))
return network.CreateResponse{ID: name}, nil
return client.NetworkCreateResult{ID: name}, nil
},
})
cmd := newCreateCommand(cli)
@@ -278,9 +278,9 @@ func TestNetworkCreateIPv6(t *testing.T) {
for _, tc := range tests {
t.Run(tc.doc, func(t *testing.T) {
cli := test.NewFakeCli(&fakeClient{
networkCreateFunc: func(ctx context.Context, name string, createBody client.NetworkCreateOptions) (network.CreateResponse, error) {
networkCreateFunc: func(ctx context.Context, name string, createBody client.NetworkCreateOptions) (client.NetworkCreateResult, error) {
assert.Check(t, is.DeepEqual(tc.expected, createBody.EnableIPv6))
return network.CreateResponse{ID: name}, nil
return client.NetworkCreateResult{ID: name}, nil
},
})
cmd := newCreateCommand(cli)

View File

@@ -28,8 +28,8 @@ require (
github.com/google/uuid v1.6.0
github.com/mattn/go-runewidth v0.0.17
github.com/moby/go-archive v0.1.0
github.com/moby/moby/api v1.52.0-beta.3.0.20251031021517-d96f50518f8d // master
github.com/moby/moby/client v0.1.0-beta.2.0.20251031021517-d96f50518f8d // master
github.com/moby/moby/api v1.52.0-beta.3.0.20251031153638-76ba3b6a4bb7 // master
github.com/moby/moby/client v0.1.0-beta.2.0.20251031153638-76ba3b6a4bb7 // master
github.com/moby/patternmatcher v0.6.0
github.com/moby/swarmkit/v2 v2.1.0
github.com/moby/sys/atomicwriter v0.1.0

View File

@@ -170,10 +170,10 @@ github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3N
github.com/moby/docker-image-spec v1.3.1/go.mod h1:eKmb5VW8vQEh/BAr2yvVNvuiJuY6UIocYsFu/DxxRpo=
github.com/moby/go-archive v0.1.0 h1:Kk/5rdW/g+H8NHdJW2gsXyZ7UnzvJNOy6VKJqueWdcQ=
github.com/moby/go-archive v0.1.0/go.mod h1:G9B+YoujNohJmrIYFBpSd54GTUB4lt9S+xVQvsJyFuo=
github.com/moby/moby/api v1.52.0-beta.3.0.20251031021517-d96f50518f8d h1:yv97052L6n+B7nwsJSms4aC8qDJcFKEuAoyNQAjJcUg=
github.com/moby/moby/api v1.52.0-beta.3.0.20251031021517-d96f50518f8d/go.mod h1:v0K/motq8oWmx+rtApG1rBTIpQ8KUONUjpf+U73gags=
github.com/moby/moby/client v0.1.0-beta.2.0.20251031021517-d96f50518f8d h1:wXNr/8nLcBwLH9RujUs3KgAxmGkpQ0AvQlTAnVaigoA=
github.com/moby/moby/client v0.1.0-beta.2.0.20251031021517-d96f50518f8d/go.mod h1:1YrJTvhL771Q4xiwwe72NSS17lgsCF67xu8fEfSd77g=
github.com/moby/moby/api v1.52.0-beta.3.0.20251031153638-76ba3b6a4bb7 h1:8zjAJN+JNF1UMPcy7MnC13B+TkpQcfMHbkLA8NuioHY=
github.com/moby/moby/api v1.52.0-beta.3.0.20251031153638-76ba3b6a4bb7/go.mod h1:v0K/motq8oWmx+rtApG1rBTIpQ8KUONUjpf+U73gags=
github.com/moby/moby/client v0.1.0-beta.2.0.20251031153638-76ba3b6a4bb7 h1:KHuqsXpsM/0PZdT+Hc+t1mrObGr1b8h9YEICaY77w14=
github.com/moby/moby/client v0.1.0-beta.2.0.20251031153638-76ba3b6a4bb7/go.mod h1:1YrJTvhL771Q4xiwwe72NSS17lgsCF67xu8fEfSd77g=
github.com/moby/patternmatcher v0.6.0 h1:GmP9lR19aU5GqSSFko+5pRqHi+Ohk1O69aFiKkVGiPk=
github.com/moby/patternmatcher v0.6.0/go.mod h1:hDPoyOpDY7OrrMDLaYoY3hf52gNCR/YOUYxkhApJIxc=
github.com/moby/swarmkit/v2 v2.1.0 h1:u+cJ5hSyF3HnzsyI+NtegYxdIPQIuibk7IbpXNxuISM=

View File

@@ -5,7 +5,6 @@ import (
"io"
"net"
"github.com/moby/moby/api/types/network"
"github.com/moby/moby/api/types/system"
)
@@ -96,7 +95,6 @@ type ImageAPIClient interface {
ImageBuild(ctx context.Context, context io.Reader, options ImageBuildOptions) (ImageBuildResult, error)
BuildCachePrune(ctx context.Context, opts BuildCachePruneOptions) (BuildCachePruneResult, error)
BuildCancel(ctx context.Context, id string, opts BuildCancelOptions) (BuildCancelResult, error)
ImageCreate(ctx context.Context, parentReference string, options ImageCreateOptions) (ImageCreateResult, error)
ImageImport(ctx context.Context, source ImageImportSource, ref string, options ImageImportOptions) (ImageImportResult, error)
ImageList(ctx context.Context, options ImageListOptions) (ImageListResult, error)
@@ -116,7 +114,7 @@ type ImageAPIClient interface {
// NetworkAPIClient defines API client methods for the networks
type NetworkAPIClient interface {
NetworkConnect(ctx context.Context, network string, options NetworkConnectOptions) (NetworkConnectResult, error)
NetworkCreate(ctx context.Context, name string, options NetworkCreateOptions) (network.CreateResponse, error)
NetworkCreate(ctx context.Context, name string, options NetworkCreateOptions) (NetworkCreateResult, error)
NetworkDisconnect(ctx context.Context, network string, options NetworkDisconnectOptions) (NetworkDisconnectResult, error)
NetworkInspect(ctx context.Context, network string, options NetworkInspectOptions) (NetworkInspectResult, error)
NetworkList(ctx context.Context, options NetworkListOptions) (NetworkListResult, error)

View File

@@ -1,50 +0,0 @@
package client
import (
"context"
"net/http"
"net/url"
cerrdefs "github.com/containerd/errdefs"
"github.com/distribution/reference"
"github.com/moby/moby/api/types/registry"
)
// ImageCreate creates a new image based on the parent options.
// It returns the JSON content in the response body.
func (cli *Client) ImageCreate(ctx context.Context, parentReference string, options ImageCreateOptions) (ImageCreateResult, error) {
ref, err := reference.ParseNormalizedNamed(parentReference)
if err != nil {
return ImageCreateResult{}, err
}
query := url.Values{}
query.Set("fromImage", ref.Name())
query.Set("tag", getAPITagFromNamedRef(ref))
if len(options.Platforms) > 0 {
if len(options.Platforms) > 1 {
// TODO(thaJeztah): update API spec and add equivalent check on the daemon. We need this still for older daemons, which would ignore it.
return ImageCreateResult{}, cerrdefs.ErrInvalidArgument.WithMessage("specifying multiple platforms is not yet supported")
}
query.Set("platform", formatPlatform(options.Platforms[0]))
}
resp, err := cli.tryImageCreate(ctx, query, staticAuth(options.RegistryAuth))
if err != nil {
return ImageCreateResult{}, err
}
return ImageCreateResult{Body: resp.Body}, nil
}
func (cli *Client) tryImageCreate(ctx context.Context, query url.Values, resolveAuth registry.RequestAuthConfig) (*http.Response, error) {
hdr := http.Header{}
if resolveAuth != nil {
registryAuth, err := resolveAuth(ctx)
if err != nil {
return nil, err
}
if registryAuth != "" {
hdr.Set(registry.AuthHeader, registryAuth)
}
}
return cli.post(ctx, "/images/create", query, nil, hdr)
}

View File

@@ -1,21 +0,0 @@
package client
import (
"io"
ocispec "github.com/opencontainers/image-spec/specs-go/v1"
)
// ImageCreateOptions holds information to create images.
type ImageCreateOptions struct {
RegistryAuth string // RegistryAuth is the base64 encoded credentials for the registry.
// Platforms specifies the platforms to platform of the image if it needs
// to be pulled from the registry. Multiple platforms can be provided
// if the daemon supports multi-platform pulls.
Platforms []ocispec.Platform
}
// ImageCreateResult holds the response body returned by the daemon for image create.
type ImageCreateResult struct {
Body io.ReadCloser
}

View File

@@ -4,11 +4,13 @@ import (
"context"
"io"
"iter"
"net/http"
"net/url"
cerrdefs "github.com/containerd/errdefs"
"github.com/distribution/reference"
"github.com/moby/moby/api/types/jsonstream"
"github.com/moby/moby/api/types/registry"
"github.com/moby/moby/client/internal"
)
@@ -75,3 +77,17 @@ func getAPITagFromNamedRef(ref reference.Named) string {
}
return ""
}
func (cli *Client) tryImageCreate(ctx context.Context, query url.Values, resolveAuth registry.RequestAuthConfig) (*http.Response, error) {
hdr := http.Header{}
if resolveAuth != nil {
registryAuth, err := resolveAuth(ctx)
if err != nil {
return nil, err
}
if registryAuth != "" {
hdr.Set(registry.AuthHeader, registryAuth)
}
}
return cli.post(ctx, "/images/create", query, nil, hdr)
}

View File

@@ -7,8 +7,31 @@ import (
"github.com/moby/moby/api/types/network"
)
// NetworkCreateOptions holds options to create a network.
type NetworkCreateOptions struct {
Driver string // Driver is the driver-name used to create the network (e.g. `bridge`, `overlay`)
Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level).
EnableIPv4 *bool // EnableIPv4 represents whether to enable IPv4.
EnableIPv6 *bool // EnableIPv6 represents whether to enable IPv6.
IPAM *network.IPAM // IPAM is the network's IP Address Management.
Internal bool // Internal represents if the network is used internal only.
Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster.
ConfigOnly bool // ConfigOnly creates a config-only network. Config-only networks are place-holder networks for network configurations to be used by other networks. ConfigOnly networks cannot be used directly to run containers or services.
ConfigFrom string // ConfigFrom specifies the source which will provide the configuration for this network. The specified network must be a config-only network; see [CreateOptions.ConfigOnly].
Options map[string]string // Options specifies the network-specific options to use for when creating the network.
Labels map[string]string // Labels holds metadata specific to the network being created.
}
// NetworkCreateResult represents the result of a network create operation.
type NetworkCreateResult struct {
ID string
Warning []string
}
// NetworkCreate creates a new network in the docker host.
func (cli *Client) NetworkCreate(ctx context.Context, name string, options NetworkCreateOptions) (network.CreateResponse, error) {
func (cli *Client) NetworkCreate(ctx context.Context, name string, options NetworkCreateOptions) (NetworkCreateResult, error) {
req := network.CreateRequest{
Name: name,
Driver: options.Driver,
@@ -20,18 +43,27 @@ func (cli *Client) NetworkCreate(ctx context.Context, name string, options Netwo
Attachable: options.Attachable,
Ingress: options.Ingress,
ConfigOnly: options.ConfigOnly,
ConfigFrom: options.ConfigFrom,
Options: options.Options,
Labels: options.Labels,
}
if options.ConfigFrom != "" {
req.ConfigFrom = &network.ConfigReference{Network: options.ConfigFrom}
}
resp, err := cli.post(ctx, "/networks/create", nil, req, nil)
defer ensureReaderClosed(resp)
if err != nil {
return network.CreateResponse{}, err
return NetworkCreateResult{}, err
}
var response network.CreateResponse
err = json.NewDecoder(resp.Body).Decode(&response)
return response, err
var warnings []string
if response.Warning != "" {
warnings = []string{response.Warning}
}
return NetworkCreateResult{ID: response.ID, Warning: warnings}, err
}

View File

@@ -1,19 +0,0 @@
package client
import "github.com/moby/moby/api/types/network"
// NetworkCreateOptions holds options to create a network.
type NetworkCreateOptions struct {
Driver string // Driver is the driver-name used to create the network (e.g. `bridge`, `overlay`)
Scope string // Scope describes the level at which the network exists (e.g. `swarm` for cluster-wide or `local` for machine level).
EnableIPv4 *bool // EnableIPv4 represents whether to enable IPv4.
EnableIPv6 *bool // EnableIPv6 represents whether to enable IPv6.
IPAM *network.IPAM // IPAM is the network's IP Address Management.
Internal bool // Internal represents if the network is used internal only.
Attachable bool // Attachable represents if the global scope is manually attachable by regular containers from workers in swarm mode.
Ingress bool // Ingress indicates the network is providing the routing-mesh for the swarm cluster.
ConfigOnly bool // ConfigOnly creates a config-only network. Config-only networks are place-holder networks for network configurations to be used by other networks. ConfigOnly networks cannot be used directly to run containers or services.
ConfigFrom *network.ConfigReference // ConfigFrom specifies the source which will provide the configuration for this network. The specified network must be a config-only network; see [CreateOptions.ConfigOnly].
Options map[string]string // Options specifies the network-specific options to use for when creating the network.
Labels map[string]string // Labels holds metadata specific to the network being created.
}

4
vendor/modules.txt vendored
View File

@@ -168,7 +168,7 @@ github.com/moby/docker-image-spec/specs-go/v1
github.com/moby/go-archive
github.com/moby/go-archive/compression
github.com/moby/go-archive/tarheader
# github.com/moby/moby/api v1.52.0-beta.3.0.20251031021517-d96f50518f8d
# github.com/moby/moby/api v1.52.0-beta.3.0.20251031153638-76ba3b6a4bb7
## explicit; go 1.23.0
github.com/moby/moby/api/pkg/authconfig
github.com/moby/moby/api/pkg/stdcopy
@@ -190,7 +190,7 @@ github.com/moby/moby/api/types/storage
github.com/moby/moby/api/types/swarm
github.com/moby/moby/api/types/system
github.com/moby/moby/api/types/volume
# github.com/moby/moby/client v0.1.0-beta.2.0.20251031021517-d96f50518f8d
# github.com/moby/moby/client v0.1.0-beta.2.0.20251031153638-76ba3b6a4bb7
## explicit; go 1.23.0
github.com/moby/moby/client
github.com/moby/moby/client/internal