Skip to content

fix(config): skip pure resource provider services in config --images - #14332

Merged
glours merged 1 commit into
docker:mainfrom
TDnorthgarden:fix/config-images-pure-provider
Nov 13, 2026
Merged

glours merged 1 commit into
docker:mainfrom
TDnorthgarden:fix/config-images-pure-provider

Conversation

@TDnorthgarden

Copy link
Copy Markdown
Contributor

Problem

compose config --images lists the image references of a project's services.
For a provider service declaring neither image: nor build: (a "pure
resource" provider, e.g. a managed database), it printed the
<project>-<service> name that GetImageNameOrDefault fabricates — a
reference that is never built (no build section) and never pulled (the image
phase of up and pull explicitly skips such services, see
pkg/compose/provider_images.go).

Reproducer:

name: edgecase
services:
  db:
    provider:
      type: sbx
  web:
    image: nginx
$ docker compose config --images
nginx
edgecase-db        # fabricated: never built, never pulled

Consumers feeding this output to a registry (e.g.
compose config --images | xargs docker pull) try to pull an image that
does not exist.

Fix

Mirror the pure-resource provider guard of the image phase of up and pull
in config --images: skip services with provider: set and neither
image: nor build:.

@TDnorthgarden
TDnorthgarden requested review from a team as code owners October 13, 2026 07:09
@TDnorthgarden
TDnorthgarden force-pushed the fix/config-images-pure-provider branch from 1b09409 to 0fb320f Compare October 13, 2026 07:17
ndeloof
ndeloof previously approved these changes Oct 13, 2026

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

Review summary: one change needed (config.go:728), the rest is non-blocking.

Comment thread cmd/compose/config.go Outdated
// pull (pkg/compose/provider_images.go): a provider service declaring
// neither image: nor build: has no image reference to print, and the
// default name GetImageNameOrDefault fabricates is never built or pulled
if s.Provider != nil && s.Image == "" && s.Build == nil {

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.

Blocking

This continue also skips the GetDependentImages loop below, so the pre_start hook images of a pure-resource provider service vanish from config --images. pull and up still pull them (pullHookImages and addPreStartHookPulls have no provider guard), and the provider receives the whole resolved service, hooks included, through get-service-config. config --images and pull agreed before this change; they no longer do.

Repro: db with provider: and pre_start: [{image: busybox:1.36.1}], plus web: nginx.

  • before: config --images prints edgecase-db, busybox:1.36.1, nginx
  • after: prints nginx only, while pull --dry-run still pulls busybox:1.36.1

Only the fabricated name has to go:

pure := s.Provider != nil && s.Image == "" && s.Build == nil
if !pure {
	_, _ = fmt.Fprintln(dockerCli.Out(), api.GetImageNameOrDefault(s, project.Name))
}
for _, img := range api.GetDependentImages(s, project.Name) {
	_, _ = fmt.Fprintln(dockerCli.Out(), img)
}

The current test passes with either version, so it needs a hook case (see the test comment).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for catching this — the continue did swallow the pre_start hook images. Fixed in 532e8b2: the guard now only wraps the main image line, so hook images stay listed while the fabricated name is gone.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Fixed — see commit 532e8b2.

The guard now only wraps the main image line, so the GetDependentImages loop still runs and the pre_start hook images stay listed:

for _, s := range project.Services {
    // pure resource provider: no image reference to list
    pure := s.Provider != nil && s.Image == "" && s.Build == nil
    if !pure {
        _, _ = fmt.Fprintln(dockerCli.Out(), api.GetImageNameOrDefault(s, project.Name))
    }
    for _, img := range api.GetDependentImages(s, project.Name) {
        _, _ = fmt.Fprintln(dockerCli.Out(), img)
    }
}

I verified the behaviour directly against the reviewer repro (db with provider: and pre_start: [{image: busybox:1.36.1}]}, plus web: nginx):

  • before the fix: edgecase-db, busybox:1.36.1, nginx
  • after the fix: busybox:1.36.1, nginx

The fabricated edgecase-db name is gone and the hook image is retained, so config --images agrees with pull again.

@glours could you take another look? The thread was left open on the earlier revision.

Comment thread cmd/compose/config.go Outdated
// pull (pkg/compose/provider_images.go): a provider service declaring
// neither image: nor build: has no image reference to print, and the
// default name GetImageNameOrDefault fabricates is never built or pulled
if s.Provider != nil && s.Image == "" && s.Build == nil {

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.

Non-blocking, follow-up: this is the third spelling of "pure resource provider" (provider_images.go:69-74, and the inverted form in build.go:111 and api.go:311). A small helper next to GetImageNameOrDefault in pkg/api would keep the definition in one place. Fine to do in a separate PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Will do in a separate PR, thanks.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Done — filed as a separate PR, as suggested: #14378

It adds api.IsPureResourceProvider next to GetImageNameOrDefault and uses it from ensureProviderImages.

One note on the call sites: pkg/api BuildOptions.Apply and pkg/compose build.go use the inverted condition (no provider and neither image nor build), which is a different predicate — those raise an "invalid service" error rather than identifying a pure resource provider — so they are left untouched. The helper covers the two places that actually skip a service for being a pure resource provider.

Comment thread cmd/compose/config.go Outdated
Comment on lines +724 to +727
// mirror the pure-resource provider guard of the image phase of up and
// pull (pkg/compose/provider_images.go): a provider service declaring
// neither image: nor build: has no image reference to print, and the
// default name GetImageNameOrDefault fabricates is never built or pulled

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.

Nit: "never built or pulled" is not accurate, get-service-config hands that fabricated name to the provider (plugins.go:447). One line is enough, like the guard it mirrors in provider_images.go:

// pure resource provider: no image reference to list

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Done — the comment now reads:

// pure resource provider: no image reference to list

which mirrors the guard in provider_images.go.

Comment thread cmd/compose/config_test.go Outdated
// provider service declaring neither image: nor build: has no image to
// list, and the GetImageNameOrDefault fallback would fabricate a
// "<project>-<service>" reference that is never built and never pulled.
func TestRunConfigImagesSkipsPureResourceProvider(t *testing.T) {

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.

Test:

  • Add a case with a pre_start hook image on the pure-resource provider, expecting the hook image to be listed (pins the change in config.go).
  • Add provider + image: and provider + build: cases, expecting redis and <project>-<service> respectively. They keep the guard narrow.
  • cli.EXPECT().Client() and ConfigFile() are never called; only Out() is needed (the test passes without them, and the MockAPIClient goes away too).
  • sort.Strings on a one-element slice does nothing. assert.Equal(t, buf.String(), "nginx\n") is stricter and shorter, and drops the sort import.
  • ProjectDir: dir is redundant, the compose file's directory is used already.
  • Non-blocking: type: sbx ties a core test to one specific provider. The docs use a neutral name (awesomecloud).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in 532e8b2 — the test now covers the guard's full shape as three single-service cases (pure + hook, provider + image:, provider + build:), each asserting the exact output. The never-called Client()/ConfigFile() expectations and the MockAPIClient are gone, sort and ProjectDir dropped in favor of a strict assert.Equal, and the provider type uses the neutral awesomecloud from the docs.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Done in 532e8b2. The test now covers the guard's full shape as three single-service cases, each asserting the exact output with assert.Equal:

  • pure resource provider with a pre_start hook image → busybox:1.36.1
  • provider with image: → redis
  • provider with build: → edgecase-db

The never-called Client() / ConfigFile() expectations and the MockAPIClient are gone, sort and ProjectDir are dropped in favour of a strict assert.Equal, and the provider type uses the neutral awesomecloud from the docs rather than sbx.

@codecov

codecov Bot commented Oct 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@TDnorthgarden
TDnorthgarden force-pushed the fix/config-images-pure-provider branch 2 times, most recently from 9060e1b to 532e8b2 Compare October 14, 2026 02:12
@TDnorthgarden

Copy link
Copy Markdown
Contributor Author

Hi @glours, all four points from your review are addressed in 532e8b2 — mind taking another look when you get a chance?

One clarification on the thread above: the changes in 532e8b2 (the guard rework, the comment, and the test matrix) are mine. The later replies summarizing them were posted by another account — thanks @OMD-123 for picking up the helper follow-up in #14378.

A provider service declaring neither image: nor build: has no image
reference to list, yet config --images printed the <project>-<service>
name GetImageNameOrDefault fabricates: a reference that is never built
and never pulled, while the image phase of up and pull already skips
such services. Consumers feeding `compose config --images` output to
a registry would try to pull an image that does not exist.

Mirror the pure-resource provider guard of pkg/compose/provider_images.go.

Signed-off-by: Aucoto <tdnorthgarden@gmail.com>
@TDnorthgarden
TDnorthgarden force-pushed the fix/config-images-pure-provider branch from 532e8b2 to fdc7a16 Compare November 13, 2026 02:51
@OMD-123

OMD-123 commented Nov 13, 2026

Copy link
Copy Markdown

@glours — the blocking review is against 0fb320f8, but the current head is fdc7a165, which already contains all four of your points:

  1. The continue swallowing GetDependentImages — fixed in 532e8b2. The guard now only wraps the main image line, so the GetDependentImages loop still runs:
for _, s := range project.Services {
	// pure resource provider: no image reference to list
	pure := s.Provider != nil && s.Image == "" && s.Build == nil
	if !pure {
		_, _ = fmt.Fprintln(dockerCli.Out(), api.GetImageNameOrDefault(s, project.Name))
	}
	for _, img := range api.GetDependentImages(s, project.Name) {
		_, _ = fmt.Fprintln(dockerCli.Out(), img)
	}
}
  1. The comment wording — now reads // pure resource provider: no image reference to list, mirroring the guard in provider_images.go.

  2. The test matrix — cmd/compose/config_test.go:322 TestRunConfigImagesPureResourceProvider now has three single-service cases, each asserting the exact output with assert.Equal: pure resource provider with a pre_start hook image → busybox:1.36.1; provider with image: → redis; provider with build: → edgecase-db. The never-called Client() / ConfigFile() expectations and the MockAPIClient are gone, sort and ProjectDir are dropped, and the provider type is the neutral awesomecloud from the docs.

  3. The hook case pinning the fix — the first case above is exactly the repro from your review: a pre_start hook image on the pure-resource provider is still listed.

I ran the test against the current head to confirm it passes:

=== RUN   TestRunConfigImagesPureResourceProvider
--- PASS: TestRunConfigImagesPureResourceProvider (0.00s)
    --- PASS: TestRunConfigImagesPureResourceProvider/pure_resource_provider_lists_only_its_hook_images (0.00s)
    --- PASS: TestRunConfigImagesPureResourceProvider/provider_with_an_image_lists_it (0.00s)
    --- PASS: TestRunConfigImagesPureResourceProvider/provider_with_a_build_lists_the_built_image_tag (0.00s)

@ndeloof has already approved fdc7a165. Since your CHANGES_REQUESTED is still anchored to the older commit, could you re-review the current head? If it looks good, a dismissal of the stale review would unblock the merge.

The "pure resource provider" definition now has a single home — api.IsPureResourceProvider in #14378 — so the spelling in config.go can adopt it once that lands.

@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 enabled auto-merge (rebase) November 13, 2026 14:31
@glours
glours merged commit 96a9194 into docker:main Nov 13, 2026
60 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.

4 participants