update userpage catalog

This commit is contained in:
sriram
2026-08-11 17:30:29 +05:30
parent 370f867355
commit 77d8536941
33 changed files with 3561 additions and 236 deletions

View File

@@ -8,14 +8,17 @@ Usage:
What this script automates:
1. Checks & launches PostgreSQL via Docker Compose (`docker compose up -d`).
2. Starts FastAPI backend server on http://localhost:8000 (with background auto-seeding).
3. Starts Vite frontend dev server on http://localhost:5173 (or serves static dist).
4. Keeps both servers running concurrently with instant hot-reloading & single Ctrl+C exit.
3. Waits until backend port 8000 is live & ready to receive connections.
4. Starts Vite frontend dev server on http://localhost:5173.
5. Keeps both servers running concurrently with instant hot-reloading & single Ctrl+C exit.
"""
import os
import sys
import time
import subprocess
import signal
import shutil
import urllib.request
from pathlib import Path
if sys.platform == "win32":
@@ -41,28 +44,71 @@ def print_banner():
print("=" * 70 + "\033[0m")
import shutil
def start_docker():
print("\n📦 Checking PostgreSQL Docker container...")
compose_file = ROOT_DIR / "docker-compose.yml"
if not compose_file.exists():
compose_file = BACKEND_DIR / "docker-compose.yml"
if not shutil.which("docker"):
print("ℹ️ Docker CLI not found. Skipping container management.")
return
# 1. Check if container is already running
try:
check_running = subprocess.run(
["docker", "ps", "--filter", "name=catalog_rag_postgres", "--format", "{{.Names}}"],
capture_output=True, text=True
)
if "catalog_rag_postgres" in check_running.stdout:
print("✅ PostgreSQL container 'catalog_rag_postgres' is running on port 5432 (pgvector ready).")
return
except Exception:
pass
# 2. Check if stopped container exists and start it
try:
check_all = subprocess.run(
["docker", "ps", "-a", "--filter", "name=catalog_rag_postgres", "--format", "{{.Names}}"],
capture_output=True, text=True
)
if "catalog_rag_postgres" in check_all.stdout:
print("🔄 Starting existing 'catalog_rag_postgres' container...")
start_res = subprocess.run(["docker", "start", "catalog_rag_postgres"], capture_output=True, text=True)
if start_res.returncode == 0:
print("✅ PostgreSQL container started on port 5432 (pgvector ready).")
return
except Exception:
pass
# 3. Fallback to Docker Compose
if compose_file.exists():
try:
res = subprocess.run(["docker", "compose", "-f", str(compose_file), "up", "-d"], capture_output=True, text=True)
res = subprocess.run(
["docker", "compose", "-f", str(compose_file), "up", "-d", "--remove-orphans"],
capture_output=True, text=True
)
if res.returncode == 0:
print("✅ PostgreSQL container is running on port 5432 (pgvector ready).")
else:
print("⚠️ Docker notice:", res.stderr.strip() or "Ensure Docker Desktop is running if using Docker Postgres.")
stderr_msg = res.stderr.strip()
if "Conflict" in stderr_msg or "already in use" in stderr_msg:
print("⚠️ Container name conflict detected. Automatically resetting container...")
subprocess.run(["docker", "rm", "-f", "catalog_rag_postgres"], capture_output=True, text=True)
retry_res = subprocess.run(
["docker", "compose", "-f", str(compose_file), "up", "-d"],
capture_output=True, text=True
)
if retry_res.returncode == 0:
print("✅ PostgreSQL container successfully recreated on port 5432 (pgvector ready).")
return
print("⚠️ Docker notice:", stderr_msg or "Ensure Docker Desktop is running if using Docker Postgres.")
except Exception as e:
print(f"⚠️ Docker check skipped: {e}")
def start_ollama():
print("\n🦙 Checking Ollama LLM service...")
import urllib.request
try:
req = urllib.request.urlopen("http://localhost:11434/api/tags", timeout=2)
if req.getcode() == 200:
@@ -84,6 +130,19 @@ def start_ollama():
return None
def wait_for_backend_ready():
print("⏳ Waiting for backend API to initialize on port 8000...")
for _ in range(30):
try:
req = urllib.request.urlopen("http://127.0.0.1:8000/api/system/status", timeout=1)
if req.getcode() == 200:
print("✅ Backend API is live and accepting connections on port 8000.")
return True
except Exception:
time.sleep(0.5)
return False
def main():
print_banner()
start_docker()
@@ -109,7 +168,10 @@ def main():
)
processes.append(p_backend)
# 2. Start Frontend Vite Dev Server
# 2. Wait until Backend is ready before starting Vite frontend
wait_for_backend_ready()
# 3. Start Frontend Vite Dev Server
print("🎨 Starting Frontend Vite Server (http://localhost:5173)...")
npm_cmd = "npm.cmd" if sys.platform == "win32" else "npm"
p_frontend = subprocess.Popen(
@@ -127,7 +189,7 @@ def main():
print("=" * 70)
print(" (Press Ctrl+C to stop all servers gracefully)\n")
# Monitor core servers (backend & frontend)
# Monitor core processes (backend & frontend)
core_processes = [p_backend, p_frontend]
while True:
time.sleep(1)