mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-12-06 01:40:19 +00:00
The override was written to .env but reached no container, and three resolvers still built the GHCR namespace from GITHUB_REPOSITORY. compose.yml passes it to the runner, call-test-workspace forwards it into the test container, and the development deploy forwards it to Ansible. mirrors.py and runner_mirror.py take the namespace from utils.docker.mirror.ghcr_coordinates() (the former _owner_and_repository, now the one resolver), and service_ref.sh reads and validates the override the same way. The repository part now follows the OCI path component grammar. 🎯 Fix: 91 % 💥 Break: 4 % 💸 Tokens: 100 % ⏱️ Velocity: 100 % 🛡️ Security: 100 % 🏆 Score: 87 🚦 Gate: ✅ 90/5, tokens and velocity <= 100, security 100 % Created-with: https://s.veen.world/skills Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
69 lines
2.2 KiB
Python
69 lines
2.2 KiB
Python
"""Point the images the CI runner pulls itself at their GHCR mirror."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import os
|
|
from typing import TYPE_CHECKING
|
|
|
|
from cli.contributing.mirror.providers import GHCRProvider
|
|
from utils.cache.yaml import dump_yaml
|
|
from utils.docker.image.discovery import iter_runner_images
|
|
from utils.docker.mirror import ghcr_coordinates
|
|
|
|
if TYPE_CHECKING:
|
|
from pathlib import Path
|
|
|
|
OVERRIDE = "build/compose/runner-mirror.override.yml"
|
|
|
|
|
|
def mirrored_images(repo_root: Path) -> dict[tuple[str, str], str]:
|
|
"""Return ``{(source_file, service): mirror reference}`` for every runner image.
|
|
|
|
Args:
|
|
repo_root: repository root the runner images are declared under.
|
|
"""
|
|
coordinates = ghcr_coordinates()
|
|
if coordinates is None:
|
|
raise RuntimeError("the GHCR mirror namespace is not resolvable")
|
|
provider = GHCRProvider(*coordinates, os.environ["INFINITO_GHCR_MIRROR_PREFIX"])
|
|
return {
|
|
(
|
|
image.source_file,
|
|
image.service,
|
|
): f"{provider.image_base(image)}:{image.version}"
|
|
for image in iter_runner_images(repo_root)
|
|
}
|
|
|
|
|
|
def write_override(repo_root: Path, layered: list[str]) -> str:
|
|
"""Write the compose override that swaps the runner's images for mirrors.
|
|
|
|
Args:
|
|
repo_root: repository root the compose files are relative to.
|
|
layered: compose files the stack is built from. Only their services
|
|
are overridden, so the override never adds a service of its own.
|
|
|
|
Returns:
|
|
The override path relative to ``repo_root``.
|
|
"""
|
|
services = {
|
|
service: {"image": reference}
|
|
for (source_file, service), reference in mirrored_images(repo_root).items()
|
|
if source_file in layered
|
|
}
|
|
target = repo_root / OVERRIDE
|
|
staging = target.with_name(f"{target.name}.{os.getpid()}")
|
|
dump_yaml(staging, {"services": services})
|
|
staging.replace(target)
|
|
return OVERRIDE
|
|
|
|
|
|
def env_image(repo_root: Path, key: str) -> str:
|
|
"""Return the mirror reference for an image ``default.env`` declares.
|
|
|
|
Args:
|
|
repo_root: repository root holding ``default.env``.
|
|
key: the ``default.env`` key naming the image.
|
|
"""
|
|
return mirrored_images(repo_root)[("default.env", key)]
|