Skip to content

Commit

Permalink
Clean up Breeze output for Docker context (#38857)
Browse files Browse the repository at this point in the history
(cherry picked from commit 5d10c4a)
  • Loading branch information
uranusjr authored and ephraimbuddy committed Jun 5, 2024
1 parent 294bcce commit 66e2b5d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
10 changes: 4 additions & 6 deletions dev/breeze/src/airflow_breeze/utils/docker_command_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ def autodetect_docker_context():
# On Windows, some contexts are used for WSL2. We don't want to use those.
if context["DockerEndpoint"] == "npipe:////./pipe/dockerDesktopLinuxEngine":
continue
get_console().print(f"[info]Using {preferred_context_name} as context.[/]")
get_console().print(f"[info]Using {preferred_context_name!r} as context.[/]")
return preferred_context_name
fallback_context = next(iter(known_contexts))
get_console().print(
Expand All @@ -662,11 +662,9 @@ def get_and_use_docker_context(context: str):
if context == "autodetect":
context = autodetect_docker_context()
run_command(["docker", "context", "create", context], check=False)
output = run_command(["docker", "context", "use", context], check=False)
if output.returncode != 0:
get_console().print(
f"[warning] Could no use the context {context}. Continuing with current context[/]"
)
output = run_command(["docker", "context", "use", context], check=False, stdout=DEVNULL, stderr=DEVNULL)
if output.returncode:
get_console().print(f"[warning]Could no use context {context!r}. Continuing with current context[/]")
return context


Expand Down
10 changes: 5 additions & 5 deletions dev/breeze/tests/test_docker_command_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ def _fake_ctx_output(*names: str) -> str:
(
_fake_ctx_output("default"),
"default",
"[info]Using default as context",
"[info]Using 'default' as context",
),
("\n", "default", "[warning]Could not detect docker builder"),
(
Expand All @@ -216,22 +216,22 @@ def _fake_ctx_output(*names: str) -> str:
(
_fake_ctx_output("a", "desktop-linux"),
"desktop-linux",
"[info]Using desktop-linux as context",
"[info]Using 'desktop-linux' as context",
),
(
_fake_ctx_output("a", "default"),
"default",
"[info]Using default as context",
"[info]Using 'default' as context",
),
(
_fake_ctx_output("a", "default", "desktop-linux"),
"desktop-linux",
"[info]Using desktop-linux as context",
"[info]Using 'desktop-linux' as context",
),
(
'[{"Name": "desktop-linux", "DockerEndpoint": "unix://desktop-linux"}]',
"desktop-linux",
"[info]Using desktop-linux as context",
"[info]Using 'desktop-linux' as context",
),
],
)
Expand Down

0 comments on commit 66e2b5d

Please sign in to comment.