Skip to content

Commit bc4177f

Browse files
committed
Exclude dependent containers on up if --no-deps.
Fixes #398. Signed-off-by: Emanuel Rietveld <[email protected]>
1 parent 8206cc3 commit bc4177f

File tree

3 files changed

+43
-4
lines changed

3 files changed

+43
-4
lines changed

newsfragments/398.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- Fixed a bug that caused dependent containers to be started even with --no-deps

podman_compose.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2600,7 +2600,8 @@ def get_excluded(compose, args):
26002600
if args.services:
26012601
excluded = set(compose.services)
26022602
for service in args.services:
2603-
excluded -= set(x.name for x in compose.services[service]["_deps"])
2603+
if not args.no_deps:
2604+
excluded -= set(x.name for x in compose.services[service]["_deps"])
26042605
excluded.discard(service)
26052606
log.debug("** excluding: %s", excluded)
26062607
return excluded
@@ -2658,6 +2659,12 @@ async def run_container(
26582659
return await compose.podman.run(*command, log_formatter=log_formatter)
26592660

26602661

2662+
def deps_from_container(args, cnt):
2663+
if args.no_deps:
2664+
return set()
2665+
return cnt['_deps']
2666+
2667+
26612668
@cmd_run(podman_compose, "up", "Create and start the entire stack or some of its services")
26622669
async def compose_up(compose: PodmanCompose, args):
26632670
excluded = get_excluded(compose, args)
@@ -2699,10 +2706,14 @@ async def compose_up(compose: PodmanCompose, args):
26992706
if cnt["_service"] in excluded:
27002707
log.debug("** skipping: %s", cnt["name"])
27012708
continue
2702-
podman_args = await container_to_args(compose, cnt, detached=args.detach)
2709+
podman_args = await container_to_args(
2710+
compose, cnt, detached=args.detach, no_deps=args.no_deps
2711+
)
27032712
subproc = await compose.podman.run([], podman_command, podman_args)
27042713
if podman_command == "run" and subproc is not None:
2705-
await run_container(compose, cnt["name"], cnt["_deps"], ([], "start", [cnt["name"]]))
2714+
await run_container(
2715+
compose, cnt["name"], deps_from_container(args, cnt), ([], "start", [cnt["name"]])
2716+
)
27062717
if args.no_start or args.detach or args.dry_run:
27072718
return
27082719
# TODO: handle already existing
@@ -2737,7 +2748,7 @@ async def compose_up(compose: PodmanCompose, args):
27372748
run_container(
27382749
compose,
27392750
cnt["name"],
2740-
cnt["_deps"],
2751+
deps_from_container(args, cnt),
27412752
([], "start", ["-a", cnt["name"]]),
27422753
log_formatter=log_formatter,
27432754
),

tests/integration/test_podman_compose_deps.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,33 @@ def test_run_nodeps(self):
6060
"down",
6161
])
6262

63+
def test_up_nodeps(self):
64+
try:
65+
self.run_subprocess_assert_returncode([
66+
podman_compose_path(),
67+
"-f",
68+
compose_yaml_path(),
69+
"up",
70+
"--no-deps",
71+
"--detach",
72+
"sleep",
73+
])
74+
output, error = self.run_subprocess_assert_returncode([
75+
podman_compose_path(),
76+
"-f",
77+
compose_yaml_path(),
78+
"ps",
79+
])
80+
self.assertNotIn(b"deps_web_1", output)
81+
self.assertIn(b"deps_sleep_1", output)
82+
finally:
83+
self.run_subprocess_assert_returncode([
84+
podman_compose_path(),
85+
"-f",
86+
compose_yaml_path(),
87+
"down",
88+
])
89+
6390

6491
class TestComposeConditionalDeps(unittest.TestCase, RunSubprocessMixin):
6592
def test_deps_succeeds(self):

0 commit comments

Comments
 (0)