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:
1 parent
eae30775e3
commit
6cdad8b046
20 files changed
+373
-415
No files matched your search
@@ -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).
|
||||
|
||||
Reference in new issue
Block a user