mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-08 11:46:35 +00:00
Follow-up to d002796a5. The formula `infinito_nexus_${INFINITO_DISTRO}` is
now defined in exactly one place — `scripts/meta/env/defaults.sh:18`,
exported outside the load-once guard so it tracks INFINITO_DISTRO across
matrix iterations (caller re-sources defaults.sh after distro changes).
Every other site reads INFINITO_CONTAINER strictly from env; nothing
re-derives the formula, no lazy/colon-dash fallbacks, no per-call defaults.
Production code aligned:
- cli/deploy/development/common.py: add resolve_container() (strict env
reader, raises SystemExit on unset). make_compose() calls it as an
early-fail guard so a missing defaults.sh source surfaces here instead
of as a confusing compose.yml interpolation error later.
- cli/deploy/development/deploy.py: stop re-deriving from compose.distro;
use resolve_container().
- compose.yml: container_name reads ${INFINITO_CONTAINER:?...} strictly,
so callers that bypass defaults.sh fail fast with a clear hint.
- scripts/meta/resolve/image/local.sh: drop ${INFINITO_DISTRO:-debian}
fallback; require INFINITO_DISTRO via :? error.
- scripts/tests/deploy/ci/dedicated.sh: drop local _container fallback.
- scripts/tests/deploy/local/deploy/fresh-kept-app.sh: drop redundant
${INFINITO_DISTRO:-debian} reassignment after sourcing env/all.sh
(defaults.sh already defaults the value).
- scripts/tests/deploy/local/deploy/fresh-purged-app.sh: drop
target_container fallback; INFINITO_CONTAINER is already in env.
- scripts/tests/deploy/local/exec/container.sh: drop the lazy
${INFINITO_CONTAINER:=infinito_nexus_...} default; defaults.sh source
in env/all.sh already guarantees the value.
- scripts/tests/dns.sh: source defaults.sh so callers only need to set
INFINITO_DISTRO (the implicit dependency was previously a footgun).
- scripts/system/tls/trust/{wsl2,linux}.sh: same — source defaults.sh,
drop the ${INFINITO_CONTAINER:-infinito_nexus_debian} fallback in
linux.sh.
- .github/workflows/test-dns.yml: drop redundant
INFINITO_CONTAINER: infinito_nexus_${{ matrix.distro }} from per-step
env blocks (3 sites). The env now flows from INFINITO_DISTRO via the
defaults.sh sourced inside the scripts.
- tests/unit/cli/deploy/development/test_matrix_deploy.py: replace the
module-level os.environ.setdefault('INFINITO_CONTAINER', 'infinito_nexus_arch')
shim — which itself encoded the formula — with a module-level patch of
resolve_container that returns an opaque test-fixture string. Drop the
now-unused distro="arch" field from the _args() Namespace fixture
(deploy.handler stopped consuming it after the --distro arg removal).
Documentation aligned:
- docs/contributing/environment/variables.md: rewrite the INFINITO_CONTAINER
row to spell out the SPOT contract — set automatically by defaults.sh,
never re-derived elsewhere, callers re-source defaults.sh after
changing INFINITO_DISTRO mid-process.
- docs/contributing/artefact/files/compose.yml.md: replace the
INFINITO_DISTRO row (which described the now-removed
`infinito_nexus_${INFINITO_DISTRO:-debian}` interpolation) with an
INFINITO_CONTAINER row noting the strict ${INFINITO_CONTAINER:?...} read.
Verified:
- Formula derivation: 1 production hit (the SPOT in defaults.sh:18).
- INFINITO_CONTAINER fallback patterns (:-/:=): 0.
- --distro CLI arg refs: 0 (one comment explaining the removal).
- make test green: 1553 unit + 168 integration tests, no skipped suites.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
101 lines
3.7 KiB
Python
101 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:
|
|
# Import only for type checking to avoid runtime import cycles.
|
|
from .compose import Compose
|
|
|
|
|
|
# SPOT: canonical repo-relative path to the development vars file that
|
|
# `infinito create inventory --vars-file <...>` consumes. Mirrors
|
|
# `INVENTORY_VARS_FILE` from scripts/meta/env/inventory.sh; the bash file
|
|
# is the SPOT-of-record for callers that go through the deploy chain
|
|
# (env is set before Python runs), and the literal here is the fallback
|
|
# for direct/test invocations that bypass that chain. A unit test locks
|
|
# both literals together so they cannot silently 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:
|
|
# <repo>/cli/deploy/development/common.py -> parents[3] == <repo>
|
|
return Path(__file__).resolve().parents[3]
|
|
|
|
|
|
def resolve_distro() -> str:
|
|
"""Return the current INFINITO_DISTRO. Single SPOT for the value.
|
|
|
|
The env var is the only input — all CLI subcommands rely on it
|
|
(callers source `scripts/meta/env/defaults.sh` before invocation).
|
|
Raises SystemExit when unset or invalid so a missing setup never
|
|
silently picks the wrong distro.
|
|
"""
|
|
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 the current INFINITO_CONTAINER. Single SPOT for the value.
|
|
|
|
The env var is kept in lock-step with INFINITO_DISTRO by
|
|
`scripts/meta/env/defaults.sh` (always-derived block outside its
|
|
load-once guard); callers that change INFINITO_DISTRO MUST re-source
|
|
defaults.sh so this stays consistent. Raises SystemExit when unset
|
|
so a missing setup never silently exec's the wrong container.
|
|
"""
|
|
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()
|
|
# Early-fail guard so a missing scripts/meta/env/defaults.sh source
|
|
# surfaces here instead of as a confusing
|
|
# `compose.yml: required variable INFINITO_CONTAINER missing` later.
|
|
# The two env vars must travel together; defaults.sh keeps them in sync.
|
|
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
|