36 Commits
Author SHA1 Message Date
Sebastiaan van Stijn 5f9299935a client/pkg/jsonmessage: add custom message printer
Add WithMessagePrinter to allow callers of DisplayStream and
DisplayMessages to customize presentation of non-auxiliary messages.

The custom printer replaces the default terminal-aware rendering, allowing
callers to handle progress output, terminal sizing, and message errors as
needed. Auxiliary messages continue to use WithAuxCallback.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-08-27 23:40:23 +02:00
Sebastiaan van Stijn aab60119ef client/pkg/jsonmessage: Display: fix godoc link
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-07-14 13:15:53 +02:00
Sebastiaan van Stijn 9aa5ac3034 client/pkg/jsonmessage: use functional options for display funcs
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-04-01 17:27:18 +02:00
Sebastiaan van Stijn 6aedc6ba32 client/pkg/jsonmessage: add DisplayStream and DisplayMessages utils
These can replace the existing DisplayJSONMessagesStream and DisplayJSONMessages
functions, not requiring the caller to perform terminal detection.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-03-31 15:31:07 +02:00
Sebastiaan van Stijn 571080854b client: go fix
Result of running `go fix -mod=readonly ./...` (twice).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-03-14 19:30:07 +01:00
Paweł Gronowski ca7b472fc5 Merge pull request #52065 from thaJeztah/client_streams_cleanup
client/pkg/streamformatter: cleanups, fixes and refactor
2026-02-27 16:19:36 +00:00
Sebastiaan van Stijn 439e2921e0 Merge pull request #52064 from thaJeztah/client_reduce_wrapping
client/pkg/progress: reduce some wrapping
2026-02-24 17:32:24 +01:00
Sebastiaan van Stijn a2edf4798d client/pkg/streamformatter: refactor
Internalize the `formatStatus` and `formatProgress` methods and consolidate
them into a single `format` method. The different implementations used
different arguments for these, so make those details internal to the
implementation.

Introduce an `emptyMessage` method, which is still used for the JSON formatter
but needs to be looked into.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-02-20 14:37:30 +01:00
Sebastiaan van Stijn 81414a6eb1 client/pkg/streamformatter: use blackbox testing
Don't test the internals, just the result.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-02-20 14:30:09 +01:00
Sebastiaan van Stijn 5f10e5fdfa client/pkg/streamformatter: add TODO for NewLines option
The "newLines" option was added in ba17f4a06a
to handle a display issue where an error during `docker build` would overwrite
a previous line due to a missing newline at the end. It was carried over in
refactorings (12b278d354) and new implementations
(572ce80230).

It's used for `docker build` (see [1], [2]), and on `docker pull` ([3]); my
suspicion is that the common denominator is that these responses use `Aux`
message for the last response.

We should look if this option is still needed, or if it could be fixed
either by the Aux message itself, or by detecting that an Aux message
will be printed.

[1]: https://github.com/moby/moby/blob/f222c1ed0532b338c9761729bd6a6d1779fa4698/daemon/server/router/build/build_routes.go#L310
[2]: https://github.com/moby/moby/blob/f222c1ed0532b338c9761729bd6a6d1779fa4698/daemon/builder/dockerfile/copy.go#L413
[3]: https://github.com/moby/moby/blob/f222c1ed0532b338c9761729bd6a6d1779fa4698/daemon/server/router/image/image_routes.go#L145

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-02-20 14:30:00 +01:00
Sebastiaan van Stijn dee810c0dc client/pkg/streamformatter: jsonProgressFormatter: remove unused code
- Inline the `formatStatus` function.
- The `formatStatus` methods were never called with a format-string, so we
  can remove it.
