Skip to content
Merged
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
2 changes: 1 addition & 1 deletion sagemaker-core/src/sagemaker/core/local/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ def _get_compose_cmd_prefix():
)

if output:
match = re.search(r"v(\d+)", output.strip())
match = re.search(r"version\s+v?(\d+)", output.strip())
if match and int(match.group(1)) >= 2:
logger.info("'Docker Compose' found using Docker CLI.")
compose_cmd_prefix.extend(["docker", "compose"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,7 +618,7 @@ def _get_compose_cmd_prefix(self) -> List[str]:
)

if output:
match = re.search(r"v(\d+)", output.strip())
match = re.search(r"version\s+v?(\d+)", output.strip())
if match and int(match.group(1)) >= 2:
logger.info("'Docker Compose' found using Docker CLI.")
compose_cmd_prefix.extend(["docker", "compose"])
Expand Down
12 changes: 12 additions & 0 deletions sagemaker-core/tests/unit/local/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,18 @@ def test_get_compose_cmd_prefix_docker_compose_v2(self, mock_check_output):

assert result == ["docker", "compose"]

@patch("subprocess.check_output")
def test_get_compose_cmd_prefix_docker_compose_v2_no_v_prefix(self, mock_check_output):
"""Docker Compose installed via brew reports the version without a 'v' prefix.

Regression test for https://github.com/aws/sagemaker-python-sdk/issues/4137.
"""
mock_check_output.return_value = "Docker Compose version 2.22.0"

result = _SageMakerContainer._get_compose_cmd_prefix()

assert result == ["docker", "compose"]

@patch("shutil.which")
@patch("subprocess.check_output")
def test_get_compose_cmd_prefix_docker_compose_cli(self, mock_check_output, mock_which):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,34 @@ def test_get_compose_cmd_prefix_docker_compose_v2(

assert result == ["docker", "compose"]

@patch("sagemaker.core.modules.local_core.local_container.subprocess.check_output")
def test_get_compose_cmd_prefix_docker_compose_v2_no_v_prefix(
self, mock_check_output, mock_session, basic_channel
):
"""Brew-installed Docker Compose reports the version without a 'v' prefix.

Regression test for https://github.com/aws/sagemaker-python-sdk/issues/4137.
"""
container = _LocalContainer(
training_job_name="test-job",
instance_type="local",
instance_count=1,
image="test-image:latest",
container_root="/tmp/test",
input_data_config=[basic_channel],
environment={},
hyper_parameters={},
container_entrypoint=[],
container_arguments=[],
sagemaker_session=mock_session,
)

mock_check_output.return_value = "Docker Compose version 2.22.0"

result = container._get_compose_cmd_prefix()

assert result == ["docker", "compose"]

@patch("sagemaker.core.modules.local_core.local_container.subprocess.check_output")
@patch("sagemaker.core.modules.local_core.local_container.shutil.which")
def test_get_compose_cmd_prefix_docker_compose_standalone(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ def _get_compose_cmd_prefix(self) -> List[str]:
)

if output:
match = re.search(r"v(\d+)", output.strip())
match = re.search(r"version\s+v?(\d+)", output.strip())
if match and int(match.group(1)) >= 2:
logger.info("'Docker Compose' found using Docker CLI.")
compose_cmd_prefix.extend(["docker", "compose"])
Expand Down
13 changes: 13 additions & 0 deletions sagemaker-train/tests/unit/train/local/test_local_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,19 @@ def test_get_compose_cmd_prefix_with_docker_compose_v2(self, mock_check_output,
result = container._get_compose_cmd_prefix()
assert result == ["docker", "compose"]

@patch("sagemaker.train.local.local_container.subprocess.check_output")
def test_get_compose_cmd_prefix_with_docker_compose_v2_no_v_prefix(
self, mock_check_output, _basic_channel
):
"""Brew-installed Docker Compose reports the version without a 'v' prefix.

Regression test for https://github.com/aws/sagemaker-python-sdk/issues/4137.
"""
container = _make_container(_basic_channel)
mock_check_output.return_value = "Docker Compose version 2.22.0"
result = container._get_compose_cmd_prefix()
assert result == ["docker", "compose"]

@patch("sagemaker.train.local.local_container.subprocess.check_output")
def test_get_compose_cmd_prefix_with_docker_compose_v5(self, mock_check_output, _basic_channel):
"""Docker Compose v5 should be accepted."""
Expand Down
Loading