Skip to content

Commit

Permalink
Fixes containers#398: exclude deps on up if --no-deps
Browse files Browse the repository at this point in the history
Signed-off-by: Emanuel Rietveld <[email protected]>
  • Loading branch information
bailsman committed Jan 15, 2025
1 parent e76a38d commit 632f377
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions newsfragments/398.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Fixed a bug that caused dependent containers to be started even with --no-deps
11 changes: 7 additions & 4 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -2600,7 +2600,8 @@ def get_excluded(compose, args):
if args.services:
excluded = set(compose.services)
for service in args.services:
excluded -= set(x.name for x in compose.services[service]["_deps"])
if not args.no_deps:
excluded -= set(x.name for x in compose.services[service]["_deps"])
excluded.discard(service)
log.debug("** excluding: %s", excluded)
return excluded
Expand Down Expand Up @@ -2699,10 +2700,11 @@ async def compose_up(compose: PodmanCompose, args):
if cnt["_service"] in excluded:
log.debug("** skipping: %s", cnt["name"])
continue
podman_args = await container_to_args(compose, cnt, detached=args.detach)
podman_args = await container_to_args(compose, cnt, detached=args.detach, no_deps=args.no_deps)
subproc = await compose.podman.run([], podman_command, podman_args)
deps = set() if args.no_deps else cnt["_deps"]
if podman_command == "run" and subproc is not None:
await run_container(compose, cnt["name"], cnt["_deps"], ([], "start", [cnt["name"]]))
await run_container(compose, cnt["name"], deps, ([], "start", [cnt["name"]]))
if args.no_start or args.detach or args.dry_run:
return
# TODO: handle already existing
Expand Down Expand Up @@ -2732,12 +2734,13 @@ async def compose_up(compose: PodmanCompose, args):
log.debug("** skipping: %s", cnt["name"])
continue

deps = set() if args.no_deps else cnt["_deps"]
tasks.add(
asyncio.create_task(
run_container(
compose,
cnt["name"],
cnt["_deps"],
deps,
([], "start", ["-a", cnt["name"]]),
log_formatter=log_formatter,
),
Expand Down
21 changes: 21 additions & 0 deletions tests/integration/test_podman_compose_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,27 @@ def test_run_nodeps(self):
"down",
])

def test_up_nodeps(self):
try:
output, error = self.run_subprocess_assert_returncode([
podman_compose_path(),
"-f",
compose_yaml_path(),
"up",
"--detach",
"--no-deps",
"sleep",
])
self.assertNotIn(b"deps_web_1", output)
self.assertIn(b"deps_sleep_1", output)
finally:
self.run_subprocess_assert_returncode([
podman_compose_path(),
"-f",
compose_yaml_path(),
"down",
])


class TestComposeConditionalDeps(unittest.TestCase, RunSubprocessMixin):
def test_deps_succeeds(self):
Expand Down

0 comments on commit 632f377

Please sign in to comment.