mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-07 19:32:17 +00:00
One module per concern, mirroring the inventory/ subpackage layout: run.py (single deploy pass + env forwarding SPOT), drill.py (recover drill, host mode exempt, paths from CONTAINER_REPO_ROOT instead of a hardcoded /opt/src/infinito), purge.py (inter-round cleanup) and cli.py (arg parsing + round/pass loop, PASS 1/2 deduplicated). Also extend the comment linter to flag bare string-expression statements outside docstring position in Python: a triple-quoted literal floating in a body is a comment in disguise and now runs through the same validity rules; docstrings and PEP 224 attribute docstrings stay allowed. Test narration comments moved into method docstrings accordingly, and the design docs now link deploy/cli.py. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
94 lines
2.2 KiB
Python
94 lines
2.2 KiB
Python
"""Execute one deploy pass inside the infinito container.
|
|
|
|
:func:`_run_deploy` is the SPOT for how a single
|
|
``cli.administration.deploy.dedicated`` invocation is assembled: the
|
|
inventory/password file layout, the ansible CLI flags, the ``-e`` var
|
|
encoding, and which host environment variables are forwarded into the
|
|
container.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import os
|
|
from typing import TYPE_CHECKING, Any
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import Mapping
|
|
|
|
_FORWARDED_ENV_KEYS = (
|
|
"GH_TOKEN",
|
|
"GITHUB_TOKEN",
|
|
"GITHUB_REPOSITORY_OWNER",
|
|
"GITHUB_REPOSITORY",
|
|
"INFINITO_IMAGE_TAG",
|
|
"INFINITO_GHCR_MIRROR_PREFIX",
|
|
)
|
|
|
|
|
|
def _run_deploy(
|
|
compose,
|
|
*,
|
|
deploy_ids: list[str],
|
|
debug: bool,
|
|
passthrough: list[str],
|
|
inventory_dir: str,
|
|
container_name: str,
|
|
extra_ansible_vars: Mapping[str, Any] | None = None,
|
|
) -> int:
|
|
inv_root = str(inventory_dir).rstrip("/")
|
|
inv_file = f"{inv_root}/devices.yml"
|
|
pw_file = f"{inv_root}/.password"
|
|
|
|
cmd = [
|
|
"python3",
|
|
"-m",
|
|
"cli.administration.deploy.dedicated",
|
|
inv_file,
|
|
"-p",
|
|
pw_file,
|
|
"-vv",
|
|
"--assert",
|
|
"true",
|
|
"--diff",
|
|
"--id",
|
|
*deploy_ids,
|
|
]
|
|
if debug:
|
|
cmd.insert(cmd.index("--diff") + 1, "--debug")
|
|
|
|
if extra_ansible_vars:
|
|
for key, value in extra_ansible_vars.items():
|
|
cmd.extend(["-e", f"{key}={json.dumps(value)}"])
|
|
|
|
if passthrough:
|
|
cmd.extend(passthrough)
|
|
|
|
extra_env: dict[str, str] = {
|
|
"ANSIBLE_FORCE_COLOR": "1",
|
|
"PY_COLORS": "1",
|
|
"TERM": "xterm-256color",
|
|
}
|
|
services_disabled = os.environ.get("disable", "")
|
|
if services_disabled:
|
|
extra_env["disable"] = services_disabled
|
|
|
|
ansible_log_path = (
|
|
os.environ.get("ANSIBLE_LOG_PATH") or "/tmp/infinito-deploy.log" # noqa: S108 - fixed fallback log path inside the ephemeral CI container
|
|
)
|
|
extra_env["ANSIBLE_LOG_PATH"] = ansible_log_path
|
|
|
|
for key in _FORWARDED_ENV_KEYS:
|
|
val = os.environ.get(key)
|
|
if val:
|
|
extra_env[key] = val
|
|
|
|
r = compose.exec(
|
|
cmd,
|
|
check=False,
|
|
live=True,
|
|
extra_env=extra_env,
|
|
)
|
|
|
|
return int(r.returncode)
|