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 autodetect_docker_context for list of dict case #34779

Merged
merged 3 commits into from
Oct 6, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,12 @@ def autodetect_docker_context():
if result.returncode != 0:
get_console().print("[warning]Could not detect docker builder. Using default.[/]")
return "default"
context_dicts = (json.loads(line) for line in result.stdout.splitlines() if line.strip())
try:
context_dicts = json.loads(result.stdout)
if isinstance(context_dicts, dict):
context_dicts = [context_dicts]
except json.decoder.JSONDecodeError:
context_dicts = (json.loads(line) for line in result.stdout.splitlines() if line.strip())
utkarsharma2 marked this conversation as resolved.
Show resolved Hide resolved
known_contexts = {info["Name"]: info for info in context_dicts}
if not known_contexts:
get_console().print("[warning]Could not detect docker builder. Using default.[/]")
Expand Down
10 changes: 10 additions & 0 deletions dev/breeze/tests/test_docker_command_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,16 @@ def _fake_ctx_output(*names: str) -> str:
"desktop-linux",
"[info]Using desktop-linux as context",
),
(
_fake_ctx_output("a", "default", "desktop-linux"),
"desktop-linux",
"[info]Using desktop-linux as context",
),
(
'[{"Name": "desktop-linux", "DockerEndpoint": "unix://desktop-linux"}]',
"desktop-linux",
"[info]Using desktop-linux as context",
),
],
)
def test_autodetect_docker_context(context_output: str, selected_context: str, console_output: str):
Expand Down