Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
25 changes: 18 additions & 7 deletions podman_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -1020,7 +1020,7 @@ def get_net_args_from_networks(compose, cnt):
return net_args


async def container_to_args(compose, cnt, detached=True):
async def container_to_args(compose, cnt, detached=True, no_deps=False):
# TODO: double check -e , --add-host, -v, --read-only
dirname = compose.dirname
pod = cnt.get("pod", "")
Expand All @@ -1035,7 +1035,7 @@ async def container_to_args(compose, cnt, detached=True):
deps = []
for dep_srv in cnt.get("_deps", []):
deps.extend(compose.container_names_by_service.get(dep_srv.name, []))
if deps:
if deps and not no_deps:
deps_csv = ",".join(deps)
podman_args.append(f"--requires={deps_csv}")
sec = norm_as_list(cnt.get("security_opt"))
Expand Down 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 @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
),
Expand Down Expand Up @@ -2915,7 +2926,7 @@ async def compose_run(compose, args):

compose_run_update_container_from_args(compose, cnt, args)
# run podman
podman_args = await container_to_args(compose, cnt, args.detach)
podman_args = await container_to_args(compose, cnt, args.detach, args.no_deps)
if not args.detach:
podman_args.insert(1, "-i")
if args.rm:
Expand Down
52 changes: 52 additions & 0 deletions tests/integration/test_podman_compose_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,58 @@ def test_deps(self):
"down",
])

def test_run_nodeps(self):
try:
output, error = self.run_subprocess_assert_returncode([
podman_compose_path(),
"-f",
compose_yaml_path(),
"run",
"--rm",
"--no-deps",
"sleep",
"/bin/sh",
"-c",
"wget -O - http://web:8000/hosts || echo Failed to connect",
])
self.assertNotIn(b"HTTP request sent, awaiting response... 200 OK", output)
self.assertNotIn(b"deps_web_1", output)
self.assertIn(b"Failed to connect", output)
finally:
self.run_subprocess_assert_returncode([
podman_compose_path(),
"-f",
compose_yaml_path(),
"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):
Expand Down
Loading