Files
computer-playbook/cli/administration/deploy/development/common.py
T
kevinveenbirkenbachandClaude Opus 4.7 9a578952c3 feat(env): SPOT env-pipeline + INFINITO_* namespace
Replace 8 bash env modules with a single Python generator
(cli.meta.env) that materialises env/static.env + runtime context
into a gitignored .env. Each variable lives in its own handler
under utils/env/handlers/; defaults carry inline one-line `# ...`
comments.

Rename to the INFINITO_* schema:
- workflow inputs: APPS, SERVICES_DISABLED, CMD, DEBUG, WHITELIST,
  BUNDLES, FULL_CYCLE, VARIANT, RUN_FLAGS, LIMIT_HOST, PARALLEL
- inventory: INVENTORY_DIR / INVENTORY_FILE / HOST_VARS_FILE,
  PW_FILE -> INVENTORY_PASSWORD_FILE
- venv: VENV_BASE / VENV_FALLBACK / VENV_NAME
- new SPOT defaults: COMPILE_SILENCE, CONTAINER_NO_CA,
  WAIT_HEALTH_TIMEOUT_S, PACKAGE_CACHE_FRONTEND_INIT_IMAGE,
  promoted IMAGE_TAG from GHA-only to general passthrough

compose.yml hardening:
- inline \${VAR:-default} removed; strict \${VAR:?...} everywhere
- new integration lint blocks regressions

Tooling:
- scripts/install/all.sh owns the stamp-file install logic
  (Makefile target delegates)
- scripts/meta/env/load.sh is the single shell entry point;
  8 bash modules deleted
- new shell lint: no INFINITO_* defaults outside env/static.env

Tests:
- 93 new unit tests for utils/env/{builder,parser,runtime,writer}
- restructure tests/lint into repository/ (file-content rules) vs
  filesystem/{shell,python,env}/ (filesystem-shape rules)
- drift + smoke integration tests against the generator

Docs:
- variables.md is now a pointer; per-variable docs live next to
  the key in env/static.env / env/ci.env
- compose.yml.md drops the Default column

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

107 lines
3.7 KiB
Python

from __future__ import annotations
import os
from typing import TYPE_CHECKING
from . import PROJECT_ROOT
from .deps import apps_with_deps, resolve_run_after
if TYPE_CHECKING:
from .compose import Compose
# Mirrors INVENTORY_VARS_FILE from scripts/meta/env/load.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 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. Run "
"'make dotenv' (or source scripts/meta/env/load.sh) before "
"invoking cli.administration.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. Run 'make dotenv' (or source scripts/meta/env/load.sh) "
"or export INFINITO_DISTRO=<arch|debian|ubuntu|fedora|centos> "
"before invoking cli.administration.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. Run 'make dotenv' (or source scripts/meta/env/load.sh) "
"before invoking cli.administration.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=PROJECT_ROOT, 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