Skip to content

Commit a6fd457

Browse files
authored
Docker client: support lists for entrypoints (#12093)
1 parent b7ed5bc commit a6fd457

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

localstack-core/localstack/utils/container_utils/container_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ class ContainerConfiguration:
450450
volumes: VolumeMappings = dataclasses.field(default_factory=VolumeMappings)
451451
ports: PortMappings = dataclasses.field(default_factory=PortMappings)
452452
exposed_ports: List[str] = dataclasses.field(default_factory=list)
453-
entrypoint: Optional[str] = None
453+
entrypoint: Optional[Union[List[str], str]] = None
454454
additional_flags: Optional[str] = None
455455
command: Optional[List[str]] = None
456456
env_vars: Dict[str, str] = dataclasses.field(default_factory=dict)
@@ -861,7 +861,7 @@ def create_container(
861861
image_name: str,
862862
*,
863863
name: Optional[str] = None,
864-
entrypoint: Optional[str] = None,
864+
entrypoint: Optional[Union[List[str], str]] = None,
865865
remove: bool = False,
866866
interactive: bool = False,
867867
tty: bool = False,

localstack-core/localstack/utils/container_utils/docker_cmd_client.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ def _build_run_create_cmd(
714714
image_name: str,
715715
*,
716716
name: Optional[str] = None,
717-
entrypoint: Optional[str] = None,
717+
entrypoint: Optional[Union[List[str], str]] = None,
718718
remove: bool = False,
719719
interactive: bool = False,
720720
tty: bool = False,
@@ -746,7 +746,10 @@ def _build_run_create_cmd(
746746
if name:
747747
cmd += ["--name", name]
748748
if entrypoint is not None: # empty string entrypoint can be intentional
749-
cmd += ["--entrypoint", entrypoint]
749+
if isinstance(entrypoint, str):
750+
cmd += ["--entrypoint", entrypoint]
751+
else:
752+
cmd += ["--entrypoint", shlex.join(entrypoint)]
750753
if privileged:
751754
cmd += ["--privileged"]
752755
if volumes:

localstack-core/localstack/utils/container_utils/docker_sdk_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ def create_container(
606606
image_name: str,
607607
*,
608608
name: Optional[str] = None,
609-
entrypoint: Optional[str] = None,
609+
entrypoint: Optional[Union[List[str], str]] = None,
610610
remove: bool = False,
611611
interactive: bool = False,
612612
tty: bool = False,

tests/integration/docker_utils/test_docker.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import re
77
import textwrap
88
import time
9-
from typing import NamedTuple, Type
9+
from typing import Callable, NamedTuple, Type
1010

1111
import pytest
1212
from docker.models.containers import Container
@@ -85,7 +85,7 @@ def create_container(docker_client: ContainerClient, create_network):
8585
"""
8686
containers = []
8787

88-
def _create_container(image_name: str, **kwargs):
88+
def _create_container(image_name: str, **kwargs) -> ContainerInfo:
8989
kwargs["name"] = kwargs.get("name", _random_container_name())
9090
cid = docker_client.create_container(image_name, **kwargs)
9191
cid = cid.strip()
@@ -187,6 +187,28 @@ def test_create_container_remove_removes_container(
187187
# it takes a while for it to be removed
188188
assert "foobar" in output
189189

190+
@pytest.mark.parametrize(
191+
"entrypoint",
192+
[
193+
"echo",
194+
["echo"],
195+
],
196+
)
197+
def test_set_container_entrypoint(
198+
self,
199+
docker_client: ContainerClient,
200+
create_container: Callable[..., ContainerInfo],
201+
entrypoint: list[str] | str,
202+
):
203+
info = create_container("alpine", entrypoint=entrypoint, command=["true"])
204+
assert 1 == len(docker_client.list_containers(f"id={info.container_id}"))
205+
206+
# start the container
207+
output, _ = docker_client.start_container(info.container_id, attach=True)
208+
output = to_str(output).strip()
209+
210+
assert output == "true"
211+
190212
@markers.skip_offline
191213
def test_create_container_non_existing_image(self, docker_client: ContainerClient):
192214
with pytest.raises(NoSuchImage):

0 commit comments

Comments
 (0)