mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-08 03:38:23 +00:00
Extend the local cache stack with three independent capabilities: 1. Inner-`dockerd` build coverage for HTTP-only package mirrors. `roles/sys-svc-compose/files/compose.py` (the runner's `compose` wrapper) auto-generates a transient `compose.cache.override.yml` per app when `INFINITO_PACKAGE_CACHE_FRONTEND_IP` is exported. The override pins `build.extra_hosts` for `deb.debian.org`, `archive.ubuntu.com`, and `security.ubuntu.com` to the frontend. `pull.py` now delegates to the wrapper so build/pull operations see the same `-f` set the wrapper auto-detects. nginx in the frontend gains a port-80 listener with path rewrites for those hostnames, and `package.sh` registers two new Nexus proxies (`apt-debian-security`, `apt-ubuntu-security`) for the security suites whose upstream URL prefix differs from the main archive. Alpine is intentionally excluded from the inner-build extra_hosts: 3.18+ defaults to HTTPS, and inner-`dockerd` build containers do not import the frontend CA. Routing apk through the frontend would trip TLS verification. 2. General cache freshness env-var. `scripts/meta/env/cache/package.sh` exports `INFINITO_PACKAGE_CACHE_MAX_AGE_MIN` (default `129600`, i.e. 90 days). The bootstrap helper consumes it for every Nexus proxy's `contentMaxAge`, `metadataMaxAge`, and `negativeCache.timeToLive`, replacing the previous 1440-minute literal. Lower the value when chasing fast-moving upstreams. 3. SPOT cache documentation at `docs/contributing/environment/cache.md`. `compose.yml.md`, `variables.md`, the per-service READMEs, and `requirements/012-...` now link to it instead of restating the stack's behaviour. Net documentation lines drop substantially while the cache page becomes the single user-facing reference. Also: code-comment cleanup per `docs/contributing/documentation.md` guidelines across all touched .py / .sh / .yml files. Multi-paragraph docstrings, banner separators, and restate-the-obvious comments are removed; one-line WHY comments remain where the rationale is not already visible in the code. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
111 lines
3.7 KiB
Python
111 lines
3.7 KiB
Python
from __future__ import annotations
|
|
|
|
import os
|
|
from pathlib import Path
|
|
from typing import TYPE_CHECKING
|
|
|
|
from .deps import apps_with_deps, resolve_run_after
|
|
|
|
if TYPE_CHECKING:
|
|
from .compose import Compose
|
|
|
|
|
|
# Mirrors INVENTORY_VARS_FILE from scripts/meta/env/inventory.sh; a unit
|
|
# test locks the two literals together so they cannot drift.
|
|
DEV_INVENTORY_VARS_FILE: str = os.environ.get(
|
|
"INVENTORY_VARS_FILE", "inventories/development/default.yml"
|
|
)
|
|
|
|
|
|
VALID_DISTROS: tuple[str, ...] = ("arch", "debian", "ubuntu", "fedora", "centos")
|
|
|
|
|
|
def repo_root_from_here() -> Path:
|
|
return Path(__file__).resolve().parents[3]
|
|
|
|
|
|
def compose_file_args() -> list[str]:
|
|
"""Compose `-f` flags shared by up and down flows."""
|
|
from .profile import Profile
|
|
|
|
out = ["-f", "compose.yml"]
|
|
if Profile().registry_cache_active():
|
|
out += ["-f", "compose/cache.override.yml"]
|
|
return out
|
|
|
|
|
|
def cache_env_overrides() -> dict[str, str]:
|
|
"""Env vars consumed strictly by compose/cache.override.yml."""
|
|
from .profile import Profile
|
|
|
|
if not Profile().registry_cache_active():
|
|
return {}
|
|
|
|
ca_dir = os.environ.get("INFINITO_PACKAGE_CACHE_FRONTEND_CA_DIR", "").strip()
|
|
if not ca_dir:
|
|
raise SystemExit(
|
|
"INFINITO_PACKAGE_CACHE_FRONTEND_CA_DIR is not set. Source "
|
|
"scripts/meta/env/cache/package.sh (or scripts/meta/env/all.sh) "
|
|
"before invoking cli.deploy.development."
|
|
)
|
|
return {
|
|
"INFINITO_REGISTRY_CACHE_PROXY_CONF": "./compose/registry-cache/proxy.conf",
|
|
"INFINITO_PACKAGE_CACHE_PIP_CONF": "./compose/package-cache/pip.conf",
|
|
"INFINITO_PACKAGE_CACHE_NPMRC": "./compose/package-cache/npmrc",
|
|
"INFINITO_PACKAGE_CACHE_APT_LIST": "./compose/package-cache/apt.list",
|
|
"INFINITO_PACKAGE_CACHE_FRONTEND_CA_FILE": f"{ca_dir}/ca.crt",
|
|
}
|
|
|
|
|
|
def resolve_distro() -> str:
|
|
"""Return INFINITO_DISTRO; raise SystemExit if missing or invalid."""
|
|
distro = os.environ.get("INFINITO_DISTRO", "").strip()
|
|
if not distro:
|
|
raise SystemExit(
|
|
"INFINITO_DISTRO is not set. Source scripts/meta/env/defaults.sh "
|
|
"or export INFINITO_DISTRO=<arch|debian|ubuntu|fedora|centos> "
|
|
"before invoking cli.deploy.development."
|
|
)
|
|
if distro not in VALID_DISTROS:
|
|
raise SystemExit(
|
|
f"INFINITO_DISTRO={distro!r} is not a valid distro. "
|
|
f"Valid: {', '.join(VALID_DISTROS)}."
|
|
)
|
|
return distro
|
|
|
|
|
|
def resolve_container() -> str:
|
|
"""Return INFINITO_CONTAINER; raise SystemExit if unset."""
|
|
container = os.environ.get("INFINITO_CONTAINER", "").strip()
|
|
if not container:
|
|
raise SystemExit(
|
|
"INFINITO_CONTAINER is not set. Source scripts/meta/env/defaults.sh "
|
|
"before invoking cli.deploy.development."
|
|
)
|
|
return container
|
|
|
|
|
|
def make_compose() -> Compose:
|
|
from .compose import Compose
|
|
|
|
distro = resolve_distro()
|
|
# Surface env-script gap here rather than as a cryptic compose error later.
|
|
resolve_container()
|
|
return Compose(repo_root=repo_root_from_here(), distro=distro)
|
|
|
|
|
|
def resolve_deploy_ids_for_app(compose: Compose, app_id: str) -> list[str]:
|
|
deps = resolve_run_after(compose, app_id)
|
|
return apps_with_deps(app_id, deps_role_names=deps)
|
|
|
|
|
|
def resolve_deploy_ids_for_apps(compose: Compose, app_spec: str) -> list[str]:
|
|
"""Resolve deploy ids for one or more space- or comma-separated app ids."""
|
|
app_ids = [a.strip() for a in app_spec.replace(",", " ").split() if a.strip()]
|
|
result: list[str] = []
|
|
for app_id in app_ids:
|
|
for dep in resolve_deploy_ids_for_app(compose, app_id):
|
|
if dep not in result:
|
|
result.append(dep)
|
|
return result
|