From bdd5556b25fee2064cb121be3633336d524a1efd Mon Sep 17 00:00:00 2001 From: Jeremias Weihmann <49484956+www84@users.noreply.github.com> Date: Mon, 23 Dec 2024 23:43:46 +0100 Subject: [PATCH] Add entrypoint option to docker.compose.run() (#659) --- python_on_whales/components/compose/cli_wrapper.py | 4 +++- tests/python_on_whales/components/test_compose.py | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/python_on_whales/components/compose/cli_wrapper.py b/python_on_whales/components/compose/cli_wrapper.py index 63b33f5a..245c81cc 100644 --- a/python_on_whales/components/compose/cli_wrapper.py +++ b/python_on_whales/components/compose/cli_wrapper.py @@ -663,7 +663,7 @@ def run( command: List[str] = [], build: bool = False, detach: bool = False, - # entrypoint: Optional[List[str]] = None, + entrypoint: Optional[List[str]] = None, # envs: Dict[str, str] = {}, labels: Dict[str, str] = {}, name: Optional[str] = None, @@ -691,6 +691,7 @@ def run( command: The command to execute. detach: if `True`, returns immediately with the Container. If `False`, returns the command stdout as string. + entrypoint: The entrypoint to execute. labels: Add or override labels name: Assign a name to the container. dependencies: Also start linked services. @@ -728,6 +729,7 @@ def run( full_cmd = self.docker_compose_cmd + ["run"] full_cmd.add_flag("--build", build) full_cmd.add_flag("--detach", detach) + full_cmd.add_simple_arg("--entrypoint", entrypoint) full_cmd.add_simple_arg("--name", name) full_cmd.add_flag("--no-TTY", not tty) full_cmd.add_flag("--no-deps", not dependencies) diff --git a/tests/python_on_whales/components/test_compose.py b/tests/python_on_whales/components/test_compose.py index 99e11ba1..c1029f0c 100644 --- a/tests/python_on_whales/components/test_compose.py +++ b/tests/python_on_whales/components/test_compose.py @@ -753,6 +753,18 @@ def test_docker_compose_run_labels(): docker.compose.down(timeout=1) +def test_compose_run_entrypoint(): + result = docker.compose.run( + "dodo", + ["cmd-is-argument-for-echo"], + entrypoint="/bin/echo", + remove=True, + tty=False, + ) + + assert result == "cmd-is-argument-for-echo" + + def test_compose_version(): assert "Docker Compose version v2" in docker.compose.version()