mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 19:01:54 +00:00
- Add MCR_REGISTRY constant, is_mcr / mcr_repo / fetch_mcr_tags helpers mirroring the Docker Hub and GHCR pattern. Tags are fetched via the Docker Registry V2 API with RFC 5988 Link-header pagination (anonymous access; MCR is a public read mirror). Wire MCR into both the external test_image_versions warning surface and the find_outdated_updates orchestrator in utils.update.docker. - Bump mcr.microsoft.com/playwright in test-e2e-playwright from v1.59.1-noble to v1.60.0-noble — the update was surfaced by the new MCR detection path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
55 lines
1.4 KiB
Python
55 lines
1.4 KiB
Python
from __future__ import annotations
|
|
|
|
import re
|
|
from typing import Any
|
|
|
|
DOCKER_HUB_REGISTRIES = frozenset(
|
|
{"docker.io", "registry-1.docker.io", "index.docker.io"}
|
|
)
|
|
GHCR_REGISTRY = "ghcr.io"
|
|
MCR_REGISTRY = "mcr.microsoft.com"
|
|
|
|
# Docker image reference (name only, WITHOUT tag/digest).
|
|
IMAGE_NAME_RE = re.compile(
|
|
r"^"
|
|
r"(" # optional registry
|
|
r"(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)"
|
|
r"(?:\.(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?))*"
|
|
r"(?:\:[0-9]{1,5})?"
|
|
r"/"
|
|
r")?"
|
|
r"[a-z0-9]+(?:[._-][a-z0-9]+)*"
|
|
r"(?:/[a-z0-9]+(?:[._-][a-z0-9]+)*)*"
|
|
r"$"
|
|
)
|
|
|
|
|
|
def is_valid_image_name(image: Any) -> bool:
|
|
if not isinstance(image, str):
|
|
return False
|
|
image = image.strip()
|
|
if not image or " " in image or "@" in image:
|
|
return False
|
|
|
|
# Reject repo:tag while still allowing registry hosts with a port.
|
|
if image.rfind(":") > image.rfind("/"):
|
|
return False
|
|
|
|
return IMAGE_NAME_RE.fullmatch(image) is not None
|
|
|
|
|
|
def split_registry_and_name(image: str) -> tuple[str | None, str] | None:
|
|
"""Return (registry, repository_name) for a validated Docker image name."""
|
|
image = image.strip()
|
|
if not is_valid_image_name(image):
|
|
return None
|
|
|
|
first, sep, rest = image.partition("/")
|
|
if not sep:
|
|
return None, image
|
|
|
|
if "." in first or ":" in first or first == "localhost":
|
|
return first, rest
|
|
|
|
return None, image
|