Skip to content

Commit 3dbd24c

Browse files
committed
fix pull image process output from stderr to stdout
Signed-off-by: Kay Yan <[email protected]>
1 parent c41b394 commit 3dbd24c

File tree

4 files changed

+44
-4
lines changed

4 files changed

+44
-4
lines changed

cmd/nerdctl/image/image_pull.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ func processPullCommandFlags(cmd *cobra.Command) (types.ImagePullOptions, error)
129129
RFlags: types.RemoteSnapshotterFlags{
130130
SociIndexDigest: sociIndexDigest,
131131
},
132-
Stdout: cmd.OutOrStdout(),
133-
Stderr: cmd.OutOrStderr(),
132+
Stdout: cmd.OutOrStdout(),
133+
Stderr: cmd.OutOrStderr(),
134+
ProgressOutputToStdout: true,
134135
}, nil
135136
}
136137

cmd/nerdctl/image/image_pull_linux_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,3 +236,36 @@ func TestImagePullSoci(t *testing.T) {
236236

237237
testCase.Run(t)
238238
}
239+
240+
func TestImagePullProcessOutput(t *testing.T) {
241+
nerdtest.Setup()
242+
243+
testCase := &test.Case{
244+
SubTests: []*test.Case{
245+
{
246+
Description: "Pull Image - output should be in stdout",
247+
NoParallel: true,
248+
Cleanup: func(data test.Data, helpers test.Helpers) {
249+
helpers.Anyhow("rmi", "-f", testutil.BusyboxImage)
250+
},
251+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
252+
return helpers.Command("pull", testutil.BusyboxImage)
253+
},
254+
Expected: test.Expects(0, nil, test.Contains(testutil.BusyboxImage)),
255+
},
256+
{
257+
Description: "Run Container with image pull - output should be in stderr",
258+
NoParallel: true,
259+
Cleanup: func(data test.Data, helpers test.Helpers) {
260+
helpers.Anyhow("rmi", "-f", testutil.BusyboxImage)
261+
},
262+
Command: func(data test.Data, helpers test.Helpers) test.TestableCommand {
263+
return helpers.Command("run", "--rm", testutil.BusyboxImage)
264+
},
265+
Expected: test.Expects(0, nil, test.DoesNotContain(testutil.BusyboxImage)),
266+
},
267+
},
268+
}
269+
270+
testCase.Run(t)
271+
}

pkg/api/types/image_types.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,8 +189,11 @@ type RemoteSnapshotterFlags struct {
189189

190190
// ImagePullOptions specifies options for `nerdctl (image) pull`.
191191
type ImagePullOptions struct {
192-
Stdout io.Writer
193-
Stderr io.Writer
192+
Stdout io.Writer
193+
Stderr io.Writer
194+
// ProgressOutputToStdout directs progress output to stdout instead of stderr
195+
ProgressOutputToStdout bool
196+
194197
GOptions GlobalCommandOptions
195198
VerifyOptions ImageVerifyOptions
196199
// Unpack the image for the current single platform.

pkg/imgutil/imgutil.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,9 @@ func PullImage(ctx context.Context, client *containerd.Client, resolver remotes.
207207
}
208208
if !options.Quiet {
209209
config.ProgressOutput = options.Stderr
210+
if options.ProgressOutputToStdout {
211+
config.ProgressOutput = options.Stdout
212+
}
210213
}
211214

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

0 commit comments

Comments
 (0)