Skip to content

refactor(compose): move images and image pruning to internal/images - #14406

Merged
glours merged 2 commits into
docker:mainfrom
ndeloof:internal-images
Nov 4, 2026
Merged

glours merged 2 commits into
docker:mainfrom
ndeloof:internal-images

Conversation

@ndeloof

@ndeloof ndeloof commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

What this PR does, in one sentence

Moves the images command, the identity of a local image and the removal of project images (down --rmi, watch --prune) out of pkg/compose into a new internal/images package, with no change in behavior.

Context

pkg/compose is one flat package where every operation is a method of the same composeService, so nothing but convention keeps a read-only command like images from reaching the lifecycle code. #14396 splits it into focused internal/ packages, one reviewable move at a time; #14331, #14333 and #14397 settled the pattern.

What the PR brings

  • internal/images holds the code of images.go and image_pruner.go. It declares what it needs from the engine as a four-method Backend (the API client, the concurrency bound, the negotiated API version, and the classification of a removal error shared with the removal of the other resources) and cannot import pkg/compose.
  • composeService implements Backend and keeps one-line forwarders under the names the rest of the package already calls, so build, pull, provider_images, down and watch are not touched. ImagePruner, ImagePruneOptions and NewImagePruner stay exported as aliases, so the SDK surface does not change.
  • Behavior is unchanged. The moved tests keep their assertions; only the setup changes, from a whole composeService to a Service over a small fake Backend (TestImages, TestImagesMissingImageRecord, TestMatchLocalManifest, TestMatchLocalManifestWithoutImageData, TestInspectLocalImages*, TestInspectLocalContent, TestCanonicalBuiltDigest, and the four pruner tests). TestPlatformPinnedDigest and TestServiceImageDigest stay in pkg/compose: serviceImageDigest depends on the pinnedImageDigest type of build.go, so it stays there too. The e2e scenarios touching images and down --rmi pass as well.
  • What is deliberately not moved: pull, push and provider_images, which are touched by open PRs. The digest helpers they and build use (localContentDigest, inspectLocalContent, canonicalBuiltDigest, ...) are already in the new package, and pkg/compose forwards to them until those files move.
  • The shared helpers come from the kernel, not from copies of their own: internal/concurrency for the bounded errgroups, internal/naming for the project filter, the service selection and the canonical container name. The only things still local to the package are the two Engine API version constants (1.48 and 1.49), which pkg/compose also keeps privately.

Why this is the right next brick

It is the part of the "Images" item of #14396 that no open PR touches. pull, push and provider_images can join the same package afterwards, and what they share with it (the image identity helpers) is already there.

Part of #14396

🤖 Generated with Claude Code

@ndeloof
ndeloof requested review from a team as code owners October 28, 2026 06:59

@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 28, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 85.22013% with 47 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
internal/images/images.go 84.79% 13 Missing and 13 partials ⚠️
internal/images/prune.go 82.35% 11 Missing and 10 partials ⚠️

📢 Thoughts on this report? Let us know!

@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

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

No blocker; see inline for the one gap the move opens. Nits, no inline:

  • internal/images/images.go:57-60 redeclares APIClient / MaxConcurrency, which internal/engine.Backend already states (be24566). Embedding it would force the fake in images_test.go to implement Containers / SpecifiedContainer, so a narrow Backend is defensible (as relay / projectloader) — say so in its doc comment rather than leaving it to look like an oversight.
  • apiVersion148 / apiVersion149 exist in both internal/images/images.go:49,52 and pkg/compose/api_versions.go:39,50 (the latter still used by create.go). A cross-reference in the two comments avoids drift.
  • Comments in internal/ naming symbols that only exist in pkg/compose: prune.go:76 (isOrphaned), prune.go:163,167,175,189 (removeResource, removeDanglingImagesOp, removeTaggedImagesOp), prune_test.go:38,79. Name down instead.
  • pkg/compose/provider_images.go:133 still points to images.go:279-291, which now lives in internal/images.
  • internal/images/images.go:231: Summarize is now exported without a doc comment.
  • internal/images/prune_test.go:132-133 still say ImagePruner / ImagePruneOptions; the types are Pruner / PruneOptions here.

Comment thread pkg/compose/images_test.go Resolved
Move the images command, the identity of a local image and the removal of
project images out of pkg/compose into internal/images, behind a small
Backend interface. composeService keeps one-line forwarders so its callers
(build, pull, down, watch) don't change, and ImagePruner, ImagePruneOptions
and NewImagePruner stay exported as aliases.

No behavior change.

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

Add TestImagesBackendWiring: the images tests now run against their own fake
backend, so nothing checked that the adapter follows the service's concurrency
bound and the negotiated API version.

Comments only otherwise: say why Backend is narrow rather than embedding
engine.Backend, cross-reference the API version constants declared in both
packages, name down instead of the pkg/compose symbols, point provider_images
to LocalContentDigest, document Summarize, and use the Pruner and PruneOptions
names.

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

ndeloof commented Nov 4, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. Addressed in 578ec1c, keeping the PR a move: the wiring test, and the comment-only nits — Backend now says why it is narrow instead of embedding engine.Backend, the apiVersion148/apiVersion149 comments cross-reference each other, the comments of prune.go / prune_test.go name down instead of pkg/compose symbols (and Pruner / PruneOptions), provider_images.go points to LocalContentDigest, and Summarize has a doc comment. Not changed: the duplication of the API version constants, which would need create.go to import them from internal/images — out of scope for a move.

@ndeloof
ndeloof requested a review from docker-agent November 4, 2026 08:19

@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

Clean refactor — no behavioral regressions found. The Backend interface is correctly wired through imagesBackend to the existing composeService fields, the type aliases preserve the public SDK surface, and all moved tests pass through the new Service/Pruner layer correctly.

Lower-confidence findings (not posted inline)

  • [low] internal/images/images_test.go — anyCancellableContext() uses context.Background() instead of t.Context() in new test code. A //nolint:forbidigo suppression is in place (the context is used only for a gomock type matcher, not for real test execution), but this deviates from the project convention in AGENTS.md. Consider context.WithCancel(t.Context()) to stay consistent and ensure automatic cancel-on-cleanup.

  • [low] pkg/compose/api_versions.go:33 / internal/images/images.go — apiVersion148 and apiVersion149 are now defined in both packages, enforced in sync only by a comment. This is a maintenance hazard introduced by the split: a future addition to the images package's version gates may not be mirrored in pkg/compose (or vice versa). Consider centralising the two constants in a shared internal package (e.g., internal/api) once the remaining files move.

@glours
glours merged commit 514aad0 into docker:main Nov 4, 2026
63 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