diff --git a/newsfragments/398.bugfix b/newsfragments/398.bugfix new file mode 100644 index 0000000..a4735db --- /dev/null +++ b/newsfragments/398.bugfix @@ -0,0 +1 @@ +- Fixed a bug that caused dependent containers to be started even with --no-deps diff --git a/podman_compose.py b/podman_compose.py index 576ed05..e569d23 100755 --- a/podman_compose.py +++ b/podman_compose.py @@ -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 @@ -2658,6 +2659,12 @@ async def run_container( return await compose.podman.run(*command, log_formatter=log_formatter) +def deps_from_container(args, cnt): + if args.no_deps: + return set() + return cnt['_deps'] + + @cmd_run(podman_compose, "up", "Create and start the entire stack or some of its services") async def compose_up(compose: PodmanCompose, args): excluded = get_excluded(compose, args) @@ -2699,10 +2706,14 @@ 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) 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_from_container(args, cnt), ([], "start", [cnt["name"]]) + ) if args.no_start or args.detach or args.dry_run: return # TODO: handle already existing @@ -2737,7 +2748,7 @@ async def compose_up(compose: PodmanCompose, args): run_container( compose, cnt["name"], - cnt["_deps"], + deps_from_container(args, cnt), ([], "start", ["-a", cnt["name"]]), log_formatter=log_formatter, ), diff --git a/tests/integration/test_podman_compose_deps.py b/tests/integration/test_podman_compose_deps.py index fe9f2fd..17893bf 100644 --- a/tests/integration/test_podman_compose_deps.py +++ b/tests/integration/test_podman_compose_deps.py @@ -60,6 +60,33 @@ class TestComposeBaseDeps(unittest.TestCase, RunSubprocessMixin): "down", ]) + def test_up_nodeps(self): + try: + self.run_subprocess_assert_returncode([ + podman_compose_path(), + "-f", + compose_yaml_path(), + "up", + "--no-deps", + "--detach", + "sleep", + ]) + output, error = self.run_subprocess_assert_returncode([ + podman_compose_path(), + "-f", + compose_yaml_path(), + "ps", + ]) + 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):