Files
computer-playbook/cli/administration/deploy/development/mirrors.py
T
kevinveenbirkenbachandClaude Opus 4.7 a77a570409 refactor(env): consolidate INFINITO_* namespace and centralize path/image SPOTs
Closes a stack of env-pipeline regressions left over from the recent
INFINITO_* namespace refactor by:

* DOMAIN_PRIMARY now reads INFINITO_DOMAIN strictly (was: legacy DOMAIN
  env var → defaulted to infinito.localhost, which never resolved
  because CoreDNS serves the INFINITO_DOMAIN value, infinito.example).
* group_vars/all/08_networks.yml IPs (ip4/ip6/dns) now read
  INFINITO_IP4 / INFINITO_IP6 / INFINITO_DNS_IP.
* PLAYWRIGHT_KEEP_ALL renamed to INFINITO_PLAYWRIGHT_KEEP end-to-end
  (env-builder, role default, run_one.yml docker exec, playwright.config.js,
  lint allowlist, docs anchor, CI workflow vars).
* PKGMGR_IMAGE renamed to INFINITO_PARENT_IMAGE; Dockerfile ARG drops
  the inline default so env/default.env is the only SPOT.
* INFINITO_SRC_DIR centralized: Dockerfile ARG (no default) + ENV;
  compose forwards it as build-arg, volume mount path, and container env;
  every Python CLI + shell helper + CI workflow now reads it strictly
  (os.environ[...] / "${INFINITO_SRC_DIR:?...}") instead of the literal
  /opt/src/infinito.
* New entries in env/default.env: INFINITO_IP6=::1, INFINITO_PARENT_IMAGE,
  INFINITO_PLAYWRIGHT_KEEP=false. All three propagated through
  utils/env/handlers/passthrough.STATIC_KEYS and (where consumed in the
  container) through compose.yml's environment block.

Validated end-to-end with `make test` (2360 tests across lint, lint-*,
test-lint, test-external, test-unit, test-integration).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-21 02:30:34 +02:00

91 lines
2.7 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 _require_bool_env(name: str) -> bool:
raw = _require_env(name)
if raw == "true":
return True
if raw == "false":
return False
raise RuntimeError(
f"Environment variable {name} must be 'true' or 'false', got {raw!r}"
)
def should_use_mirrors_on_ci() -> bool:
"""
Mirrors are enabled strictly based on INFINITO_RUNNING_ON_GITHUB.
"""
return _require_bool_env("INFINITO_RUNNING_ON_GITHUB")
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