fix(config): warn when service selection is silently ignored
Some checks failed
ci / validate (lint) (push) Has been cancelled
ci / validate (validate-docs) (push) Has been cancelled
ci / validate (validate-go-mod) (push) Has been cancelled
ci / validate (validate-headers) (push) Has been cancelled
ci / binary (push) Has been cancelled
ci / bin-image-test (push) Has been cancelled
ci / test (push) Has been cancelled
ci / e2e (plugin, oldstable) (push) Has been cancelled
ci / e2e (standalone, oldstable) (push) Has been cancelled
ci / e2e (plugin, stable) (push) Has been cancelled
ci / e2e (standalone, stable) (push) Has been cancelled
merge / bin-image-prepare (push) Has been cancelled
merge / module-image (push) Has been cancelled
Scorecards supply-chain security / Scorecards analysis (push) Has been cancelled
zizmor / zizmor (push) Has been cancelled
ci / binary-finalize (push) Has been cancelled
ci / coverage (push) Has been cancelled
ci / release (push) Has been cancelled
merge / bin-image (push) Has been cancelled

`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 #13614

Signed-off-by: Guillaume Lours <glours@users.noreply.github.com>
This commit is contained in:
Guillaume Lours 2026-07-17 15:58:54 +02:00 committed by Guillaume Lours
parent 5bf5a21687
commit efb63f2e6e
2 changed files with 23 additions and 0 deletions

View file

@ -32,6 +32,7 @@ import (
"github.com/compose-spec/compose-go/v2/template"
"github.com/compose-spec/compose-go/v2/types"
"github.com/docker/cli/cli/command"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"go.yaml.in/yaml/v4"
@ -266,6 +267,9 @@ func imagesOnly(project *types.Project) *types.Project {
}
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 {
@ -519,6 +523,9 @@ func runConfigImages(ctx context.Context, dockerCli command.Cli, opts configOpti
}
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))
if err != nil {

View file

@ -47,6 +47,14 @@ func TestLocalComposeConfig(t *testing.T) {
res.Assert(t, icmd.Expected{Out: `- ${PORT:-8080}:80`})
})
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 --format json", func(t *testing.T) {
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/config/compose.yaml", "--project-name", projectName, "config", "--variables", "--format", "json")
res.Assert(t, icmd.Expected{Out: `{
@ -67,4 +75,12 @@ func TestLocalComposeConfig(t *testing.T) {
presencevalue: ""
required: false`})
})
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`,
})
})
}