Skip to content
Open
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
14 changes: 14 additions & 0 deletions cmd/compose/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,20 @@ func runConfigNoInterpolate(ctx context.Context, dockerCli command.Cli, opts con
return nil, err
}

if len(services) > 0 {
if svcs, ok := model["services"].(map[string]any); ok {
filtered := make(map[string]any, len(services))
for _, name := range services {
if svc, exists := svcs[name]; exists {
filtered[name] = svc
} else {
return nil, fmt.Errorf("no such service: %s", name)
}
}
model["services"] = filtered
}
}

if opts.resolveImageDigests {
err = resolveImageDigests(ctx, dockerCli, model)
if err != nil {
Expand Down
9 changes: 9 additions & 0 deletions pkg/e2e/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@
package e2e

import (
"strings"
"testing"

"gotest.tools/v3/assert"
"gotest.tools/v3/icmd"
)

Expand Down Expand Up @@ -47,6 +49,13 @@ func TestLocalComposeConfig(t *testing.T) {
res.Assert(t, icmd.Expected{Out: `- ${PORT:-8080}:80`})
})

t.Run("--no-interpolate with service filter", func(t *testing.T) {
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/config-filter/compose.yaml", "--project-name", projectName, "config", "--no-interpolate", "example1")
res.Assert(t, icmd.Expected{Out: `example1`})
// example2 should NOT appear in the output when only example1 is requested
assert.Assert(t, !strings.Contains(res.Stdout(), "example2"), "expected example2 to be filtered out")
})

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 Down
18 changes: 18 additions & 0 deletions pkg/e2e/fixtures/config-filter/compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:
example1:
container_name: example1
image: example/example
restart: unless-stopped
ports:
- "3001:3000"
environment:
TZ: ${TZ:-Etc/UTC}

example2:
container_name: example2
image: example/example
restart: unless-stopped
ports:
- "3002:3000"
environment:
TZ: ${TZ:-Etc/UTC}