Skip to content

Commit

Permalink
Merge pull request #146 from dirkmueller/main
Browse files Browse the repository at this point in the history
Reset the entrypoint properly when custom_entrypoint is used
  • Loading branch information
dcermak authored Aug 7, 2023
2 parents 66e1c68 + 92888b3 commit 0237e49
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
25 changes: 16 additions & 9 deletions pytest_container/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def get_volume_creator(


_CONTAINER_ENTRYPOINT = "/bin/bash"
_CONTAINER_STOPSIGNAL = ["--stop-signal", "SIGTERM"]
_CONTAINER_STOPSIGNAL = ("--stop-signal", "SIGTERM")


@enum.unique
Expand Down Expand Up @@ -519,22 +519,29 @@ def get_launch_cmd(
)

id_or_url = self.container_id or self.url
bash_launch_end = _CONTAINER_STOPSIGNAL + [
"-it",
id_or_url,
container_launch = ("-it", id_or_url)
bash_launch_end = (
*_CONTAINER_STOPSIGNAL,
*container_launch,
_CONTAINER_ENTRYPOINT,
]
)
if self.entry_point == EntrypointSelection.IMAGE:
cmd.extend(["-it", id_or_url])
cmd.extend(container_launch)
elif self.entry_point == EntrypointSelection.BASH:
cmd.extend(bash_launch_end)
elif self.entry_point == EntrypointSelection.AUTO:
if self.custom_entry_point:
cmd.extend(["-it", id_or_url, self.custom_entry_point])
cmd.extend(
(
"--entrypoint",
self.custom_entry_point,
*container_launch,
)
)
elif container_runtime._get_image_entrypoint_cmd(
id_or_url, "Entrypoint"
) or container_runtime._get_image_entrypoint_cmd(id_or_url, "Cmd"):
cmd.extend(["-it", id_or_url])
cmd.extend(container_launch)
else:
cmd.extend(bash_launch_end)
else: # pragma: no cover
Expand Down Expand Up @@ -916,7 +923,7 @@ def release_lock() -> None:
extra_run_args = self.extra_run_args

if self.container_name:
extra_run_args.extend(["--name", self.container_name])
extra_run_args.extend(("--name", self.container_name))

# We must perform the launches in separate branches, as containers with
# port forwards must be launched while the lock is being held. Otherwise
Expand Down
9 changes: 9 additions & 0 deletions tests/images.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@
""",
)

CMDLINE_APP_CONTAINER = DerivedContainer(
base=LEAP,
custom_entry_point="/bin/sh",
containerfile="""
ENTRYPOINT ["/usr/bin/id"]
CMD ["--help"]
""",
)

LEAP_WITH_MAN = DerivedContainer(
base=LEAP_URL,
containerfile="RUN zypper -n in man",
Expand Down
17 changes: 17 additions & 0 deletions tests/test_launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import pytest

from .images import CMDLINE_APP_CONTAINER
from .images import CONTAINER_THAT_FAILS_TO_LAUNCH
from .images import LEAP
from .test_volumes import LEAP_WITH_BIND_MOUNT_AND_VOLUME
Expand Down Expand Up @@ -212,6 +213,22 @@ def test_launcher_does_not_override_stopsignal_for_entrypoint(
assert container.inspect.config.stop_signal in (9, "SIGKILL")


@pytest.mark.parametrize(
"container",
[
CMDLINE_APP_CONTAINER,
],
indirect=True,
)
def test_launcher_does_can_check_binaries_with_entrypoint(
container: ContainerData,
) -> None:
"""Check that the we can check for installed binaries even if the container
has an entrypoint specified that is not a shell and terminates immediately.
"""
assert container.connection.exists("bash")


def test_derived_container_pulls_base(
container_runtime: OciRuntimeBase, host: Any, pytestconfig: pytest.Config
) -> None:
Expand Down

0 comments on commit 0237e49

Please sign in to comment.