Skip to content

Commit

Permalink
Merge pull request #10789 from ndeloof/run_no_deps
Browse files Browse the repository at this point in the history
Apply no-deps before we select and mutate target service
  • Loading branch information
glours committed Jul 10, 2023
2 parents ee6aeed + e6a7694 commit 8339269
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 7 additions & 7 deletions cmd/compose/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@ type runOptions struct {
}

func (options runOptions) apply(project *types.Project) error {
if options.noDeps {
err := project.ForServices([]string{options.Service}, types.IgnoreDependencies)
if err != nil {
return err
}
}

target, err := project.GetService(options.Service)
if err != nil {
return err
Expand Down Expand Up @@ -93,13 +100,6 @@ func (options runOptions) apply(project *types.Project) error {
}
}

if options.noDeps {
err := project.ForServices([]string{options.Service}, types.IgnoreDependencies)
if err != nil {
return err
}
}

for i, s := range project.Services {
if s.Name == options.Service {
project.Services[i] = target
Expand Down
8 changes: 8 additions & 0 deletions pkg/e2e/compose_run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,4 +136,12 @@ func TestLocalComposeRun(t *testing.T) {

c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/deps.yaml", "down", "--remove-orphans")
})

t.Run("run without dependencies", func(t *testing.T) {
res := c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/deps.yaml", "run", "--no-deps", "service_a")
assert.Assert(t, !strings.Contains(res.Combined(), "shared_dep"), res.Combined())
assert.Assert(t, !strings.Contains(res.Combined(), "service_b"), res.Combined())

c.RunDockerComposeCmd(t, "-f", "./fixtures/run-test/deps.yaml", "down", "--remove-orphans")
})
}

0 comments on commit 8339269

Please sign in to comment.