mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 10:59:59 +00:00
One boolean answered five unrelated questions: whether the pull-through cache stack runs, whether image pulls take the GHCR mirror, whether the docker data root may be wiped, plus runtime naming and inventory resolution. The workspace is the environment where those answers diverge — it simulates a developer machine on a real runner — so getting one of them meant misreporting where the suite runs and silently paying for the other four.
is_ci() and runs_on_github() stay facts about the machine. cache_stack_enabled, image_mirror_enabled and docker_root_ephemeral become decisions that default off those facts and can be declared explicitly, so an environment states what it wants. Every default reproduces the previous condition exactly, including the distinction the old mirror and wipe gates drew between a real runner and act.
73ae40585 got the cache stack by flipping the identity flag and lost the docker-root wipe with it; the workspace now declares all three capabilities instead. Pairs with 4c068d1cf, which makes the resulting stray bind sources harmless rather than fatal.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
82 lines
2.5 KiB
Python
82 lines
2.5 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
import shlex
|
|
from pathlib import Path
|
|
|
|
CONTAINER_REPO_ROOT = Path(os.environ["INFINITO_SRC_DIR"])
|
|
|
|
|
|
def _require_env(name: str) -> str:
|
|
val = os.environ.get(name)
|
|
if val is None or not str(val).strip():
|
|
raise RuntimeError(f"Required environment variable is missing or empty: {name}")
|
|
return str(val).strip()
|
|
|
|
|
|
def should_use_mirrors() -> bool:
|
|
"""True iff image references should be rewritten to the GHCR mirror."""
|
|
from .profile import Profile
|
|
|
|
return Profile().image_mirror_enabled()
|
|
|
|
|
|
def _exec_env() -> dict[str, str]:
|
|
"""
|
|
All variables are mandatory. No fallbacks.
|
|
"""
|
|
return {
|
|
"INFINITO_RUNNING_ON_GITHUB": _require_env("INFINITO_RUNNING_ON_GITHUB"),
|
|
"GITHUB_REPOSITORY_OWNER": _require_env("GITHUB_REPOSITORY_OWNER"),
|
|
"GITHUB_REPOSITORY": _require_env("GITHUB_REPOSITORY"),
|
|
"INFINITO_GHCR_MIRROR_PREFIX": _require_env("INFINITO_GHCR_MIRROR_PREFIX"),
|
|
}
|
|
|
|
|
|
def generate_ci_mirrors_file(compose, *, inventory_dir: str) -> str:
|
|
"""
|
|
Generate mirrors.yml inside the container using cli.contributing.mirror.resolver.
|
|
|
|
Writes:
|
|
<inventory_dir>/mirrors.yml
|
|
"""
|
|
inv_root = str(inventory_dir).rstrip("/")
|
|
if not inv_root:
|
|
raise RuntimeError("inventory_dir must not be empty")
|
|
|
|
env = _exec_env()
|
|
ghcr_namespace = env["GITHUB_REPOSITORY_OWNER"].lower()
|
|
ghcr_repository = env["GITHUB_REPOSITORY"].split("/", 1)[-1].lower()
|
|
ghcr_prefix = env["INFINITO_GHCR_MIRROR_PREFIX"].strip().strip("/")
|
|
if not ghcr_prefix:
|
|
raise RuntimeError("INFINITO_GHCR_MIRROR_PREFIX must not be empty")
|
|
|
|
mirrors_path = f"{inv_root}/mirrors.yml"
|
|
repo_root = str(CONTAINER_REPO_ROOT)
|
|
|
|
cmd = [
|
|
"bash",
|
|
"-lc",
|
|
(
|
|
"set -euo pipefail; "
|
|
f"mkdir -p {shlex.quote(inv_root)}; "
|
|
'"${PYTHON:-python3}" -m cli.contributing.mirror.resolver '
|
|
f"--repo-root {shlex.quote(repo_root)} "
|
|
f"--ghcr-namespace {shlex.quote(ghcr_namespace)} "
|
|
f"--ghcr-repository {shlex.quote(ghcr_repository)} "
|
|
f"--ghcr-prefix {shlex.quote(ghcr_prefix)} "
|
|
f"> {shlex.quote(mirrors_path)}; "
|
|
f"echo '[init] mirrors generated:' {shlex.quote(mirrors_path)}; "
|
|
f"wc -l {shlex.quote(mirrors_path)}"
|
|
),
|
|
]
|
|
|
|
compose.exec(
|
|
cmd,
|
|
check=True,
|
|
workdir=repo_root,
|
|
extra_env=env,
|
|
)
|
|
|
|
return mirrors_path
|