Skip to content

Commit 96bc39b

Browse files
authored
Merge pull request #6597 from thaJeztah/use_pull_for_pull
cli/command/container: use ImagePull instead of ImageCreate
2 parents 918ec8c + 7bdb4df commit 96bc39b

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

cli/command/container/client_test.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,22 @@ func mockContainerLogsResult(content string) client.ContainerLogsResult {
3232
return out
3333
}
3434

35+
type fakeStreamResult struct {
36+
io.ReadCloser
37+
client.ImagePushResponse // same interface as [client.ImagePushResponse]
38+
}
39+
40+
func (e fakeStreamResult) Read(p []byte) (int, error) { return e.ReadCloser.Read(p) }
41+
func (e fakeStreamResult) Close() error { return e.ReadCloser.Close() }
42+
3543
type fakeClient struct {
3644
client.Client
3745
inspectFunc func(string) (client.ContainerInspectResult, error)
3846
execInspectFunc func(execID string) (client.ExecInspectResult, error)
3947
execCreateFunc func(containerID string, options client.ExecCreateOptions) (client.ExecCreateResult, error)
4048
createContainerFunc func(options client.ContainerCreateOptions) (client.ContainerCreateResult, error)
4149
containerStartFunc func(containerID string, options client.ContainerStartOptions) (client.ContainerStartResult, error)
42-
imageCreateFunc func(ctx context.Context, parentReference string, options client.ImageCreateOptions) (client.ImageCreateResult, error)
50+
imagePullFunc func(ctx context.Context, parentReference string, options client.ImagePullOptions) (client.ImagePullResponse, error)
4351
infoFunc func() (client.SystemInfoResult, error)
4452
containerStatPathFunc func(containerID, path string) (client.ContainerStatPathResult, error)
4553
containerCopyFromFunc func(containerID, srcPath string) (client.CopyFromContainerResult, error)
@@ -107,11 +115,11 @@ func (f *fakeClient) ContainerRemove(ctx context.Context, containerID string, op
107115
return client.ContainerRemoveResult{}, nil
108116
}
109117

110-
func (f *fakeClient) ImageCreate(ctx context.Context, parentReference string, options client.ImageCreateOptions) (client.ImageCreateResult, error) {
111-
if f.imageCreateFunc != nil {
112-
return f.imageCreateFunc(ctx, parentReference, options)
118+
func (f *fakeClient) ImagePull(ctx context.Context, parentReference string, options client.ImagePullOptions) (client.ImagePullResponse, error) {
119+
if f.imagePullFunc != nil {
120+
return f.imagePullFunc(ctx, parentReference, options)
113121
}
114-
return client.ImageCreateResult{}, nil
122+
return fakeStreamResult{}, nil
115123
}
116124

117125
func (f *fakeClient) Info(context.Context, client.InfoOptions) (client.SystemInfoResult, error) {

cli/command/container/create.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,22 +140,22 @@ func pullImage(ctx context.Context, dockerCli command.Cli, img string, options *
140140
// Already validated.
141141
ociPlatforms = append(ociPlatforms, platforms.MustParse(options.platform))
142142
}
143-
resp, err := dockerCli.Client().ImageCreate(ctx, img, client.ImageCreateOptions{
143+
resp, err := dockerCli.Client().ImagePull(ctx, img, client.ImagePullOptions{
144144
RegistryAuth: encodedAuth,
145145
Platforms: ociPlatforms,
146146
})
147147
if err != nil {
148148
return err
149149
}
150150
defer func() {
151-
_ = resp.Body.Close()
151+
_ = resp.Close()
152152
}()
153153

154154
out := dockerCli.Err()
155155
if options.quiet {
156156
out = streams.NewOut(io.Discard)
157157
}
158-
return jsonstream.Display(ctx, resp.Body, out)
158+
return jsonstream.Display(ctx, resp, out)
159159
}
160160

161161
type cidFile struct {

cli/command/container/create_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,9 @@ func TestCreateContainerImagePullPolicy(t *testing.T) {
124124
return client.ContainerCreateResult{ID: containerID}, nil
125125
}
126126
},
127-
imageCreateFunc: func(ctx context.Context, parentReference string, options client.ImageCreateOptions) (client.ImageCreateResult, error) {
127+
imagePullFunc: func(ctx context.Context, parentReference string, options client.ImagePullOptions) (client.ImagePullResponse, error) {
128128
defer func() { pullCounter++ }()
129-
return client.ImageCreateResult{Body: io.NopCloser(strings.NewReader(""))}, nil
129+
return fakeStreamResult{ReadCloser: io.NopCloser(strings.NewReader(""))}, nil
130130
},
131131
infoFunc: func() (client.SystemInfoResult, error) {
132132
return client.SystemInfoResult{

cli/command/container/run_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func TestRunPullTermination(t *testing.T) {
235235
containerAttachFunc: func(ctx context.Context, containerID string, options client.ContainerAttachOptions) (client.ContainerAttachResult, error) {
236236
return client.ContainerAttachResult{}, errors.New("shouldn't try to attach to a container")
237237
},
238-
imageCreateFunc: func(ctx context.Context, parentReference string, options client.ImageCreateOptions) (client.ImageCreateResult, error) {
238+
imagePullFunc: func(ctx context.Context, parentReference string, options client.ImagePullOptions) (client.ImagePullResponse, error) {
239239
server, respReader := net.Pipe()
240240
t.Cleanup(func() {
241241
_ = server.Close()
@@ -260,7 +260,7 @@ func TestRunPullTermination(t *testing.T) {
260260
}
261261
}()
262262
attachCh <- struct{}{}
263-
return client.ImageCreateResult{Body: respReader}, nil
263+
return fakeStreamResult{ReadCloser: respReader}, nil
264264
},
265265
Version: client.MaxAPIVersion,
266266
})

0 commit comments

Comments
 (0)