From e7fdaa1d101feb41f5fb28a11751a421f96ceda9 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Mon, 2 Feb 2026 15:45:27 +0100 Subject: [PATCH] fix(mirror): iterate all images and fail at end on mirror errors - mirror sync now continues on individual skopeo failures - collect and summarize failed images - return non-zero exit code only after all images were processed - make GitHub workflow respect mirror sync exit status https://chatgpt.com/share/6980b558-5fdc-800f-911e-48bbc35a461f --- .github/workflows/mirror-images.yml | 5 ++-- cli/mirror/sync/__main__.py | 44 +++++++++++++++++++++++++---- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/.github/workflows/mirror-images.yml b/.github/workflows/mirror-images.yml index c3d4a0650a..276b0ac034 100644 --- a/.github/workflows/mirror-images.yml +++ b/.github/workflows/mirror-images.yml @@ -97,7 +97,7 @@ jobs: continue-on-error: true shell: bash run: | - set +e + set -euo pipefail # Defaults: # - Namespace defaults to repo owner (user/org), works for schedule & normal runs @@ -116,5 +116,4 @@ jobs: --ghcr-namespace "${GHCR_NAMESPACE}" \ --ghcr-prefix "${GHCR_PREFIX}" - echo ">>> Mirror sync finished (best-effort)" - exit 0 + echo ">>> Mirror sync finished." diff --git a/cli/mirror/sync/__main__.py b/cli/mirror/sync/__main__.py index 95ef277166..99947ff0ab 100644 --- a/cli/mirror/sync/__main__.py +++ b/cli/mirror/sync/__main__.py @@ -1,9 +1,13 @@ from __future__ import annotations -import argparse -from pathlib import Path -from cli.mirror.util import iter_role_images +import argparse +import subprocess +import sys +from pathlib import Path +from typing import List + from cli.mirror.providers import GHCRProvider +from cli.mirror.util import iter_role_images def main() -> int: @@ -16,9 +20,39 @@ def main() -> int: provider = GHCRProvider(args.ghcr_namespace, args.ghcr_prefix) repo_root = Path(args.repo_root).resolve() - for img in iter_role_images(repo_root): - provider.mirror(img) + failures: List[str] = [] + total = 0 + for img in iter_role_images(repo_root): + total += 1 + src = f"docker://docker.io/{img.source}" + dest = f"docker://{provider.image_base(img)}:{img.version}" + label = f"{img.role}:{img.service} ({img.name}:{img.version})" + + try: + print(f"[mirror] {label}: {src} -> {dest}", flush=True) + provider.mirror(img) + except subprocess.CalledProcessError as e: + # keep going, but remember the failure + msg = ( + f"{label}: FAILED (exit={e.returncode})\n" + f" cmd: {' '.join(map(str, e.cmd))}" + ) + failures.append(msg) + print(f"[mirror] {label}: FAILED, continuing...", file=sys.stderr, flush=True) + except Exception as e: + msg = f"{label}: FAILED (unexpected error: {e!r})" + failures.append(msg) + print(f"[mirror] {label}: FAILED (unexpected), continuing...", file=sys.stderr, flush=True) + + if failures: + print("\n[mirror] SUMMARY: some images failed:", file=sys.stderr) + for f in failures: + print(f"- {f}", file=sys.stderr) + print(f"\n[mirror] Result: {len(failures)}/{total} failed.", file=sys.stderr) + return 1 + + print(f"\n[mirror] Result: {total}/{total} succeeded.") return 0