Skip to content

Commit

Permalink
Add envs option to docker.compose.run() (#664) (#665)
Browse files Browse the repository at this point in the history
  • Loading branch information
www84 authored Dec 26, 2024
1 parent 406eea4 commit 6312061
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
5 changes: 4 additions & 1 deletion python_on_whales/components/compose/cli_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ def run(
build: bool = False,
detach: bool = False,
entrypoint: Optional[str] = None,
# envs: Dict[str, str] = {},
envs: Dict[str, str] = {},
labels: Dict[str, str] = {},
name: Optional[str] = None,
tty: bool = True,
Expand Down Expand Up @@ -695,6 +695,7 @@ def run(
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 @@ -735,6 +736,8 @@ def 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
12 changes: 12 additions & 0 deletions tests/python_on_whales/components/test_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,6 +765,18 @@ def test_compose_run_entrypoint():
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_run_volume():
with tempfile.NamedTemporaryFile() as fst, tempfile.NamedTemporaryFile() as snd:
fst.write(b"Hello ")
Expand Down

0 comments on commit 6312061

Please sign in to comment.