mirror of
https://github.com/containers/podman-compose.git
synced 2025-02-05 12:59:40 +01:00
Exclude dependent containers on up if --no-deps.
Fixes #398. Signed-off-by: Emanuel Rietveld <e.j.rietveld@gmail.com>
This commit is contained in:
parent
8206cc3ea2
commit
bc4177fbdc
1
newsfragments/398.bugfix
Normal file
1
newsfragments/398.bugfix
Normal file
@ -0,0 +1 @@
|
||||
- Fixed a bug that caused dependent containers to be started even with --no-deps
|
@ -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,
|
||||
),
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user