Files
computer-playbook/tests/unit/python/cli/contributing/mirror/test_sync.py
T
kevinveenbirkenbachandClaude Opus 5.5 1ba796d7f1 fix(ci): pull the images the runner uses itself from the GHCR mirror
The GHCR mirror covered role images only. The images the runner pulls on
its own went straight to Docker Hub: coredns from compose.yml, the cache
stack in compose/cache.override.yml and alpine:latest, the init image of
scripts/docker/cache/package-frontend/certs.sh. With the anonymous
githubactions quota spent, the guide step of Postmarks#0 (main run
37954203718) and Shopware#2 (#872) died on "toomanyrequests" while pulling
alpine:latest, after coredns had hit the same limit.

iter_runner_images (utils/docker/image/discovery.py) finds those images,
and the mirror sync and the fork-PR wait now cover them next to the role
images. On a real GitHub runner compose_file_args layers a generated
build/compose/runner-mirror.override.yml that points only the services of
the layered compose files at their mirror, and the certificate generator
gets the mirrored init image. Local runs and act are unchanged, and the
coredns literal stays in compose.yml for Dependabot. test-dns now waits for
images-mirror-missing like the deploy and workspace jobs, since it brings up
the stack too.

Verified with docker compose config on a simulated GitHub runner: the
service set is unchanged and only the runner images point at
ghcr.io/infinito-nexus/core/mirror/docker.io/..., and an existing role mirror
under that scheme pulls anonymously.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-10 10:37:41 +02:00

97 lines
2.9 KiB
Python

from __future__ import annotations
import unittest
from unittest.mock import patch
import cli.contributing.mirror.sync.__main__ as sync_main
from cli.contributing.mirror.model import ImageRef
class TestMirrorSync(unittest.TestCase):
def test_only_missing_skips_existing_destination(self) -> None:
image = ImageRef(
role="web-app-nextcloud",
service="app",
name="nextcloud",
version="31.0.0",
source="docker.io/library/nextcloud:31.0.0",
registry="docker.io",
)
with (
patch(
"cli.contributing.mirror.sync.__main__.iter_role_images",
return_value=[image],
),
patch(
"cli.contributing.mirror.sync.__main__.iter_runner_images",
return_value=[],
),
patch.object(
sync_main.GHCRProvider,
"image_base",
return_value="ghcr.io/acme/myrepo/mirror/docker.io/nextcloud",
),
patch.object(
sync_main.GHCRProvider, "tag_exists", return_value=True
) as mock_tag_exists,
patch.object(sync_main.GHCRProvider, "mirror") as mock_mirror,
patch(
"sys.argv",
[
"mirror-sync",
"--ghcr-namespace",
"acme",
"--ghcr-repository",
"myrepo",
"--only-missing",
],
),
):
result = sync_main.main()
self.assertEqual(result, 0)
mock_tag_exists.assert_called_once_with(image)
mock_mirror.assert_not_called()
def test_runner_images_are_mirrored_with_the_role_images(self) -> None:
image = ImageRef(
role="runner",
service="coredns",
name="coredns/coredns",
version="1.14.4",
source="docker.io/coredns/coredns:1.14.4",
registry="docker.io",
source_file="compose.yml",
)
with (
patch(
"cli.contributing.mirror.sync.__main__.iter_role_images",
return_value=[],
),
patch(
"cli.contributing.mirror.sync.__main__.iter_runner_images",
return_value=[image],
),
patch.object(sync_main.GHCRProvider, "mirror") as mock_mirror,
patch(
"sys.argv",
[
"mirror-sync",
"--ghcr-namespace",
"acme",
"--ghcr-repository",
"myrepo",
],
),
):
result = sync_main.main()
self.assertEqual(result, 0)
mock_mirror.assert_called_once_with(image)
if __name__ == "__main__": # pragma: no cover
unittest.main()