mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-10 04:36:40 +00:00
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>
107 lines
2.9 KiB
Python
107 lines
2.9 KiB
Python
"""
|
|
Resolve and aggregate role groups (apps) from one or more inventory bundles.
|
|
|
|
Bundles live under ``inventories/bundles/{servers,workstations}/<name>/inventory.yml``.
|
|
Each bundle declares the role groups it activates beneath ``all.children``.
|
|
|
|
Invoked from ``scripts/tests/deploy/local/deploy/bundles.sh`` to feed INFINITO_APPS into
|
|
the existing fresh-purged deploy flow:
|
|
|
|
python -m utils.inventory.bundle_apps education-suite,startup-essentials
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import sys
|
|
from typing import TYPE_CHECKING
|
|
|
|
from utils import PROJECT_ROOT
|
|
from utils.cache.yaml import load_yaml
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import Iterable
|
|
from pathlib import Path
|
|
|
|
SEARCH_DIRS = (
|
|
PROJECT_ROOT / "inventories" / "bundles" / "servers",
|
|
PROJECT_ROOT / "inventories" / "bundles" / "workstations",
|
|
)
|
|
|
|
|
|
def _split_csv(raw: str) -> list[str]:
|
|
return [item.strip() for item in raw.split(",") if item.strip()]
|
|
|
|
|
|
def _locate(bundle: str) -> Path | None:
|
|
for base in SEARCH_DIRS:
|
|
candidate = base / bundle / "inventory.yml"
|
|
if candidate.is_file():
|
|
return candidate
|
|
return None
|
|
|
|
|
|
def resolve(bundles: Iterable[str]) -> list[str]:
|
|
"""Return deduplicated role-group names from the given bundle inventories.
|
|
|
|
Raises FileNotFoundError if any bundle is missing.
|
|
"""
|
|
apps: list[str] = []
|
|
seen: set[str] = set()
|
|
missing: list[str] = []
|
|
|
|
for bundle in bundles:
|
|
inventory = _locate(bundle)
|
|
if inventory is None:
|
|
missing.append(bundle)
|
|
continue
|
|
data = load_yaml(inventory, default_if_missing={}) or {}
|
|
children = (data.get("all") or {}).get("children") or {}
|
|
for app in children:
|
|
if app in seen:
|
|
continue
|
|
seen.add(app)
|
|
apps.append(app)
|
|
|
|
if missing:
|
|
raise FileNotFoundError(
|
|
"bundle(s) not found under inventories/bundles/"
|
|
"{servers,workstations}: " + ", ".join(missing)
|
|
)
|
|
|
|
return apps
|
|
|
|
|
|
def main(argv: list[str] | None = None) -> int:
|
|
parser = argparse.ArgumentParser(
|
|
prog="utils.inventory.bundle_apps",
|
|
description="Aggregate role groups from inventory bundles into a CSV.",
|
|
)
|
|
parser.add_argument(
|
|
"bundles",
|
|
help="Comma-separated bundle names (e.g. education-suite,startup-essentials).",
|
|
)
|
|
args = parser.parse_args(argv)
|
|
|
|
names = _split_csv(args.bundles)
|
|
if not names:
|
|
sys.stderr.write("ERROR: no bundle names provided\n")
|
|
return 2
|
|
|
|
try:
|
|
apps = resolve(names)
|
|
except FileNotFoundError as exc:
|
|
sys.stderr.write(f"ERROR: {exc}\n")
|
|
return 2
|
|
|
|
if not apps:
|
|
sys.stderr.write("ERROR: no role groups resolved from bundles\n")
|
|
return 2
|
|
|
|
sys.stdout.write(",".join(apps) + "\n")
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
sys.exit(main())
|