Skip to content

Commit efb63f2

Browse files
committed
fix(config): warn when service selection is silently ignored
`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>
1 parent 5bf5a21 commit efb63f2

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

cmd/compose/config.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
"github.com/compose-spec/compose-go/v2/template"
3333
"github.com/compose-spec/compose-go/v2/types"
3434
"github.com/docker/cli/cli/command"
35+
"github.com/sirupsen/logrus"
3536
"github.com/spf13/cobra"
3637
"go.yaml.in/yaml/v4"
3738

@@ -266,6 +267,9 @@ func imagesOnly(project *types.Project) *types.Project {
266267
}
267268

268269
func runConfigNoInterpolate(ctx context.Context, dockerCli command.Cli, opts configOptions, services []string) ([]byte, error) {
270+
if len(services) > 0 {
271+
logrus.Warn("service filtering is not applied when --no-interpolate is set, the full model will be rendered")
272+
}
269273
// we can't use ToProject, so the model we render here is only partially resolved
270274
model, err := opts.ToModel(ctx, dockerCli, services)
271275
if err != nil {
@@ -519,6 +523,9 @@ func runConfigImages(ctx context.Context, dockerCli command.Cli, opts configOpti
519523
}
520524

521525
func runVariables(ctx context.Context, dockerCli command.Cli, opts configOptions, services []string) error {
526+
if len(services) > 0 {
527+
logrus.Warn("service filtering is not applied when --variables is set, variables from the full model will be rendered")
528+
}
522529
opts.noInterpolate = true
523530
model, err := opts.ToModel(ctx, dockerCli, services, cli.WithoutEnvironmentResolution, cli.WithLoadOptions(loader.WithSkipValidation))
524531
if err != nil {

pkg/e2e/config_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ func TestLocalComposeConfig(t *testing.T) {
4747
res.Assert(t, icmd.Expected{Out: `- ${PORT:-8080}:80`})
4848
})
4949

50+
t.Run("--no-interpolate with service selection", func(t *testing.T) {
51+
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/config/compose.yaml", "--project-name", projectName, "config", "--no-interpolate", "test")
52+
res.Assert(t, icmd.Expected{
53+
Err: "service filtering is not applied when --no-interpolate is set",
54+
Out: `- ${PORT:-8080}:80`,
55+
})
56+
})
57+
5058
t.Run("--variables --format json", func(t *testing.T) {
5159
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/config/compose.yaml", "--project-name", projectName, "config", "--variables", "--format", "json")
5260
res.Assert(t, icmd.Expected{Out: `{
@@ -67,4 +75,12 @@ func TestLocalComposeConfig(t *testing.T) {
6775
presencevalue: ""
6876
required: false`})
6977
})
78+
79+
t.Run("--variables with service selection", func(t *testing.T) {
80+
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/config/compose.yaml", "--project-name", projectName, "config", "--variables", "test")
81+
res.Assert(t, icmd.Expected{
82+
Err: "service filtering is not applied when --variables is set",
83+
Out: `PORT`,
84+
})
85+
})
7086
}

0 commit comments

Comments
 (0)