feat: enhance service discovery and proxy management

This commit is contained in:
gabdevele
2026-05-05 13:57:46 +02:00 Unverified
parent 93ba8e9ac2
commit a523c2faa3
53 changed files with 3206 additions and 706 deletions
+19 -5
View File
@@ -1,7 +1,6 @@
import os
import sys
from contextlib import asynccontextmanager
from pathlib import Path
from api.auth.router import router as auth_router
from api.editor.router import router as editor_router
@@ -12,9 +11,11 @@ from core.redis import close_redis, init_redis
from core.security import hash_password
from fastapi import FastAPI
from integrations.docker import get_all_services_in_dir
from integrations.docker.discovery import service_scan_root
from repositories.auth import ensure_auth_indexes, ensure_single_account
from repositories.examples import ensure_example_indexes
from repositories.proxy import ensure_proxy_indexes
from services.mitmproxy.recovery import reconcile_runtime
@asynccontextmanager
@@ -28,14 +29,27 @@ async def lifespan(_: FastAPI):
)
await ensure_proxy_indexes()
await ensure_example_indexes()
recovered = await reconcile_runtime()
if recovered:
recovered_count = len(recovered)
error_count = sum(
1
for _proxy_port, values in recovered
if values.get("status") == "error"
)
print(
f"[thePlug] Reconciled {recovered_count} persisted proxy runtimes"
f" ({error_count} with errors).",
file=sys.stderr,
)
home_dir = str(Path.home())
app.state.services = get_all_services_in_dir(home_dir) or []
scan_root = service_scan_root()
app.state.services = get_all_services_in_dir(scan_root) or []
if not app.state.services:
warning = (
"\n" + "!" * 60 + "\n"
" WARNING: No services found in home directory!\n"
f" Scanned: {home_dir}\n" + "!" * 60 + "\n"
" WARNING: No services found in scan root!\n"
f" Scanned: {scan_root}\n" + "!" * 60 + "\n"
)
print(warning, file=sys.stderr)