- Marshaling the `jsonstream.Message` should never produce an error with
  the given struct, so remove the `formatError` and return nil (similar
  to what's done elsewhere.
- Also do some minor cleanup in `jsonProgressFormatter.formatProgress`

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-02-20 13:41:57 +01:00
Sebastiaan van Stijn fe6838cf4c client/pkg/streamformatter: optimize appendNewline
This function is called repeatedly; slightly optimize it.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-02-20 13:41:57 +01:00
Sebastiaan van Stijn 71025997bc client/pkg/streamformatter: remove redundant nil check
rawProgressString already checks for nil-values;
https://github.com/moby/moby/blob/f222c1ed0532b338c9761729bd6a6d1779fa4698/client/pkg/streamformatter/streamformatter.go#L83-L86

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-02-20 13:41:57 +01:00
Sebastiaan van Stijn cf4d504c29 client/pkg/streamformatter: fix faulty TestNewJSONProgressOutput
This  test was added in 956c5b61ce, but
wasn't really testing anything (other than testing stdlib).

Ironically there was a review comment on the PR, but about the naming
of the test, and not about the test itself;

> but it isn't really testing NewJSONProgressOutput. NewJSONProgressOutput
> just returns a struct. IMHO it's testing WriteProgress.

Let's make the test test something.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-02-20 13:41:57 +01:00
Sebastiaan van Stijn e3e1167c00 client/pkg/streamformatter: remove redundant cmp-opts in test
This option was added to handle the deprecated `ProgressMessage` field,
which was removed in fdaccdb233.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-02-20 13:41:56 +01:00
Sebastiaan van Stijn 21706fb5cd client/pkg/progress: reduce some wrapping
Reduce wrapping (Updatef > Update) to make it clearer what functions
are used (or no longer used).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-02-20 13:41:24 +01:00
Sebastiaan van Stijn 8b4edd73b3 client/pkg/jsonmessage: make DisplayJSONMessages accept a iter.Seq2
The `DisplayJSONMessages` only accepted a `JSONMessagesStream`. This meant that
it would not accept the output from (for example) [client.ImagePushResponse].

This patch:

- Makes `DisplayJSONMessages` accept any `iter.Seq2[jsonstream.Message, error]`
- Makes `JSONMessagesStream` an alias instead of a concrete type (TBD if we
  actually need the type).
- Some minor cleanups in the implementation.

[client.ImagePushResponse]: https://github.com/moby/moby/blob/fa87120ae64a170fd42096de3b873b439b95016b/client/image_push.go#L20-L24

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-02-20 13:40:56 +01:00
Sebastiaan van Stijn c5a0bfd9ff client/pkg/jsonmessage: fix typo in godoc
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2026-02-19 09:54:19 +01:00
Sebastiaan van Stijn 8f3bfa3f34 client: fix missing import aliases (importas)
client/container_exec.go:8:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
        "github.com/containerd/errdefs"
        ^
    client/container_exec_test.go:9:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
        "github.com/containerd/errdefs"
        ^
    client/container_rename.go:8:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
        "github.com/containerd/errdefs"
        ^
    client/pkg/security/security_opts_test.go:8:2: import "gotest.tools/v3/assert/cmp" imported without alias but must be with alias "is" according to config (importas)
        "gotest.tools/v3/assert/cmp"
        ^
    client/volume_prune.go:9:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
        "github.com/containerd/errdefs"
        ^
    client/volume_prune_test.go:8:2: import "github.com/containerd/errdefs" imported without alias but must be with alias "cerrdefs" according to config (importas)
        "github.com/containerd/errdefs"
        ^
    client/container_exec_test.go:10:2: ST1019(related information): other import of "github.com/containerd/errdefs" (staticcheck)
        cerrdefs "github.com/containerd/errdefs"
        ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-12-18 15:27:34 +01:00
Sebastiaan van Stijn 745c483e42 client: pkg/streamformatter: un-export unused utilities
Un-export or remove utilities that have no (external) users;

- AuxFormatter (not used)
- FormatError (only used internally)
- FormatStatus (only used internally)
- NewJSONProgressOutput (used by CLI)
- NewProgressOutput (used by compose, cli for classic builder)
- NewStderrWriter (not used)
- NewStdoutWriter (not used)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-06 23:12:11 +01:00
Sebastiaan van Stijn 31f7f62d6c client/pkg/security: simplify
This utility is used to split the SecurityOptions field from the
"/info" response into a slice of security.Option. It's effectively
only used by the CLI to present the `docker info` output, but has
a use in buildx to parse the response.

We can assume the daemon returns a valid response, remove the error-
conditions and fallback for legacy daemon versions (< 1.13), and limit
it to parsing the response only.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-11-03 11:36:44 +01:00
Cory Snider bbaeb9036f client/pkg/jsonmessage: use api message def'ns
Signed-off-by: Cory Snider <csnider@mirantis.com>
2025-10-28 17:10:34 -04:00
Cory Snider 687c3d7f42 api/types/jsonstream: define Message type
The schema of a JSON-stream message is very pertinent to the api module.
Provide a canonical definition in the api module and refactor the daemon
code to use it. Drop the long-deprecated ErrorMessage field from the API
definition, but have the daemon continue to emit it for compatibility
with docker-py v7.1.0.

Co-authored-by: Cory Snider <csnider@mirantis.com>
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
2025-10-24 07:56:58 -05:00
Cory Snider ae28867804 api/pkg/progress: move to client and daemon/internal
Move the progress package up into the client as a temporary shared location for
common clients like CLI and compose.

The progress package is used by the daemon to write progress updates to
some sink, typically a streamformatter. This package is of little use to
API clients as this package does not provide any facilities to consume
the progress updates.

Co-authored-by: Cory Snider <csnider@mirantis.com>
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
2025-10-24 07:56:57 -05:00
Cory Snider 6baf274fa3 api/pkg/streamformatter: move to client and daemon/internal
Move the streamformatter package up into the client for a temporary
shared location between common clients like CLI and compose.

The streamformatter package is used by the daemon to write streams of
status and progress messages to API clients. It is completely out of
scope of the api module and not used outside the daemon. Remove the
unused rawSteamFormatter, whose purpose is to render the progress as a
TUI.

Co-authored-by: Cory Snider <csnider@mirantis.com>
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
2025-10-24 07:56:51 -05:00
Austin VazquezandClaude f40e1a7582 api: move types/versions to client/pkg and daemon/internal
This change moves the api/types/versions package out into client and daemon versions.

Co-authored-by: Claude <noreply@anthropic.com>
Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
2025-10-23 19:22:31 -05:00
Sebastiaan van Stijn c7fe7136d2 client: gofumpt
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-10-22 14:01:01 +02:00
Nicolas De Loof e6bac8983b introduce ImagePullResponse to manage JSONMessage stream decoding
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2025-10-09 15:36:22 +02:00
Austin Vazquez e2e9f36c5f api/types/system: move SecurityOpt type and DecodeSecurityOptions to client
This change moves the `system.SecurityOpt` type and `system.DecodeSecurityOptions` function to the client and adds a set of unit tests to capture current implementation. This change also create a set of daemon backend copies for usage.

Signed-off-by: Austin Vazquez <austin.vazquez@docker.com>
2025-09-03 12:49:06 -05:00
Sebastiaan van Stijn 47bdbf5a4b client/pkg/jsonmessage: remove unused fields
The JSONMessage struct contained fields that were previously used to produce the
`/events` response. However, commit 72f1881df1
introduced an events.Message type that replaced the use of JSONMessage for
that purpose, and clients no longer use the JSONMessage struct to unmarshal
those responses.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-19 17:55:01 +02:00
Sebastiaan van Stijn 195a6bbb1e client: touch-up godoc
Not perfect yet, but addressing some godoc "doc" links that needed
to be updated, and touching up some references.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-08-02 17:12:05 +02:00
Sebastiaan van Stijn f3ba0b2dc2 client/pkg/jsonmessage: remove Stream interface
It was an interface to match CLI-specific primitives and is no
longer used.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-30 23:22:12 +02:00
Sebastiaan van Stijn 19edf5c53c client/pkg/jsonmessage: remove DisplayJSONMessagesToStream
It was an adaptor around DisplayJSONMessagesStream for CLI-specific
primitives that was used in the CLI, but can be implemented by users
of this package.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-30 23:22:09 +02:00
Sebastiaan van Stijn fdaccdb233 pkg/jsonmessage: stop printing deprecated progressDetail, errorDetail
The API still returns it for backward-compatibility (but probably
shouldn't), but we should no longer print it. This removes the
use of these fields for printing, but keeps them for streamformatter
to use.

- ErrorMessage was deprecated in 3043c26419
- ProgressMessage was deprecated in 597e0e69b4

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-30 22:51:13 +02:00
Derek McGowan 0d8ca8eefe Move pkg/jsonmessage to client/pkg/jsonmessage
Signed-off-by: Derek McGowan <derek@mcg.dev>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-30 14:22:31 +02:00
Sebastiaan van Stijn ca1c5ee08f pkg/stringid: move to daemon, and provide copy in client
The stringid package is used in many places; while it's trivial
to implement a similar utility, let's just provide it as a utility
package in the client, removing the daemon-specific logic.

For integration tests, I opted to use the implementation in the
client, as those should not ideally not make assumptions about
the daemon implementation.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2025-07-25 13:39:32 +02:00