Skip to content

Commit 088ff46

Browse files
committed
Fixes #398: exclude deps on up if --no-deps
Signed-off-by: Emanuel Rietveld <[email protected]>
1 parent e76a38d commit 088ff46

File tree

3 files changed

+31
-4
lines changed

3 files changed

+31
-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: 9 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
@@ -2699,10 +2700,13 @@ async def compose_up(compose: PodmanCompose, args):
26992700
if cnt["_service"] in excluded:
27002701
log.debug("** skipping: %s", cnt["name"])
27012702
continue
2702-
podman_args = await container_to_args(compose, cnt, detached=args.detach)
2703+
podman_args = await container_to_args(
2704+
compose, cnt, detached=args.detach, no_deps=args.no_deps
2705+
)
27032706
subproc = await compose.podman.run([], podman_command, podman_args)
2707+
deps = set() if args.no_deps else cnt["_deps"]
27042708
if podman_command == "run" and subproc is not None:
2705-
await run_container(compose, cnt["name"], cnt["_deps"], ([], "start", [cnt["name"]]))
2709+
await run_container(compose, cnt["name"], deps, ([], "start", [cnt["name"]]))
27062710
if args.no_start or args.detach or args.dry_run:
27072711
return
27082712
# TODO: handle already existing
@@ -2732,12 +2736,13 @@ async def compose_up(compose: PodmanCompose, args):
27322736
log.debug("** skipping: %s", cnt["name"])
27332737
continue
27342738

2739+
deps = set() if args.no_deps else cnt["_deps"]
27352740
tasks.add(
27362741
asyncio.create_task(
27372742
run_container(
27382743
compose,
27392744
cnt["name"],
2740-
cnt["_deps"],
2745+
deps,
27412746
([], "start", ["-a", cnt["name"]]),
27422747
log_formatter=log_formatter,
27432748
),

tests/integration/test_podman_compose_deps.py

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

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

6485
class TestComposeConditionalDeps(unittest.TestCase, RunSubprocessMixin):
6586
def test_deps_succeeds(self):

0 commit comments

Comments
 (0)