1
0
mirror of https://github.com/docker/cli.git synced 2026-01-13 18:22:35 +03:00

Merge pull request #6597 from thaJeztah/use_pull_for_pull

cli/command/container: use ImagePull instead of ImageCreate
This commit is contained in:
Paweł Gronowski
2025-10-31 17:29:13 +01:00
committed by GitHub
4 changed files with 20 additions and 12 deletions

View File

@@ -32,6 +32,14 @@ func mockContainerLogsResult(content string) client.ContainerLogsResult {
return out
}
type fakeStreamResult struct {
io.ReadCloser
client.ImagePushResponse // same interface as [client.ImagePushResponse]
}
func (e fakeStreamResult) Read(p []byte) (int, error) { return e.ReadCloser.Read(p) }
func (e fakeStreamResult) Close() error { return e.ReadCloser.Close() }
type fakeClient struct {
client.Client
inspectFunc func(string) (client.ContainerInspectResult, error)
@@ -39,7 +47,7 @@ type fakeClient struct {
execCreateFunc func(containerID string, options client.ExecCreateOptions) (client.ExecCreateResult, error)
createContainerFunc func(options client.ContainerCreateOptions) (client.ContainerCreateResult, error)
containerStartFunc func(containerID string, options client.ContainerStartOptions) (client.ContainerStartResult, error)
imageCreateFunc func(ctx context.Context, parentReference string, options client.ImageCreateOptions) (client.ImageCreateResult, error)
imagePullFunc func(ctx context.Context, parentReference string, options client.ImagePullOptions) (client.ImagePullResponse, error)
infoFunc func() (client.SystemInfoResult, error)
containerStatPathFunc func(containerID, path string) (client.ContainerStatPathResult, error)
containerCopyFromFunc func(containerID, srcPath string) (client.CopyFromContainerResult, error)
@@ -107,11 +115,11 @@ func (f *fakeClient) ContainerRemove(ctx context.Context, containerID string, op
return client.ContainerRemoveResult{}, nil
}
func (f *fakeClient) ImageCreate(ctx context.Context, parentReference string, options client.ImageCreateOptions) (client.ImageCreateResult, error) {
if f.imageCreateFunc != nil {
return f.imageCreateFunc(ctx, parentReference, options)
func (f *fakeClient) ImagePull(ctx context.Context, parentReference string, options client.ImagePullOptions) (client.ImagePullResponse, error) {
if f.imagePullFunc != nil {
return f.imagePullFunc(ctx, parentReference, options)
}
return client.ImageCreateResult{}, nil
return fakeStreamResult{}, nil
}
func (f *fakeClient) Info(context.Context, client.InfoOptions) (client.SystemInfoResult, error) {

View File

@@ -140,7 +140,7 @@ func pullImage(ctx context.Context, dockerCli command.Cli, img string, options *
// Already validated.
ociPlatforms = append(ociPlatforms, platforms.MustParse(options.platform))
}
resp, err := dockerCli.Client().ImageCreate(ctx, img, client.ImageCreateOptions{
resp, err := dockerCli.Client().ImagePull(ctx, img, client.ImagePullOptions{
RegistryAuth: encodedAuth,
Platforms: ociPlatforms,
})
@@ -148,14 +148,14 @@ func pullImage(ctx context.Context, dockerCli command.Cli, img string, options *
return err
}
defer func() {
_ = resp.Body.Close()
_ = resp.Close()
}()
out := dockerCli.Err()
if options.quiet {
out = streams.NewOut(io.Discard)
}
return jsonstream.Display(ctx, resp.Body, out)
return jsonstream.Display(ctx, resp, out)
}
type cidFile struct {

View File

@@ -124,9 +124,9 @@ func TestCreateContainerImagePullPolicy(t *testing.T) {
return client.ContainerCreateResult{ID: containerID}, nil
}
},
imageCreateFunc: func(ctx context.Context, parentReference string, options client.ImageCreateOptions) (client.ImageCreateResult, error) {
imagePullFunc: func(ctx context.Context, parentReference string, options client.ImagePullOptions) (client.ImagePullResponse, error) {
defer func() { pullCounter++ }()
return client.ImageCreateResult{Body: io.NopCloser(strings.NewReader(""))}, nil
return fakeStreamResult{ReadCloser: io.NopCloser(strings.NewReader(""))}, nil
},
infoFunc: func() (client.SystemInfoResult, error) {
return client.SystemInfoResult{

View File

@@ -235,7 +235,7 @@ func TestRunPullTermination(t *testing.T) {
containerAttachFunc: func(ctx context.Context, containerID string, options client.ContainerAttachOptions) (client.ContainerAttachResult, error) {
return client.ContainerAttachResult{}, errors.New("shouldn't try to attach to a container")
},
imageCreateFunc: func(ctx context.Context, parentReference string, options client.ImageCreateOptions) (client.ImageCreateResult, error) {
imagePullFunc: func(ctx context.Context, parentReference string, options client.ImagePullOptions) (client.ImagePullResponse, error) {
server, respReader := net.Pipe()
t.Cleanup(func() {
_ = server.Close()
@@ -260,7 +260,7 @@ func TestRunPullTermination(t *testing.T) {
}
}()
attachCh <- struct{}{}
return client.ImageCreateResult{Body: respReader}, nil
return fakeStreamResult{ReadCloser: respReader}, nil
},
Version: client.MaxAPIVersion,
})