Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add entrypoint and envs options to docker.compose.run() (#659) #660

Closed
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
9 changes: 7 additions & 2 deletions python_on_whales/components/compose/cli_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -663,8 +663,8 @@ def run(
command: List[str] = [],
build: bool = False,
detach: bool = False,
# entrypoint: Optional[List[str]] = None,
# envs: Dict[str, str] = {},
entrypoint: Optional[List[str]] = None,
envs: Dict[str, str] = {},
labels: Dict[str, str] = {},
name: Optional[str] = None,
tty: bool = True,
Expand All @@ -691,6 +691,8 @@ 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.
envs: A dictionary of environment variables to set in the container.
labels: Add or override labels
name: Assign a name to the container.
dependencies: Also start linked services.
Expand Down Expand Up @@ -728,6 +730,9 @@ 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)
for key, value in envs.items():
full_cmd.add_simple_arg("--env", f"{key}={value}")
full_cmd.add_simple_arg("--name", name)
full_cmd.add_flag("--no-TTY", not tty)
full_cmd.add_flag("--no-deps", not dependencies)
Expand Down
24 changes: 24 additions & 0 deletions tests/python_on_whales/components/test_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,6 +753,30 @@ 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_run_envs():
result = docker.compose.run(
"dodo",
["-c", "echo $VAR1,$VAR2"],
envs={"VAR1": "hello", "VAR2": "world"},
remove=True,
tty=False,
)

assert result == "hello,world"


def test_compose_version():
assert "Docker Compose version v2" in docker.compose.version()

Expand Down