ashb commented on code in PR #73836:
URL: https://github.com/apache/airflow/pull/73836#discussion_r4126123444


##########
dev/breeze/src/airflow_breeze/utils/docker_command_utils.py:
##########
@@ -802,22 +806,61 @@ def pull_images_with_retries(
     return all_pulled
 
 
+def remove_stale_worktree_containers() -> None:
+    result = run_command(
+        [
+            "docker",
+            "ps",
+            "--all",
+            "--filter",
+            "label=org.apache.airflow.breeze=true",
+            "--format",
+            '{{.ID}}\t{{.Label "org.apache.airflow.breeze.worktree"}}',
+        ],
+        capture_output=True,
+        text=True,
+        check=False,
+    )
+    if result.returncode != 0:
+        console_print("[error]Unable to discover containers belonging to 
deleted worktrees.[/]")
+        return
+    for line in result.stdout.splitlines():
+        container_id, _, worktree = line.partition("\t")
+        if _worktree_is_missing(worktree):
+            console_print(f"Removing container {container_id} for deleted 
worktree {worktree}")
+            run_command(["docker", "rm", "--force", "--volumes", 
container_id], check=False)
+
+
+def _worktree_is_missing(worktree: str) -> bool:

Review Comment:
   We could, but it feels like overkill to me -- just how often is it that two 
different machines will be pointing at the same docker host. Feels like rarest 
of edge cases?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to