mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-06 10:59:59 +00:00
3529 invalid comments in 528 files, grandfathered in while the linter only saw the working-tree diff. Removal ran through the linter's own collectors, so detection and deletion cannot drift: a comment whose opener line is blank before it and whose closer line is blank after it loses all its lines, anything else loses only the comment region, and a line left holding a bare delimiter goes with it. Five files keep their comments behind a nocheck marker instead. Four are upstream configs whose inline docs are upstream's own (mautrix, systemd journald, nextcloud-oidc-login, MediaWiki). In littlejs the commented-out entries ARE the deactivation mechanism for an example tile, so deleting them would delete configuration. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
88 lines
3.2 KiB
Python
88 lines
3.2 KiB
Python
"""Central "engine" dependencies (cache / queue / search / vector / DNS resolver).
|
|
|
|
A role may consume an engine either *embedded* (a sidecar inside its own stack) or
|
|
*central* (a single pinned ``svc-db-*`` / ``svc-dns-*`` stack shared by many roles),
|
|
selected per consumer with the ``shared`` flag exactly like the RDBMS
|
|
(postgres / mariadb) pattern in :mod:`utils.roles.applications.services.database`.
|
|
|
|
See ``docs/architecture/central-engines.md`` for the rationale (engine on-disk state
|
|
cannot live on NFS, so centralising it keeps the application roles unpinned and
|
|
NFS-shareable in swarm).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING, Any
|
|
|
|
if TYPE_CHECKING:
|
|
from collections.abc import Mapping
|
|
|
|
ENGINES: dict[str, dict[str, Any]] = {
|
|
"redis": {"svc": "svc-db-redis", "port": 6379, "isolation": "acl"},
|
|
"memcached": {"svc": "svc-db-memcached", "port": 11211, "isolation": "prefix"},
|
|
"rabbitmq": {"svc": "svc-db-rabbitmq", "port": 5672, "isolation": "vhost"},
|
|
"elasticsearch": {
|
|
"svc": "svc-db-elasticsearch",
|
|
"port": 9200,
|
|
"isolation": "index",
|
|
},
|
|
"typesense": {"svc": "svc-db-typesense", "port": 8108, "isolation": "apikey"},
|
|
"qdrant": {"svc": "svc-db-qdrant", "port": 6333, "isolation": "collection"},
|
|
"unbound": {"svc": "svc-dns-unbound", "port": 53, "isolation": "none"},
|
|
}
|
|
|
|
ENGINE_KEYS = tuple(ENGINES)
|
|
|
|
|
|
def _as_mapping(value: Any) -> dict[str, Any]:
|
|
return value if isinstance(value, dict) else {}
|
|
|
|
|
|
def get_services(
|
|
applications: Mapping[str, Any], application_id: str
|
|
) -> dict[str, Any]:
|
|
return _as_mapping(_as_mapping(applications.get(application_id)).get("services"))
|
|
|
|
|
|
def engine_service(
|
|
applications: Mapping[str, Any], application_id: str, engine: str
|
|
) -> dict[str, Any]:
|
|
"""The consumer's ``services.<engine>`` block (or empty)."""
|
|
return _as_mapping(get_services(applications, application_id).get(engine))
|
|
|
|
|
|
def is_engine_enabled(
|
|
applications: Mapping[str, Any], application_id: str, engine: str
|
|
) -> bool:
|
|
return bool(engine_service(applications, application_id, engine).get("enabled"))
|
|
|
|
|
|
def is_engine_shared(
|
|
applications: Mapping[str, Any], application_id: str, engine: str
|
|
) -> bool:
|
|
"""Consumer wants the central instance (``enabled`` and ``shared``)."""
|
|
svc = engine_service(applications, application_id, engine)
|
|
return bool(svc.get("enabled")) and bool(svc.get("shared"))
|
|
|
|
|
|
def is_engine_embedded(
|
|
applications: Mapping[str, Any], application_id: str, engine: str
|
|
) -> bool:
|
|
"""Consumer wants an embedded sidecar (``enabled`` and not ``shared``)."""
|
|
svc = engine_service(applications, application_id, engine)
|
|
return bool(svc.get("enabled")) and not bool(svc.get("shared"))
|
|
|
|
|
|
def central_consumers(applications: Mapping[str, Any], engine: str) -> list[str]:
|
|
"""Roles consuming ``engine`` as ``shared: true`` -- drives on-demand enable of
|
|
the central engine stack (deploy it only when at least one role needs it)."""
|
|
return sorted(
|
|
application_id
|
|
for application_id in applications
|
|
if is_engine_shared(applications, application_id, engine)
|
|
)
|
|
|
|
|
|
def central_engine_needed(applications: Mapping[str, Any], engine: str) -> bool:
|
|
return bool(central_consumers(applications, engine))
|