Only start direct dependencies of service on `compose run ...`

Signed-off-by: Laura Brehm <laurabrehm@hey.com>
This commit is contained in:
Laura Brehm 2022-06-14 01:01:22 +02:00 committed by Nicolas De loof
parent 8862f95858
commit 80b7a8d274
3 changed files with 29 additions and 1 deletions

View File

@ -262,7 +262,9 @@ func startDependencies(ctx context.Context, backend api.Service, project types.P
}
if len(dependencies) > 0 {
return backend.Start(ctx, project.Name, api.StartOptions{})
return backend.Start(ctx, project.Name, api.StartOptions{
Project: &project,
})
}
return nil
}

View File

@ -117,4 +117,16 @@ func TestLocalComposeRun(t *testing.T) {
res := c.RunDockerCmd("ps", "--all")
assert.Assert(t, !strings.Contains(res.Stdout(), "run-test"), res.Stdout())
})
t.Run("run starts only container and dependencies", func(t *testing.T) {
// ensure that even if another service is up run does not start it: https://github.com/docker/compose/issues/9459
res := c.RunDockerComposeCmd("-f", "./fixtures/run-test/deps.yaml", "up", "service_b")
res.Assert(t, icmd.Success)
res = c.RunDockerComposeCmd("-f", "./fixtures/run-test/deps.yaml", "run", "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("-f", "./fixtures/run-test/deps.yaml", "down", "--remove-orphans")
})
}

View File

@ -0,0 +1,14 @@
version: "3.6"
services:
service_a:
image: bash
command: echo "a"
depends_on:
- shared_dep
service_b:
image: bash
command: echo "b"
depends_on:
- shared_dep
shared_dep:
image: bash