Skip to content

Modern Docker Management, Designed for Everyone

fix(cli): show json stream output

Kyle Mendellace2c8da5ff7
diff --git a/cli/pkg/images/cmd.go b/cli/pkg/images/cmd.go
index 9cbefd73c..ebfe3ec8f 100644
--- a/cli/pkg/images/cmd.go
+++ b/cli/pkg/images/cmd.go
@@ -518,6 +518,8 @@ func readPullStream(cmd *cobra.Command, reader io.Reader) error {
Status string `json:"status"`
Error string `json:"error"`
ID string `json:"id"`
+ Log string `json:"log"`
+ Done bool `json:"done"`
ProgressDetail struct {
Current int64 `json:"current"`
Total int64 `json:"total"`
@@ -534,7 +536,16 @@ func readPullStream(cmd *cobra.Command, reader io.Reader) error {
loading.Finish(event.ID, pullErr)
return pullErr
}
- if jsonMode || event.Type != "" && event.Status == "" {
+ if event.Done {
+ break
+ }
+ // Servers render Docker progress as "<layer>: <status>" log lines.
+ if id, status, ok := strings.Cut(event.Log, ": "); ok && len(id) == 12 && strings.Trim(id, "0123456789abcdef") == "" {
+ event.ID, event.Status = id, status
+ } else if event.Log != "" {
+ event.Status = event.Log
+ }
+ if jsonMode || event.Status == "" {
continue
}
if event.ID != "" {
@@ -546,9 +557,9 @@ func readPullStream(cmd *cobra.Command, reader io.Reader) error {
if (!output.IsTerminal(cmd.ErrOrStderr()) || !output.IsTerminal(cmd.OutOrStdout()) || event.ID == "") && event.Status != "Downloading" && event.Status != "Extracting" {
resume := output.SuspendProgress()
if event.ID != "" {
- _, _ = fmt.Fprintf(cmd.OutOrStdout(), "%s: %s\n", event.ID, event.Status)
+ _, _ = fmt.Fprintf(cmd.OutOrStdout(), " %s: %s\n", event.ID, event.Status)
} else {
- _, _ = fmt.Fprintln(cmd.OutOrStdout(), event.Status)
+ _, _ = fmt.Fprintf(cmd.OutOrStdout(), " %s\n", event.Status)
}
resume()
}
diff --git a/cli/pkg/images/extra.go b/cli/pkg/images/extra.go
index fe43ce604..1abb075ea 100644
--- a/cli/pkg/images/extra.go
+++ b/cli/pkg/images/extra.go
@@ -568,9 +568,10 @@ func readBuildStream(cmd *cobra.Command, reader io.Reader) error {
line := scanner.Text()
trimmed := strings.TrimSpace(line)
var frame struct {
- Type string `json:"type"`
- Done bool `json:"done"`
- Error string `json:"error"`
+ Type string `json:"type"`
+ Done bool `json:"done"`
+ Error string `json:"error"`
+ Log *string `json:"log"`
}
framed := strings.HasPrefix(trimmed, "{") && json.Unmarshal([]byte(trimmed), &frame) == nil
if jsonMode && trimmed != "" {
@@ -589,6 +590,9 @@ func readBuildStream(cmd *cobra.Command, reader io.Reader) error {
if frame.Type != "" {
continue
}
+ if frame.Log != nil {
+ line = *frame.Log
+ }
}
if !jsonMode {
_, _ = fmt.Fprintln(output.Stdout(), line)
diff --git a/tests/spec/cli.spec.ts b/tests/spec/cli.spec.ts
index 5e23a1d53..08a5c877c 100644
--- a/tests/spec/cli.spec.ts
+++ b/tests/spec/cli.spec.ts
@@ -119,11 +119,7 @@ const readOnlyJsonCommands: JsonReadOnlyCommand[] = [
name: 'images counts',
args: ['--output', 'json', 'images', 'counts'],
expectation: (value) => {
- expect(value).toEqual(
- expect.objectContaining({
- data: expect.objectContaining({ totalImages: expect.any(Number) })
- })
- );
+ expect(value).toEqual(expect.objectContaining({ totalImages: expect.any(Number) }));
}
},
{