Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(devservices): Fix healthcheck bug #247

Merged
merged 1 commit into from
Mar 31, 2025
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 devservices/commands/up.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ def _up(
for cmd in up_commands:
try:
container_names = get_container_names_for_project(
cmd.project_name, cmd.config_path
cmd.project_name, cmd.config_path, cmd.services
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a way to make it clearer that these are the services in the mode?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really besides naming, but I think this should be satisfactory for now, since these are the services that are involved in the docker compose cmd

)
containers_to_check.extend(container_names)
except DockerComposeError as dce:
Expand Down
5 changes: 4 additions & 1 deletion devservices/utils/docker_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def install_docker_compose() -> None:


def get_container_names_for_project(
project_name: str, config_path: str
project_name: str, config_path: str, services: list[str]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a set in theory? I know it would make everything more difficult though

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, that would be more accurate although this shouldn't be a problem here since container names are always unique

) -> list[ContainerNames]:
try:
output = subprocess.check_output(
Expand All @@ -107,6 +107,9 @@ def get_container_names_for_project(
"-f",
config_path,
"ps",
]
+ sorted(services)
+ [
"--format",
'{"name":"{{.Names}}", "short_name":"{{.Service}}"}',
],
Expand Down
8 changes: 6 additions & 2 deletions tests/utils/test_docker_compose.py
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,9 @@ def test_get_all_commands_to_run_complex_shared_dependency(
@mock.patch("devservices.utils.docker_compose.subprocess.check_output")
def test_get_container_names_for_project_success(_mock_check_output: mock.Mock) -> None:
_mock_check_output.return_value = '{"name": "devservices-container1", "short_name": "container1"}\n{"name": "devservices-container2", "short_name": "container2"}'
assert get_container_names_for_project("project", "config_path") == [
assert get_container_names_for_project(
"project", "config_path", ["container1", "container2"]
) == [
ContainerNames(name="devservices-container1", short_name="container1"),
ContainerNames(name="devservices-container2", short_name="container2"),
]
Expand All @@ -787,5 +789,7 @@ def test_get_container_names_for_project_error(_mock_check_output: mock.Mock) ->
returncode=1, cmd="docker compose ps --format", stderr="command failed"
)
with pytest.raises(DockerComposeError) as e:
get_container_names_for_project("project", "config_path")
get_container_names_for_project(
"project", "config_path", ["container1", "container2"]
)
assert e.value.stderr == "command failed"
Loading