Skip to content

Commit e6a7694

Browse files
committed
Apply no-deps before we select and mutate target service
Signed-off-by: Nicolas De Loof <[email protected]>
1 parent e90df62 commit e6a7694

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

cmd/compose/run.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ type runOptions struct {
6363
}
6464

6565
func (options runOptions) apply(project *types.Project) error {
66+
if options.noDeps {
67+
err := project.ForServices([]string{options.Service}, types.IgnoreDependencies)
68+
if err != nil {
69+
return err
70+
}
71+
}
72+
6673
target, err := project.GetService(options.Service)
6774
if err != nil {
6875
return err
@@ -93,13 +100,6 @@ func (options runOptions) apply(project *types.Project) error {
93100
}
94101
}
95102

96-
if options.noDeps {
97-
err := project.ForServices([]string{options.Service}, types.IgnoreDependencies)
98-
if err != nil {
99-
return err
100-
}
101-
}
102-
103103
for i, s := range project.Services {
104104
if s.Name == options.Service {
105105
project.Services[i] = target

pkg/e2e/compose_run_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,4 +136,12 @@ func TestLocalComposeRun(t *testing.T) {
136136

137137
c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/deps.yaml", "down", "--remove-orphans")
138138
})
139+
140+
t.Run("run without dependencies", func(t *testing.T) {
141+
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/deps.yaml", "run", "--no-deps", "service_a")
142+
assert.Assert(t, !strings.Contains(res.Combined(), "shared_dep"), res.Combined())
143+
assert.Assert(t, !strings.Contains(res.Combined(), "service_b"), res.Combined())
144+
145+
c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/deps.yaml", "down", "--remove-orphans")
146+
})
139147
}

0 commit comments

Comments
 (0)