Skip to content
Open
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
6 changes: 5 additions & 1 deletion sagemaker-core/src/sagemaker/core/local/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,11 @@ def _create_docker_host(
if self.container_entrypoint:
host_config["entrypoint"] = self.container_entrypoint
if self.container_arguments:
host_config["entrypoint"] = host_config["entrypoint"] + self.container_arguments
if "entrypoint" in host_config:
host_config["entrypoint"] = host_config["entrypoint"] + self.container_arguments
else:
# No custom entrypoint: pass the arguments to the image's own entrypoint.
host_config["command"] = self.container_arguments

if self.is_studio:
host_config["network_mode"] = "sagemaker"
Expand Down
33 changes: 33 additions & 0 deletions sagemaker-core/tests/unit/local/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -1252,6 +1252,39 @@ def test_container_with_entrypoint(self, mock_session_class, mock_get_compose):
assert container.container_entrypoint == ["/bin/bash"]
assert container.container_arguments == ["script.sh"]

@pytest.mark.parametrize(
"entrypoint, arguments, expected",
[
(None, ["--input", "data"], {"command": ["--input", "data"]}),
(["python3", "run.py"], None, {"entrypoint": ["python3", "run.py"]}),
(
["python3", "run.py"],
["--input", "data"],
{"entrypoint": ["python3", "run.py", "--input", "data"]},
),
],
)
@patch("sagemaker.core.local.utils.check_for_studio", return_value=False)
@patch("sagemaker.core.local.image._SageMakerContainer._get_compose_cmd_prefix")
def test_create_docker_host_processing_entrypoint_and_arguments(
self, mock_get_compose, mock_studio, entrypoint, arguments, expected
):
"""Processing arguments are passed with or without a custom entrypoint"""
mock_get_compose.return_value = ["docker", "compose"]
container = _SageMakerContainer(
"local",
1,
"test-image:latest",
Mock(config={}),
container_entrypoint=entrypoint,
container_arguments=arguments,
)

host_config = container._create_docker_host("algo-1", [], set(), "process", [])

for key in ("command", "entrypoint"):
assert host_config.get(key) == expected.get(key)

@patch("subprocess.check_output")
def test_get_compose_cmd_prefix_v2(self, mock_check_output):
"""Test getting docker compose v2 command"""
Expand Down
Loading