mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-08 03:38:23 +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>
64 lines
2.0 KiB
Python
64 lines
2.0 KiB
Python
from __future__ import annotations
|
|
|
|
import argparse
|
|
import os
|
|
|
|
from .common import make_compose
|
|
|
|
|
|
def add_parser(sub: argparse._SubParsersAction) -> None:
|
|
p = sub.add_parser("exec", help="Execute a command inside the infinito container.")
|
|
p.add_argument(
|
|
"--env",
|
|
action="append",
|
|
default=[],
|
|
metavar="KEY=VALUE",
|
|
help=(
|
|
"Inject KEY=VALUE into the container environment for this "
|
|
"exec call. Repeatable. Lets bash callers pass per-run "
|
|
"context (INFINITO_INVENTORY_FILE, INFINITO_APPS, ...) into in-container "
|
|
"helper scripts without inlining heredocs."
|
|
),
|
|
)
|
|
p.add_argument(
|
|
"cmd",
|
|
nargs=argparse.REMAINDER,
|
|
help="Command to execute (use `--` to separate).",
|
|
)
|
|
p.set_defaults(_handler=handler)
|
|
|
|
|
|
def _parse_env_pairs(pairs: list[str]) -> dict[str, str]:
|
|
parsed: dict[str, str] = {}
|
|
for pair in pairs:
|
|
if "=" not in pair:
|
|
raise SystemExit(f"--env expects KEY=VALUE; got {pair!r} without '='")
|
|
key, value = pair.split("=", 1)
|
|
key = key.strip()
|
|
if not key:
|
|
raise SystemExit(f"--env KEY is empty in {pair!r}")
|
|
parsed[key] = value
|
|
return parsed
|
|
|
|
|
|
def handler(args: argparse.Namespace) -> int:
|
|
compose = make_compose()
|
|
|
|
cmd = list(args.cmd or [])
|
|
if cmd and cmd[0] == "--":
|
|
cmd = cmd[1:]
|
|
if not cmd:
|
|
raise SystemExit("exec requires a command (e.g. exec -- sh -lc 'whoami')")
|
|
|
|
extra_env: dict[str, str] = {}
|
|
services_disabled = os.environ.get("INFINITO_SERVICES_DISABLED", "")
|
|
if services_disabled:
|
|
extra_env["INFINITO_SERVICES_DISABLED"] = services_disabled
|
|
|
|
# Caller-supplied --env entries win over implicit ones (current convention
|
|
# in the dev CLI: explicit user input overrides implicit defaults).
|
|
extra_env.update(_parse_env_pairs(args.env or []))
|
|
|
|
r = compose.exec(cmd, check=False, extra_env=extra_env or None)
|
|
return int(r.returncode)
|