diff --git a/cli/command/container/create.go b/cli/command/container/create.go index 9f73b7f0afe3..00f187c36cf2 100644 --- a/cli/command/container/create.go +++ b/cli/command/container/create.go @@ -148,7 +148,7 @@ func pullImage(ctx context.Context, dockerCli command.Cli, img string, options * if options.quiet { out = streams.NewOut(io.Discard) } - return jsonmessage.DisplayJSONMessagesToStream(responseBody, out, nil) + return jsonmessage.DisplayJSONMessagesToStream(ctx, responseBody, out, nil) } type cidFile struct { diff --git a/cli/command/container/run_test.go b/cli/command/container/run_test.go index 81b176d904c9..6c46aebd5de5 100644 --- a/cli/command/container/run_test.go +++ b/cli/command/container/run_test.go @@ -230,12 +230,7 @@ func TestRunPullTermination(t *testing.T) { createContainerFunc: func(config *container.Config, hostConfig *container.HostConfig, networkingConfig *network.NetworkingConfig, platform *specs.Platform, containerName string, ) (container.CreateResponse, error) { - select { - case <-ctx.Done(): - return container.CreateResponse{}, ctx.Err() - default: - } - return container.CreateResponse{}, fakeNotFound{} + return container.CreateResponse{}, errors.New("shouldn't try to create a container") }, containerAttachFunc: func(ctx context.Context, containerID string, options container.AttachOptions) (types.HijackedResponse, error) { return types.HijackedResponse{}, errors.New("shouldn't try to attach to a container") @@ -277,7 +272,7 @@ func TestRunPullTermination(t *testing.T) { cmd := NewRunCommand(fakeCLI) cmd.SetOut(io.Discard) cmd.SetErr(io.Discard) - cmd.SetArgs([]string{"foobar:latest"}) + cmd.SetArgs([]string{"--pull", "always", "foobar:latest"}) cmdErrC := make(chan error, 1) go func() { diff --git a/cli/command/image/build.go b/cli/command/image/build.go index 4a258646dcce..d276b90b3bbd 100644 --- a/cli/command/image/build.go +++ b/cli/command/image/build.go @@ -361,7 +361,7 @@ func runBuild(ctx context.Context, dockerCli command.Cli, options buildOptions) } } - err = jsonmessage.DisplayJSONMessagesStream(response.Body, buildBuff, dockerCli.Out().FD(), dockerCli.Out().IsTerminal(), aux) + err = jsonmessage.DisplayJSONMessagesStream(ctx, response.Body, buildBuff, dockerCli.Out().FD(), dockerCli.Out().IsTerminal(), aux) if err != nil { if jerr, ok := err.(*jsonmessage.JSONError); ok { // If no error code is set, default to 1 diff --git a/cli/command/image/import.go b/cli/command/image/import.go index f6ad73d9baa4..3b979173ea70 100644 --- a/cli/command/image/import.go +++ b/cli/command/image/import.go @@ -90,5 +90,5 @@ func runImport(ctx context.Context, dockerCli command.Cli, options importOptions } defer responseBody.Close() - return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil) + return jsonmessage.DisplayJSONMessagesToStream(ctx, responseBody, dockerCli.Out(), nil) } diff --git a/cli/command/image/load.go b/cli/command/image/load.go index 3dff2da082e6..7616a6bcfd69 100644 --- a/cli/command/image/load.go +++ b/cli/command/image/load.go @@ -89,7 +89,7 @@ func runLoad(ctx context.Context, dockerCli command.Cli, opts loadOptions) error defer response.Body.Close() if response.Body != nil && response.JSON { - return jsonmessage.DisplayJSONMessagesToStream(response.Body, dockerCli.Out(), nil) + return jsonmessage.DisplayJSONMessagesToStream(ctx, response.Body, dockerCli.Out(), nil) } _, err = io.Copy(dockerCli.Out(), response.Body) diff --git a/cli/command/image/push.go b/cli/command/image/push.go index 9ad2abd1ff87..d7d36a3f04c7 100644 --- a/cli/command/image/push.go +++ b/cli/command/image/push.go @@ -140,17 +140,17 @@ To push the complete multi-platform image, remove the --platform flag. defer responseBody.Close() if !opts.untrusted { // TODO PushTrustedReference currently doesn't respect `--quiet` - return PushTrustedReference(dockerCli, repoInfo, ref, authConfig, responseBody) + return PushTrustedReference(ctx, dockerCli, repoInfo, ref, authConfig, responseBody) } if opts.quiet { - err = jsonmessage.DisplayJSONMessagesToStream(responseBody, streams.NewOut(io.Discard), handleAux(dockerCli)) + err = jsonmessage.DisplayJSONMessagesToStream(ctx, responseBody, streams.NewOut(io.Discard), handleAux(dockerCli)) if err == nil { fmt.Fprintln(dockerCli.Out(), ref.String()) } return err } - return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), handleAux(dockerCli)) + return jsonmessage.DisplayJSONMessagesToStream(ctx, responseBody, dockerCli.Out(), handleAux(dockerCli)) } var notes []string diff --git a/cli/command/image/trust.go b/cli/command/image/trust.go index 6bb21fa556a7..c1ba94652563 100644 --- a/cli/command/image/trust.go +++ b/cli/command/image/trust.go @@ -39,13 +39,13 @@ func TrustedPush(ctx context.Context, cli command.Cli, repoInfo *registry.Reposi defer responseBody.Close() - return PushTrustedReference(cli, repoInfo, ref, authConfig, responseBody) + return PushTrustedReference(ctx, cli, repoInfo, ref, authConfig, responseBody) } // PushTrustedReference pushes a canonical reference to the trust server. // //nolint:gocyclo -func PushTrustedReference(ioStreams command.Streams, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig registrytypes.AuthConfig, in io.Reader) error { +func PushTrustedReference(ctx context.Context, ioStreams command.Streams, repoInfo *registry.RepositoryInfo, ref reference.Named, authConfig registrytypes.AuthConfig, in io.Reader) error { // If it is a trusted push we would like to find the target entry which match the // tag provided in the function and then do an AddTarget later. target := &client.Target{} @@ -84,14 +84,14 @@ func PushTrustedReference(ioStreams command.Streams, repoInfo *registry.Reposito default: // We want trust signatures to always take an explicit tag, // otherwise it will act as an untrusted push. - if err := jsonmessage.DisplayJSONMessagesToStream(in, ioStreams.Out(), nil); err != nil { + if err := jsonmessage.DisplayJSONMessagesToStream(ctx, in, ioStreams.Out(), nil); err != nil { return err } fmt.Fprintln(ioStreams.Err(), "No tag specified, skipping trust metadata push") return nil } - if err := jsonmessage.DisplayJSONMessagesToStream(in, ioStreams.Out(), handleTarget); err != nil { + if err := jsonmessage.DisplayJSONMessagesToStream(ctx, in, ioStreams.Out(), handleTarget); err != nil { return err } @@ -283,7 +283,7 @@ func imagePullPrivileged(ctx context.Context, cli command.Cli, imgRefAndAuth tru if opts.quiet { out = streams.NewOut(io.Discard) } - return jsonmessage.DisplayJSONMessagesToStream(responseBody, out, nil) + return jsonmessage.DisplayJSONMessagesToStream(ctx, responseBody, out, nil) } // TrustedReference returns the canonical trusted reference for an image reference diff --git a/cli/command/plugin/install.go b/cli/command/plugin/install.go index 6d9ea7da5fda..6cee1cca337c 100644 --- a/cli/command/plugin/install.go +++ b/cli/command/plugin/install.go @@ -129,7 +129,7 @@ func runInstall(ctx context.Context, dockerCli command.Cli, opts pluginOptions) return err } defer responseBody.Close() - if err := jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil); err != nil { + if err := jsonmessage.DisplayJSONMessagesToStream(ctx, responseBody, dockerCli.Out(), nil); err != nil { return err } fmt.Fprintf(dockerCli.Out(), "Installed plugin %s\n", opts.remote) // todo: return proper values from the API for this result diff --git a/cli/command/plugin/push.go b/cli/command/plugin/push.go index 7f8b5dcca4e5..df99eb1ec687 100644 --- a/cli/command/plugin/push.go +++ b/cli/command/plugin/push.go @@ -66,8 +66,8 @@ func runPush(ctx context.Context, dockerCli command.Cli, opts pushOptions) error defer responseBody.Close() if !opts.untrusted { - return image.PushTrustedReference(dockerCli, repoInfo, named, authConfig, responseBody) + return image.PushTrustedReference(ctx, dockerCli, repoInfo, named, authConfig, responseBody) } - return jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil) + return jsonmessage.DisplayJSONMessagesToStream(ctx, responseBody, dockerCli.Out(), nil) } diff --git a/cli/command/plugin/upgrade.go b/cli/command/plugin/upgrade.go index d609c8d01e31..8a571fe693aa 100644 --- a/cli/command/plugin/upgrade.go +++ b/cli/command/plugin/upgrade.go @@ -86,7 +86,7 @@ func runUpgrade(ctx context.Context, dockerCli command.Cli, opts pluginOptions) return err } defer responseBody.Close() - if err := jsonmessage.DisplayJSONMessagesToStream(responseBody, dockerCli.Out(), nil); err != nil { + if err := jsonmessage.DisplayJSONMessagesToStream(ctx, responseBody, dockerCli.Out(), nil); err != nil { return err } fmt.Fprintf(dockerCli.Out(), "Upgraded plugin %s to %s\n", opts.localName, opts.remote) // todo: return proper values from the API for this result diff --git a/cli/command/service/helpers.go b/cli/command/service/helpers.go index a8ff310a57f3..daac4a725a0f 100644 --- a/cli/command/service/helpers.go +++ b/cli/command/service/helpers.go @@ -24,7 +24,7 @@ func WaitOnService(ctx context.Context, dockerCli command.Cli, serviceID string, return <-errChan } - err := jsonmessage.DisplayJSONMessagesToStream(pipeReader, dockerCli.Out(), nil) + err := jsonmessage.DisplayJSONMessagesToStream(ctx, pipeReader, dockerCli.Out(), nil) if err == nil { err = <-errChan } diff --git a/cli/command/swarm/ca.go b/cli/command/swarm/ca.go index 25c235a4503c..cd854c58ead2 100644 --- a/cli/command/swarm/ca.go +++ b/cli/command/swarm/ca.go @@ -120,7 +120,7 @@ func attach(ctx context.Context, dockerCli command.Cli, opts caOptions) error { return <-errChan } - err := jsonmessage.DisplayJSONMessagesToStream(pipeReader, dockerCli.Out(), nil) + err := jsonmessage.DisplayJSONMessagesToStream(ctx, pipeReader, dockerCli.Out(), nil) if err == nil { err = <-errChan }