Run the containers with the systemd configuration, 1:1

The containers now read the unchanged .env of the matching systemd instance
(/home/llmadmin/mindnet_dev/.env, /home/llmadmin/mindnet/.env) and use the
same Qdrant, Ollama, vault and collection prefix, so both can be compared
side by side. Only container-specific values are overridden: host service
addresses (host.docker.internal instead of 127.0.0.1) and the read-only vault.

- deploy/appenv.py derives the vault mount and prefix from that .env and
  rejects application keys in the container-only file.
- Remove the separate dev Qdrant, the synthetic test vault and the import step.
- UI binds 0.0.0.0 like systemd; API stays loopback by default.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
LarsandClaude Opus 5.5 committed 2026-10-28 17:22:08 +01:00
1 parent eae30775e3
commit 6cdad8b046
20 files changed
+373 -415

No files matched your search

+96
View File
@@ -0,0 +1,96 @@
"""
FILE: deploy/appenv.py
DESCRIPTION: Liest die unveränderte .env der systemd-Instanz und leitet daraus ab, was
Compose für denselben Betrieb im Container braucht:
- Vault: Host-Pfad und Einhängepunkt so, dass MINDNET_VAULT_ROOT der .env im
Container auf dasselbe Verzeichnis zeigt (relativ -> unter /app, wie unter
dem WorkingDirectory der systemd-Unit)
- erwartetes Collection-Präfix für den Smoke-Test
Prüft außerdem, dass die Container-Datei nur Container-Angaben enthält und
damit keine Anwendungskonfiguration überschreibt.
Nur Standardbibliothek (läuft direkt auf dem Runner).
VERSION: 1.0.0
STATUS: Active
USAGE: appenv.py <systemd.env> <container.env> -> Shell-Zuweisungen auf stdout
"""
from __future__ import annotations
import posixpath
import shlex
import sys
from pathlib import Path
# Einzige Schlüssel, die die Container-Datei setzen darf.
CONTAINER_KEYS = {
"MINDNET_API_PORT", "MINDNET_API_BIND", "MINDNET_UI_PORT", "MINDNET_UI_BIND",
"MINDNET_API_MEM_LIMIT", "MINDNET_UI_MEM_LIMIT", "MINDNET_ALLOW_CLOUD_EGRESS",
"MINDNET_VAULT_SENTINEL",
}
APP_WORKDIR = "/app"
DEFAULT_VAULT_ROOT = "./vault_master" # Default aus app/config.py
DEFAULT_PREFIX = "mindnet" # Default aus app/config.py
class AppEnvError(RuntimeError):
pass
def parse(path: str) -> dict[str, str]:
"""Einfacher dotenv-Parser (KEY=VALUE, optional 'export', Quotes, Kommentare)."""
values = {}
for raw in Path(path).read_text(encoding="utf-8").splitlines():
line = raw.strip()
if not line or line.startswith("#") or "=" not in line:
continue
if line.startswith("export "):
line = line[len("export "):].lstrip()
key, value = (part.strip() for part in line.split("=", 1))
if len(value) >= 2 and value[0] in "\"'" and value[-1] == value[0]:
value = value[1:-1]
elif " #" in value:
value = value.split(" #", 1)[0].rstrip()
values[key] = value
return values
def vault_mount(app_env_path: str, values: dict[str, str]) -> tuple[str, str]:
root = values.get("MINDNET_VAULT_ROOT") or DEFAULT_VAULT_ROOT
if posixpath.isabs(root):
return posixpath.normpath(root), posixpath.normpath(root)
# systemd startet im Ordner der .env (WorkingDirectory), der Container in /app.
host_dir = posixpath.dirname(Path(app_env_path).as_posix())
return posixpath.normpath(posixpath.join(host_dir, root)), posixpath.normpath(posixpath.join(APP_WORKDIR, root))
def derive(app_env_path: str, container_env_path: str) -> dict[str, str]:
extra = sorted(set(parse(container_env_path)) - CONTAINER_KEYS)
if extra:
raise AppEnvError(
f"{container_env_path} darf nur Container-Angaben enthalten; "
f"Anwendungswerte gehören in {app_env_path}: {', '.join(extra)}"
)
values = parse(app_env_path)
host, target = vault_mount(app_env_path, values)
return {
"MINDNET_VAULT_HOST_PATH": host,
"MINDNET_VAULT_TARGET": target,
"MINDNET_EXPECTED_PREFIX": values.get("COLLECTION_PREFIX") or DEFAULT_PREFIX,
}
def main(argv: list[str]) -> int:
if len(argv) != 3:
print("Aufruf: appenv.py <systemd.env> <container.env>", file=sys.stderr)
return 2
try:
derived = derive(argv[1], argv[2])
except (OSError, AppEnvError) as e:
print(f"appenv: {e}", file=sys.stderr)
return 1
for key, value in derived.items():
print(f"{key}={shlex.quote(value)}")
return 0
if __name__ == "__main__":
sys.exit(main(sys.argv))