Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions cmd/compose/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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 {
Comment on lines 269 to 275
Expand Down Expand Up @@ -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))
Comment on lines 525 to 530
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions pkg/e2e/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
})
})
Comment on lines +50 to +56

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: `{
Expand All @@ -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`,
})
})
Comment on lines +79 to +85
}
Loading