Skip to content

refactor: give each component only the engine families it uses - #14534

Open
ndeloof wants to merge 1 commit into
docker:mainfrom
ndeloof:engine-interface
Open

ndeloof wants to merge 1 commit into
docker:mainfrom
ndeloof:engine-interface

Conversation

@ndeloof

@ndeloof ndeloof commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does, in one sentence

It gives each component extracted from pkg/compose only the part of the Docker Engine API it uses, instead of the whole moby client.

Context

Every component reaches the daemon through the complete moby APIClient: several hundred methods, of which each component calls a handful. Nothing in its Backend says which, so a component that only copies files into containers could as well manage networks or swarm. The classic image build even reached the daemon through the Docker CLI rather than through its backend.

What the PR brings

  • The Backend of each component (build, images, relay, containerops, logstream, devwatch, inspect, projectloader, publish, provider) asks for the client interfaces moby already defines per resource (ContainerAPI(), NetworkAPI(), ImageAPI(), ImageBuildAPI(), ExecAPI(), VolumeAPI(), SystemAPI(), DistributionAPI()), and only for those it calls: containerops works on containers alone, registry only resolves digests. The helpers they call (registry, desktop, log stream monitor) take the matching family.
  • composeService implements every accessor with its engine, and the classic build now goes through its backend like the others.
  • composeService gets an optional engine field, used instead of the Docker CLI's client when set. By default the engine is still the CLI's client, resolved on first use as before: that client initializes lazily, so a command that never reaches the engine (compose config) still doesn't open a connection. WithDryRun refuses a service holding an injected engine, since the dry-run client only wraps the CLI's one, and Close releases the engine handed to the service while the CLI's client stays with the CLI.

Guardrails: no behavior change, no change to the exported signatures of pkg/compose. What stays on the Docker CLI is what really is bound to it: terminal streams, config file, buildx and model plugins, and attach/exec.

Why this is the right first brick

A component's Backend now states exactly what it needs from the engine, which is what makes it possible to run it against something else than a CLI-backed client, and to separate the remaining Docker CLI dependencies (streams, credentials, plugins) one at a time.

🤖 Generated with Claude Code

@ndeloof
ndeloof requested review from a team as code owners November 19, 2026 13:46

@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: 🔴 CRITICAL

This PR correctly introduces engine.API as a narrowed interface and plumbs it throughout the codebase. The mechanical refactoring is consistent. Two correctness issues are introduced by the new s.engine priority in apiClient().

Lower-confidence findings (not posted inline)

  • [medium] pkg/compose/compose.go:279 — Close() may not close s.dockerCli.Client() connection when s.engine is set (confidence: weak 52/100)

Comment thread pkg/compose/compose.go Resolved
Comment thread pkg/compose/run.go Resolved

@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: 🟡 NEEDS ATTENTION

Comment thread pkg/compose/compose.go Resolved
Comment thread pkg/compose/run.go Resolved
Comment thread pkg/compose/compose.go Resolved
Comment thread internal/engine/api.go Resolved
@codecov

codecov Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

@ndeloof
ndeloof marked this pull request as draft November 19, 2026 14:28
@ndeloof
ndeloof requested a review from docker-agent November 19, 2026 15:07

@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 requested a review from docker-agent November 19, 2026 16:38

@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

Incremental review — this review covers only the commits pushed since 155ec8f959c0e52062b98543dd1c83ca5918b9d9.

The incremental diff refines the engine-interface refactor by giving each sub-package only the narrower engine family it actually calls (ContainerAPI(), ImageAPI(), NetworkAPI(), etc.) rather than the full engine.API. The changes are mechanically consistent: every method call site is covered by the new narrower interface type, the WithDryRun-with-injected-engine guard introduced in the previous round is intact, and the NewMonitor signature split into separate ContainerAPIClient / SystemAPIClient fields is reflected at all call sites. No bugs were introduced by the incremental commits.

The packages extracted from pkg/compose (build, images, relay, containerops,
logstream, devwatch, inspect, projectloader, publish, provider) each received
the whole moby client through a single APIClient accessor, and the classic
image build reached the daemon through the Docker CLI.

Their Backend interfaces now ask for the client interfaces moby defines per
resource (ContainerAPI, NetworkAPI, ImageAPI, ImageBuildAPI, ExecAPI,
VolumeAPI, SystemAPI, DistributionAPI), and only for those the component
calls: containerops works on containers alone, registry only resolves
digests, and so on. The helpers they call (registry, desktop, the log stream
monitor) take the matching family. composeService implements every accessor
with its engine.

composeService gets an optional engine field, used instead of the client of
the Docker CLI when set. The CLI client still backs it by default, resolved on
first use as before, since it initializes lazily. WithDryRun refuses a service
holding an engine, as the dry-run client only wraps the CLI's one. Close
releases the engine handed to the service, while the CLI's client stays with
the CLI.

No behavior change.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@ndeloof ndeloof changed the title refactor: define the engine API Compose needs as an interface refactor: give each component only the engine families it uses Nov 19, 2026
@ndeloof
ndeloof requested a review from docker-agent November 19, 2026 16:53
@ndeloof
ndeloof marked this pull request as ready for review November 19, 2026 16:55

@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

@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

This branch has not been deployed

No deployments
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