Repository navigation
fix(config): skip pure resource provider services in config --images #14332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -721,6 +721,13 @@ func runConfigImages(ctx context.Context, dockerCli command.Cli, opts configOpti | |
| } | ||
|
|
||
| for _, s := range project.Services { | ||
| // 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 | ||
| if s.Provider != nil && s.Image == "" && s.Build == nil { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Blocking This Repro:
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).
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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" ( |
||
| continue | ||
| } | ||
| _, _ = fmt.Fprintln(dockerCli.Out(), api.GetImageNameOrDefault(s, project.Name)) | ||
| for _, img := range api.GetDependentImages(s, project.Name) { | ||
| _, _ = fmt.Fprintln(dockerCli.Out(), img) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,11 +17,16 @@ | |
| package compose | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "os" | ||
| "path/filepath" | ||
| "sort" | ||
| "strings" | ||
| "testing" | ||
|
|
||
| "github.com/compose-spec/compose-go/v2/types" | ||
| "github.com/docker/cli/cli/config/configfile" | ||
| "github.com/docker/cli/cli/streams" | ||
| "github.com/moby/moby/api/types/registry" | ||
| "github.com/moby/moby/client" | ||
| ocispec "github.com/opencontainers/image-spec/specs-go/v1" | ||
|
|
@@ -307,3 +312,43 @@ func TestLockModel(t *testing.T) { | |
| }, | ||
| }) | ||
| } | ||
|
|
||
| // TestRunConfigImagesSkipsPureResourceProvider mirrors the pure-resource | ||
| // provider guard of the pull path (pkg/compose/provider_images.go): a | ||
| // 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) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Test:
|
||
| ctrl := gomock.NewController(t) | ||
| defer ctrl.Finish() | ||
|
|
||
| dir := t.TempDir() | ||
| composePath := filepath.Join(dir, "compose.yaml") | ||
| assert.NilError(t, os.WriteFile(composePath, []byte(` | ||
| name: edgecase | ||
| services: | ||
| db: | ||
| provider: | ||
| type: sbx | ||
| web: | ||
| image: nginx | ||
| `), 0o600)) | ||
|
|
||
| buf := new(bytes.Buffer) | ||
| cli := mocks.NewMockCli(ctrl) | ||
| cli.EXPECT().Out().Return(streams.NewOut(buf)).AnyTimes() | ||
| cli.EXPECT().Client().Return(mocks.NewMockAPIClient(ctrl)).AnyTimes() | ||
| cli.EXPECT().ConfigFile().Return(configfile.New("")).AnyTimes() | ||
|
|
||
| opts := configOptions{ | ||
| ProjectOptions: &ProjectOptions{ | ||
| ConfigPaths: []string{composePath}, | ||
| ProjectDir: dir, | ||
| }, | ||
| } | ||
| assert.NilError(t, runConfigImages(t.Context(), cli, opts, nil)) | ||
|
|
||
| lines := strings.Split(strings.TrimSpace(buf.String()), "\n") | ||
| sort.Strings(lines) | ||
| assert.DeepEqual(t, lines, []string{"nginx"}) | ||
| } | ||
There was a problem hiding this comment.
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-confighands that fabricated name to the provider (plugins.go:447). One line is enough, like the guard it mirrors inprovider_images.go:// pure resource provider: no image reference to list