Skip to content

refactor: remove the helpers duplicated across pkg/compose and the internal packages - #14424

Merged
ndeloof merged 22 commits into
docker:mainfrom
ndeloof:dedup-shared-helpers
Oct 29, 2026
Merged

ndeloof merged 22 commits into
docker:mainfrom
ndeloof:dedup-shared-helpers

Conversation

@ndeloof

@ndeloof ndeloof commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Part of #14396

What this PR does, in one sentence

Removes the copies of the same helper that the #14396 extractions and older code left in several places, one commit per case, without changing any behavior.

Context

Moving code out of pkg/compose into internal/* packages recopied a number of small helpers (progress events, container names, label filters, engine adapters, event processors that do nothing...) instead of letting pkg/compose use the extracted ones, and a few older copies were never merged. A duplication analysis, which also finds equivalent blocks written differently, listed them and the places that should share one implementation.

What the PR brings

One commit per case, behavior unchanged, tests kept with the same assertions (new helpers get a small test of their own).

Shared core, now used by pkg/compose and the internal/* packages alike:

  • progress events (internal/progress, including a Noop event processor);
  • container naming and the label=key=value filters (internal/naming);
  • how a container is folded into a service definition (internal/projectloader);
  • the engine methods and the one-off enum that internal/inspect and internal/containerops both declared, now in internal/engine with a single adapter in pkg/compose;
  • the per-service container filter and the bounded per-container fan-out (internal/concurrency).

Local clean-ups: the pull/push stream decoding, sorted map keys through slices.Sorted(maps.Keys(m)), pause/unpause, the project fallback of down/kill/stop/restart, the Desktop client get[T], the yaml replacements, the Desktop shortcuts, the limiter gating of down, create/createAndStart, the blkio throttle devices, the depends_on label codec (encoder and decoder side by side, with a round-trip test), the --y flag, the config subcommands and the OCI layer descriptors.

Where two copies differ in behavior (an edge case handled in one and not in the other), they are deliberately left alone rather than unified, so each commit stays a pure de-duplication.

The last commit enables the dupl linter so that new copies show up in review: it reports blocks of syntax that are equivalent up to a renaming of identifiers and literals, and does not detect semantic equivalents such as reordered operands, which remain a matter for review. The threshold is 80 tokens, tests and the e2e DSL are excluded, and the few remaining pairs (declarative cobra commands, mirrored event and lookup functions) carry a targeted //nolint:dupl with the reason.

Why this is the right next brick

It keeps the #14396 series from leaving two implementations of every helper behind: the extracted packages become the single source for the shared core, and the linter keeps it that way. It only touches helpers and their call sites, so it is independent of the other extractions in flight.

🤖 Generated with Claude Code

pkg/compose carried its own copy of the event constructors that internal/progress already provides. Use the shared ones and move the generic waiting, healthy, exited and skipped events there too.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
pkg/compose kept private copies of the canonical, default and project-less container name helpers that internal/naming already provides. Use the shared ones, and host the project-prefix stripping that compose.go and monitor.go each implemented.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
The label=key=value filter was rebuilt in pkg/compose, internal/inspect, internal/relay, cmd/compose and pkg/bridge. Build it once in internal/naming and use it everywhere.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
internal/projectloader and pkg/compose each rebuilt a service definition from the containers of a project with the same bootstrap and replica counting. Keep it in internal/projectloader and call it from both.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
internal/inspect and internal/containerops declared the same engine methods and one-off enum, and pkg/compose adapted them twice. Declare them in internal/engine, embed them in both Backend interfaces and keep a single adapter.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
images and volumes each looped over the project containers to keep those of the selected services, as internal/inspect already did for ps and top. Use one helper for all four.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
internal/containerops and pkg/compose both had a copy of forEachContainerConcurrent. Provide it once, generic, in internal/concurrency.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
The quiet display, pkg/compose and three test files each defined an api.EventProcessor doing nothing. Provide it once as internal/progress.Noop.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
pull and push decoded the daemon's JSON message stream with the same loop and computed the completion percentage the same way. Move both to helpers.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Several places copied the keys of a map into a slice and sorted it by hand, some through their own generic helper. Use slices.Sorted(maps.Keys(m)), keeping the sorted order of the output.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
…ambles

pause and unpause listed and filtered their containers identically, and down, kill, stop and restart each re-spelled how to fall back to the project rebuilt from the engine. Each now has a single helper.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
Ping and FeatureFlags issued the same GET and decoded the same way. Share the request, status check and decoding in get[T].

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
…ents

ReplaceExtendsFile and ReplaceEnvFile started with the same parsing and lookup of the service node. Move it to a helper.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
The four menu shortcuts that open a Docker Desktop view repeated the same background span, open and error reporting. Only the link and the error wording differ.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
The volume, network and relay link network removals of down each spelled out the same acquire/release of the shared limiter. Wrap them with a helper built on internal/concurrency.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
create and createAndStart prepared, announced and executed their plan identically, differing only by scope.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
The four throttle device lists of the blkio configuration were converted by four identical loops.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
The service depends_on was written to a container label in create.go and read back in compose.go, each side knowing the other's format only by convention. Put the encoder and decoder side by side, with a round-trip test; the label content is unchanged.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
create and up each carried the same normalization function mapping the mistaken --y spelling to --yes.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
…place

Eight config subcommands created a Compose service and loaded the project with the same four lines. Move them to a helper of configOptions.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
…one helper

DescriptorForComposeFile and DescriptorForEnvFile only differed by their media type and annotation key.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
dupl reports blocks of syntax that are the same up to a renaming of identifiers and literals, which is the kind of copy this series removed; it does not see semantic equivalents such as reordered operands, which stay a matter for review. The threshold is 80 tokens; tests and the e2e DSL are excluded, and the few remaining pairs (declarative cobra commands, mirrored event and lookup functions) carry a targeted nolint with the reason.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@ndeloof
ndeloof requested review from a team as code owners October 29, 2026 10:04

@docker-agent docker-agent left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assessment: 🟢 APPROVE

@ndeloof
ndeloof merged commit ed976f1 into docker:main Oct 29, 2026
63 of 64 checks passed
@ndeloof
ndeloof deleted the dedup-shared-helpers branch October 29, 2026 10:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants