diff --git a/newsfragments/398.bugfix b/newsfragments/398.bugfix new file mode 100644 index 00000000..a4735dbb --- /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 576ed051..c2abc1bf 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 @@ -2699,10 +2700,13 @@ 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 @@ -2732,12 +2736,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, ), diff --git a/tests/integration/test_podman_compose_deps.py b/tests/integration/test_podman_compose_deps.py index fe9f2fd3..65c3485d 100644 --- a/tests/integration/test_podman_compose_deps.py +++ b/tests/integration/test_podman_compose_deps.py @@ -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):