Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pull image process output from stderr to stdout #3773

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cmd/nerdctl/image/image_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ func processPullCommandFlags(cmd *cobra.Command) (types.ImagePullOptions, error)
RFlags: types.RemoteSnapshotterFlags{
SociIndexDigest: sociIndexDigest,
},
Stdout: cmd.OutOrStdout(),
Stderr: cmd.OutOrStderr(),
Stdout: cmd.OutOrStdout(),
Stderr: cmd.OutOrStderr(),
ProgressOutputToStdout: true,
}, nil
}

Expand Down
33 changes: 33 additions & 0 deletions cmd/nerdctl/image/image_pull_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,3 +236,36 @@ func TestImagePullSoci(t *testing.T) {

testCase.Run(t)
}

func TestImagePullProcessOutput(t *testing.T) {
nerdtest.Setup()

testCase := &test.Case{
SubTests: []*test.Case{
{
Description: "Pull Image - output should be in stdout",
NoParallel: true,
Cleanup: func(data test.Data, helpers test.Helpers) {
helpers.Anyhow("rmi", "-f", testutil.BusyboxImage)
},
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
return helpers.Command("pull", testutil.BusyboxImage)
},
Expected: test.Expects(0, nil, test.Contains(testutil.BusyboxImage)),
},
{
Description: "Run Container with image pull - output should be in stderr",
NoParallel: true,
Cleanup: func(data test.Data, helpers test.Helpers) {
helpers.Anyhow("rmi", "-f", testutil.BusyboxImage)
},
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
return helpers.Command("run", "--rm", testutil.BusyboxImage)
},
Expected: test.Expects(0, nil, test.DoesNotContain(testutil.BusyboxImage)),
},
},
}

testCase.Run(t)
}
7 changes: 5 additions & 2 deletions pkg/api/types/image_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,11 @@ type RemoteSnapshotterFlags struct {

// ImagePullOptions specifies options for `nerdctl (image) pull`.
type ImagePullOptions struct {
Stdout io.Writer
Stderr io.Writer
Stdout io.Writer
Stderr io.Writer
// ProgressOutputToStdout directs progress output to stdout instead of stderr
ProgressOutputToStdout bool

GOptions GlobalCommandOptions
VerifyOptions ImageVerifyOptions
// Unpack the image for the current single platform.
Expand Down
3 changes: 3 additions & 0 deletions pkg/imgutil/imgutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ func PullImage(ctx context.Context, client *containerd.Client, resolver remotes.
}
if !options.Quiet {
config.ProgressOutput = options.Stderr
if options.ProgressOutputToStdout {
config.ProgressOutput = options.Stdout
}
}

// unpack(B) if given 1 platform unless specified by `unpack`
Expand Down