Fix Jenkins-update flow: redeploy_project pull + delete_image safety + delete_container
Bug fixes from product test: 1. redeploy_project: BUILD_FAILED now includes explicit image pull (stop → pull → start) 2. delete_image: Distinguishes running vs stopped containers, suggests system_prune for stopped refs 3. New tool delete_container: Verify stopped state before deletion, confirmation required Tests added for all three paths plus stopped-container edge cases. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -217,7 +217,8 @@ def register_images(mcp: FastMCP, config: AppConfig, client: DsmClient) -> None:
|
||||
img_hash = target.get("id", "")
|
||||
|
||||
# Check if image is in use by any container
|
||||
in_use_by: list[str] = []
|
||||
in_use_running: list[str] = []
|
||||
in_use_stopped: list[str] = []
|
||||
try:
|
||||
ctr_data = await client.request(
|
||||
"SYNO.Docker.Container",
|
||||
@@ -231,12 +232,25 @@ def register_images(mcp: FastMCP, config: AppConfig, client: DsmClient) -> None:
|
||||
ctr_img_id == img_hash or (hash_prefix and ctr_img_id.startswith(hash_prefix))
|
||||
):
|
||||
ctr_name = ctr.get("name") or ctr.get("Names", ["?"])[0]
|
||||
in_use_by.append(ctr_name)
|
||||
status = ctr.get("status", ctr.get("state", "")).lower()
|
||||
if status == "running":
|
||||
in_use_running.append(ctr_name)
|
||||
else:
|
||||
in_use_stopped.append(ctr_name)
|
||||
except Exception as e:
|
||||
logger.debug("Could not fetch containers for in-use check: %s", e)
|
||||
|
||||
if in_use_by:
|
||||
return f"Cannot delete '{display_name}': image is used by " + ", ".join(in_use_by)
|
||||
if in_use_running:
|
||||
return (
|
||||
f"Cannot delete '{display_name}': image is used by running container(s): "
|
||||
+ ", ".join(in_use_running)
|
||||
)
|
||||
|
||||
if in_use_stopped:
|
||||
return (
|
||||
f"Cannot delete '{display_name}': image is used by stopped container '{in_use_stopped[0]}'.\n"
|
||||
f"Delete the container first or run system_prune to clean up stopped containers."
|
||||
)
|
||||
|
||||
if not confirmed:
|
||||
return (
|
||||
|
||||
Reference in New Issue
Block a user