Skip to content

Commit

Permalink
Added timezone argument to run and create (#579)
Browse files Browse the repository at this point in the history
  • Loading branch information
tjd78 authored Apr 18, 2024
1 parent 0a9edc5 commit de46667
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
7 changes: 7 additions & 0 deletions python_on_whales/components/container/cli_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -626,6 +626,7 @@ def create(
systemd: Optional[Union[bool, Literal["always"]]] = None,
tmpfs: List[ValidPath] = [],
tty: bool = False,
tz: Optional[str] = None,
ulimit: List[str] = [],
user: Optional[str] = None,
userns: Optional[str] = None,
Expand Down Expand Up @@ -791,6 +792,7 @@ def create(
full_cmd.add_simple_arg("--systemd", systemd)
full_cmd.add_args_list("--tmpfs", tmpfs)
full_cmd.add_flag("--tty", tty)
full_cmd.add_simple_arg("--tz", tz)
full_cmd.add_args_list("--ulimit", ulimit)

full_cmd.add_simple_arg("--user", user)
Expand Down Expand Up @@ -1387,6 +1389,7 @@ def run(
systemd: Optional[Union[bool, Literal["always"]]] = None,
tmpfs: List[ValidPath] = [],
tty: bool = False,
tz: Optional[str] = None,
ulimit: List[str] = [],
user: Optional[str] = None,
userns: Optional[str] = None,
Expand Down Expand Up @@ -1549,6 +1552,9 @@ def run(
https://docs.podman.io/en/latest/markdown/podman-run.1.html#systemd-true-false-always
tty: Allocate a pseudo-TTY. Allow the process to access your terminal
to write on it.
tz: Set timezone in container, or `local` to match the host's timezone.
See `/usr/share/zoneinfo/` for valid timezones.
Note: This option is only known to apply to Podman containers.
user: Username or UID (format: `<name|uid>[:<group|gid>]`)
userns: User namespace to use
uts: UTS namespace to use
Expand Down Expand Up @@ -1718,6 +1724,7 @@ def run(
full_cmd.add_simple_arg("--systemd", systemd)
full_cmd.add_args_list("--tmpfs", tmpfs)
full_cmd.add_flag("--tty", tty)
full_cmd.add_simple_arg("--tz", tz)
full_cmd.add_args_list("--ulimit", ulimit)

full_cmd.add_simple_arg("--user", user)
Expand Down
20 changes: 20 additions & 0 deletions tests/python_on_whales/components/test_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,26 @@ def test_run_with_preserve_fds(podman_client: DockerClient):
assert os.read(read_fd, 7) == b"foobar\n"


def test_run_with_timezone(podman_client: DockerClient):
output = podman_client.container.run(
"ubuntu", ["date", "+%Z"], tz="local", remove=True
)
# Check the timezone in the container matches that in the host.
assert output == datetime.now().astimezone().strftime("%Z")


def test_create_start_with_timezone(podman_client: DockerClient):
# Choose a timezone to check that's different from the default in ubuntu
# (UTC). GMT is a commonly available and valid timezone.
with podman_client.container.create(
"ubuntu", ["sleep", "infinity"], tz="GMT"
) as container:
container.start()
output = podman_client.execute(container, ["date", "+%Z"])
# Check the timezone in the container matches what was specified
assert output == "GMT"


@pytest.mark.parametrize(
"ctr_client",
["docker", pytest.param("podman", marks=pytest.mark.xfail)],
Expand Down

0 comments on commit de46667

Please sign in to comment.