Skip to content

refactor(api): split Compose into focused interfaces - #14322

Merged
glours merged 2 commits into
docker:mainfrom
ndeloof:refactor/split-compose-api
Oct 12, 2026
Merged

glours merged 2 commits into
docker:mainfrom
ndeloof:refactor/split-compose-api

Conversation

@ndeloof

@ndeloof ndeloof commented Oct 10, 2026

Copy link
Copy Markdown
Contributor

What this PR does, in one sentence

Splits the 30-odd-method api.Compose interface into six small interfaces by responsibility and rebuilds Compose by embedding them, without changing its method set.

Context

api.Compose is a god interface: every command added to Compose touches it, its generated mock and the docs, and every consumer (the cmd/compose commands, SDK users) depends on the whole surface even when it calls one or two methods. Tests that need a backend end up with the full mock, and nothing in a function signature tells the reader what it actually needs from the backend.

What the PR brings

Compose is now Lifecycle + Inspector + ImageManager + Runner + Watcher + ProjectLoader:

  • Lifecycle: Create, Start, Restart, Stop, Up, Down, Kill, Pause, UnPause, Scale, Remove, Wait
  • Inspector (read-only): Ps, List, Top, Ports, Images, Volumes, Events, Logs, Viz
  • ImageManager: Build, Push, Pull, Publish
  • Runner: RunOneOffContainer, Exec, Attach, Copy, Export, Commit
  • Watcher: Watch
  • ProjectLoader: LoadProject, Generate

The guardrails: the method set of Compose is strictly identical, with every doc comment kept, so SDK users and composeService are unaffected. The mocks are regenerated with the pinned mockgen; MockCompose is unchanged and a mock per narrow interface is added. No behavior change.

As a first illustration, the two ToProject helpers in cmd/compose, which only ever call LoadProject, now take an api.ProjectLoader. No other consumer is migrated here.

Why this is the right first brick

It is purely additive and inert, so it is easy to review. It also makes the follow-up mechanical: narrow the cmd/compose dependencies one command at a time to the sub-interface they use, with correspondingly small test doubles, without ever touching the public Compose contract.

🤖 Generated with Claude Code

Compose is now composed by embedding Lifecycle, Inspector, ImageManager,
Runner, Watcher and ProjectLoader. The method set of Compose is unchanged.
ProjectOptions.ToProject and configOptions.ToProject only need to load a
project, so they now depend on api.ProjectLoader.

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

@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

@codecov

codecov Bot commented Oct 10, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0.31153% with 320 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/mocks/mock_docker_compose_api.go 0.00% 320 Missing ⚠️

📢 Thoughts on this report? Let us know!

@glours glours 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.

LGTM

@glours
glours merged commit 175cc83 into docker:main Oct 12, 2026
62 of 64 checks passed
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