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

+78
View File
@@ -0,0 +1,78 @@
"""
FILE: tests/test_container_appenv.py
DESCRIPTION: Prüft deploy/appenv.py: Aus der unveränderten .env der systemd-Instanz
werden Vault-Mount und Präfix so abgeleitet, dass der Container dieselbe
Konfiguration nutzt; die Container-Datei darf nichts davon überschreiben.
"""
import importlib.util
import shlex
from pathlib import Path
import pytest
DEPLOY = Path(__file__).resolve().parents[1] / "deploy"
_spec = importlib.util.spec_from_file_location("mindnet_appenv", DEPLOY / "appenv.py")
appenv = importlib.util.module_from_spec(_spec)
_spec.loader.exec_module(appenv)
APP_ENV = "/home/llmadmin/mindnet_dev/.env"
def _files(tmp_path, app_text, container_text="MINDNET_UI_PORT=8512\n"):
app = tmp_path / "app.env"
app.write_text(app_text, encoding="utf-8")
container = tmp_path / "container.env"
container.write_text(container_text, encoding="utf-8")
return str(app), str(container)
def test_parse_handles_export_quotes_and_comments(tmp_path):
app, _ = _files(tmp_path, '# Kommentar\nexport A=1\nB="mit # Raute"\nC=wert # Kommentar\nD=\n')
assert appenv.parse(app) == {"A": "1", "B": "mit # Raute", "C": "wert", "D": ""}
@pytest.mark.parametrize("root, host, target", [
("./vault", "/home/llmadmin/mindnet_dev/vault", "/app/vault"),
("vault_dev", "/home/llmadmin/mindnet_dev/vault_dev", "/app/vault_dev"),
("../shared/vault", "/home/llmadmin/shared/vault", "/shared/vault"),
("/mnt/nas/vault/", "/mnt/nas/vault", "/mnt/nas/vault"),
])
def test_vault_mount_points_where_the_app_looks(root, host, target):
# Relativ: systemd löst gegen WorkingDirectory (= Ordner der .env) auf, der Container gegen /app.
assert appenv.vault_mount(APP_ENV, {"MINDNET_VAULT_ROOT": root}) == (host, target)
def test_vault_mount_uses_app_default_when_unset():
assert appenv.vault_mount(APP_ENV, {}) == ("/home/llmadmin/mindnet_dev/vault_master", "/app/vault_master")
def test_derive_takes_prefix_from_systemd_env(tmp_path):
app, container = _files(tmp_path, "COLLECTION_PREFIX=mindnet_dev\nMINDNET_VAULT_ROOT=/srv/vault\n")
derived = appenv.derive(app, container)
assert derived["MINDNET_EXPECTED_PREFIX"] == "mindnet_dev"
assert derived["MINDNET_VAULT_HOST_PATH"] == derived["MINDNET_VAULT_TARGET"] == "/srv/vault"
def test_derive_falls_back_to_app_default_prefix(tmp_path):
app, container = _files(tmp_path, "MINDNET_VAULT_ROOT=/srv/vault\n")
assert appenv.derive(app, container)["MINDNET_EXPECTED_PREFIX"] == "mindnet"
@pytest.mark.parametrize("key", ["COLLECTION_PREFIX", "MINDNET_VAULT_ROOT", "OPENROUTER_API_KEY", "QDRANT_URL"])
def test_container_env_must_not_override_app_config(tmp_path, key):
app, container = _files(tmp_path, "COLLECTION_PREFIX=mindnet_dev\n", f"MINDNET_UI_PORT=8512\n{key}=x\n")
with pytest.raises(appenv.AppEnvError, match=key):
appenv.derive(app, container)
def test_main_prints_shell_safe_assignments(tmp_path, capsys):
app, container = _files(tmp_path, "COLLECTION_PREFIX=mindnet_dev\nMINDNET_VAULT_ROOT=/srv/my vault\n")
assert appenv.main(["appenv.py", app, container]) == 0
lines = capsys.readouterr().out.splitlines()
parsed = dict(shlex.split(line)[0].split("=", 1) for line in lines)
assert parsed["MINDNET_VAULT_HOST_PATH"] == "/srv/my vault"
def test_main_reports_missing_file(tmp_path, capsys):
assert appenv.main(["appenv.py", str(tmp_path / "fehlt.env"), str(tmp_path / "auch.env")]) == 1
assert "appenv:" in capsys.readouterr().err
+33 -34
View File
@@ -13,16 +13,18 @@ import yaml
ROOT = Path(__file__).resolve().parents[1]
DEPLOY = ROOT / "deploy"
SYSTEMD_PORTS = {8001, 8002, 8501, 8502}
# WorkingDirectory der systemd-Units (llm-node), deren .env der Container unverändert liest.
SYSTEMD_ENV_FILES = {"dev": "/home/llmadmin/mindnet_dev/.env", "prod": "/home/llmadmin/mindnet/.env"}
def _load_entrypoint():
spec = importlib.util.spec_from_file_location("mindnet_entrypoint", DEPLOY / "entrypoint.py")
def _load_deploy_module(name):
spec = importlib.util.spec_from_file_location(f"mindnet_{name}", DEPLOY / f"{name}.py")
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module)
return module
ep = _load_entrypoint()
ep = _load_deploy_module("entrypoint")
@pytest.fixture
@@ -189,26 +191,29 @@ def test_compose_app_services_hardened(envname):
@pytest.mark.parametrize("envname", ["dev", "prod"])
def test_compose_vault_is_read_only_bind_without_autocreate(envname):
mounts = [v for v in COMPOSE[envname]["services"]["api"]["volumes"]
if isinstance(v, dict) and v.get("target") == "/vault"]
if isinstance(v, dict) and v.get("type") == "bind"]
assert len(mounts) == 1
assert mounts[0]["target"].startswith("${MINDNET_VAULT_TARGET:?") # aus der systemd-.env abgeleitet
assert mounts[0]["read_only"] is True
assert mounts[0]["bind"]["create_host_path"] is False
assert all(":/vault" not in v for v in COMPOSE[envname]["services"]["ui"]["volumes"] if isinstance(v, str))
assert not [v for v in COMPOSE[envname]["services"]["ui"]["volumes"] if isinstance(v, dict)]
@pytest.mark.parametrize("envname", ["dev", "prod"])
def test_compose_api_only_on_loopback(envname):
assert all(p.startswith("127.0.0.1:") for p in COMPOSE[envname]["services"]["api"]["ports"])
def test_compose_api_defaults_to_loopback(envname):
assert all(p.startswith("${MINDNET_API_BIND:-127.0.0.1}:") for p in COMPOSE[envname]["services"]["api"]["ports"])
def test_prod_uses_existing_qdrant_and_dev_its_own():
assert "qdrant" not in COMPOSE["prod"]["services"]
dev_qdrant = COMPOSE["dev"]["services"]["qdrant"]
assert "@sha256:" in dev_qdrant["image"]
@pytest.mark.parametrize("envname", ["dev", "prod"])
def test_compose_uses_existing_host_services_and_app_config(envname):
# Wie systemd: gemeinsame Host-Qdrant und Host-Ollama; Präfix/Vault aus der systemd-.env.
assert set(COMPOSE[envname]["services"]) == set(APP_SERVICES)
for name in APP_SERVICES:
dev_env = COMPOSE["dev"]["services"][name]["environment"]
assert dev_env["QDRANT_URL"] == "http://qdrant:6333"
assert dev_env["COLLECTION_PREFIX"].endswith("_dev")
env = COMPOSE[envname]["services"][name]["environment"]
assert env["MINDNET_ENV"] == envname
assert env["QDRANT_URL"] == "http://host.docker.internal:6333"
assert env["MINDNET_OLLAMA_URL"] == "http://host.docker.internal:11434"
assert not {"COLLECTION_PREFIX", "MINDNET_VAULT_ROOT", "MINDNET_VOCAB_PATH"} & set(env)
def test_dockerfile_pinned_and_non_root():
@@ -235,10 +240,11 @@ def test_dockerignore_is_allowlist_without_env_files():
assert not any(l.startswith("!") and ("vault" in l or ".env" in l) for l in lines)
def test_prod_env_example_blocks_cloud_egress():
values = dict(l.split("=", 1) for l in (DEPLOY / "env" / "prod.env.example").read_text(encoding="utf-8").splitlines()
if "=" in l and not l.startswith("#"))
assert values["OPENROUTER_API_KEY"] == "" and values["GOOGLE_API_KEY"] == ""
@pytest.mark.parametrize("envname", ["dev", "prod"])
def test_container_env_example_has_only_container_keys(envname):
appenv = _load_deploy_module("appenv")
values = appenv.parse(str(DEPLOY / "env" / f"{envname}.env.example"))
assert set(values) <= appenv.CONTAINER_KEYS
assert values["MINDNET_ALLOW_CLOUD_EGRESS"] == "false"
@@ -260,7 +266,8 @@ def test_workflow_maps_branch_to_environment(name, branch, envname):
assert on["push"]["branches"] == [branch]
job = wf["jobs"]["deploy"]
assert job["runs-on"] == "linux_host"
assert job["env"]["MINDNET_ENV_FILE"].startswith("/") and job["env"]["MINDNET_ENV_FILE"].endswith(f"{envname}.env")
assert job["env"]["MINDNET_ENV_FILE"].startswith("/") and job["env"]["MINDNET_ENV_FILE"].endswith("container.env")
assert job["env"]["MINDNET_APP_ENV_FILE"] == SYSTEMD_ENV_FILES[envname]
assert any(s.get("run") == f"bash deploy/deploy.sh {envname}" for s in job["steps"])
@@ -274,32 +281,24 @@ def test_deploy_script_checks_before_touching_running_stack():
script = (DEPLOY / "deploy.sh").read_text(encoding="utf-8")
assert "\r" not in script
steps = script.split('step "1/5', 1)[1] # ohne Kopfkommentar und Funktionsdefinitionen
order = [steps.index(s) for s in ("--network none", "preflight --live", "up -d --wait --no-build && smoke")]
order = [steps.index(s) for s in ("--network none", "preflight --live", "up -d --wait --no-build --remove-orphans && smoke")]
assert order == sorted(order)
assert "RUN_DEPS=(--no-deps)" in script and "SMOKE_ARGS=(--require-data)" in script
assert "preflight --live" in script and "run --rm --no-deps api preflight" in script
assert "--require-data" in script and "deploy/appenv.py" in script
assert "last_good_tag" in script
@pytest.mark.parametrize("envname", ["dev", "prod"])
def test_compose_reads_env_file_from_host(envname):
assert COMPOSE[envname]["x-hardening"]["env_file"] == [f"${{MINDNET_ENV_FILE:-env/{envname}.env}}"]
def test_compose_reads_systemd_env_then_container_env(envname):
files = COMPOSE[envname]["x-hardening"]["env_file"]
assert files[0].startswith("${MINDNET_APP_ENV_FILE:?")
assert files[1] == f"${{MINDNET_ENV_FILE:-env/{envname}.env}}"
def test_prod_workflow_not_active_before_switchover():
assert not (ROOT / ".gitea" / "workflows" / "deploy-prod.yml").exists()
def test_dev_testvault_is_synthetic_and_parseable():
vault = DEPLOY / "testvault"
vocab = (vault / "_system" / "dictionary" / "edge_vocabulary.md").read_text(encoding="utf-8")
# Gleiches Muster wie app/services/edge_registry.py
rows = re.findall(r"\|\s*\*\*`?([a-zA-Z0-9_-]+)`?\*\*\s*\|\s*`?([a-zA-Z0-9_-]+)`?\s*\|\s*([^|]+)\|", vocab)
assert len(rows) >= 10
assert (vault / "_system" / "dictionary" / "graph_schema.md").is_file()
notes = [f for f in vault.rglob("*.md") if "_system" not in f.parts]
assert notes and all("topic/test" in f.read_text(encoding="utf-8") for f in notes)
@pytest.mark.parametrize("name", ["deploy-dev.yml", "deploy-prod.yml"])
def test_workflow_needs_no_external_actions(name):
# Der Runner-Host soll ohne Internet/DNS deployen können (kein github.com).