fix(config): warn when service selection is silently ignored - #13950
Conversation
`docker compose config --no-interpolate <service>` and `docker compose config --variables <service>` load the raw model without applying service filtering, so the full model is rendered regardless of the services passed as arguments. Filtering will not be supported on these paths, so emit a warning to make sure users are no longer misled by silently ignored arguments. Fixes docker#13614 Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
docker-agent
left a comment
There was a problem hiding this comment.
Assessment: 🟢 APPROVE
The change is small, correct, and well-tested. The two new logrus.Warn guards in runConfigNoInterpolate and runVariables accurately surface the silent-ignore behaviour described in the PR, and the accompanying E2E subtests validate both the warning text (stderr) and the expected output (stdout). No logic errors, resource leaks, missing error handling, or correctness issues were found in the added code.
There was a problem hiding this comment.
Pull request overview
Adds user-facing warnings to docker compose config when [SERVICE...] arguments are provided but are not applied for --no-interpolate and --variables, preventing silent misinterpretation of output (Fixes #13614).
Changes:
- Emit warnings when service selection is provided for
config --no-interpolateandconfig --variables, clarifying that the full model is rendered. - Add E2E coverage asserting the warning appears when a service name is passed with
--no-interpolate/--variables.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| cmd/compose/config.go | Adds warning logs for ignored service selectors in --no-interpolate and --variables code paths. |
| pkg/e2e/config_test.go | Adds E2E tests expecting a warning on stderr when service selection is passed with --no-interpolate / --variables. |
| func runConfigNoInterpolate(ctx context.Context, dockerCli command.Cli, opts configOptions, services []string) ([]byte, error) { | ||
| if len(services) > 0 { | ||
| logrus.Warn("service filtering is not applied when --no-interpolate is set, the full model will be rendered") | ||
| } | ||
| // we can't use ToProject, so the model we render here is only partially resolved | ||
| model, err := opts.ToModel(ctx, dockerCli, services) | ||
| if err != nil { |
| t.Run("--no-interpolate with service selection", func(t *testing.T) { | ||
| res := c.RunDockerComposeCmd(t, "-f", "./fixtures/config/compose.yaml", "--project-name", projectName, "config", "--no-interpolate", "test") | ||
| res.Assert(t, icmd.Expected{ | ||
| Err: "service filtering is not applied when --no-interpolate is set", | ||
| Out: `- ${PORT:-8080}:80`, | ||
| }) | ||
| }) |
| t.Run("--variables with service selection", func(t *testing.T) { | ||
| res := c.RunDockerComposeCmd(t, "-f", "./fixtures/config/compose.yaml", "--project-name", projectName, "config", "--variables", "test") | ||
| res.Assert(t, icmd.Expected{ | ||
| Err: "service filtering is not applied when --variables is set", | ||
| Out: `PORT`, | ||
| }) | ||
| }) |
| func runVariables(ctx context.Context, dockerCli command.Cli, opts configOptions, services []string) error { | ||
| if len(services) > 0 { | ||
| logrus.Warn("service filtering is not applied when --variables is set, variables from the full model will be rendered") | ||
| } | ||
| opts.noInterpolate = true | ||
| model, err := opts.ToModel(ctx, dockerCli, services, cli.WithoutEnvironmentResolution, cli.WithLoadOptions(loader.WithSkipValidation)) |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
What I did
docker compose config --no-interpolate <service>anddocker compose config --variables <service>load the raw model without applying service filtering, so the full model is rendered regardless of the services passed as arguments. Filtering will not be supported on these paths, so emit a warning to make sure users are no longer misled by silently ignored arguments.Related issue
Fixes #13614
(not mandatory) A picture of a cute animal, if possible in relation to what you did