feat: name nodes and templates in Docker image delete conflicts

The compute translates the container ids in a daemon delete conflict
into the GNS3 node and project behind each container. Leftover
containers from closed projects and containers created outside GNS3
are named as such.

The controller lists the templates referencing the image in the
conflict error, matched through the canonical image name. After a
successful deletion it emits a docker.image.deleted notification with
those templates: their nodes can no longer start.
This commit is contained in:
YueGuobin committed 2026-11-06 22:05:52 +08:00
1 parent 04a8ba06a8
commit de986e890e
6 files changed
+341 -7

No files matched your search

+38
View File
@@ -72,6 +72,44 @@ def validate_docker_image_name(image: str) -> None:
raise ValueError(f"Invalid Docker image name: {image}")
def canonical_docker_image_name(image: str) -> str:
"""
Normalize a Docker image reference for name comparisons.
Registry hosts are dropped, Docker Hub's implicit "library/" namespace and
the implicit ":latest" tag are made explicit, so "alpine",
"library/alpine:latest" and "docker.io/library/alpine" all normalize to
the same string. A reference pinned by digest keeps its digest and loses
its tag.
"""
reference = image.strip()
if "/" in reference:
registry, _, remainder = reference.partition("/")
if registry == "localhost" or "." in registry or ":" in registry:
# the first path element is a registry host, not a namespace
reference = remainder
if "@" in reference:
repository, _, digest = reference.rpartition("@")
if not repository:
return reference # a bare digest, nothing to normalize
# with a digest pinned the tag does not take part in the identity
repository = repository.partition(":")[0]
return f"{_canonical_docker_repository(repository)}@{digest}"
repository, separator, tag = reference.rpartition(":")
if not separator or not repository:
repository, tag = reference, "latest"
return f"{_canonical_docker_repository(repository)}:{tag or 'latest'}"
def _canonical_docker_repository(repository: str) -> str:
if "/" not in repository:
# images without a namespace live in Docker Hub's "library/" namespace
return f"library/{repository}"
return repository
async def list_images(image_type):
"""
Scan directories for available image for a given type.