iris-ir-platform / docker-entrypoint.sh
rajvivan's picture
sync: push iris-ir-platform to HuggingFace Space
1775b97 verified
Raw
History Blame Contribute Delete
1.35 kB
#!/bin/bash
set -e
echo "Starting IRIS IR Platform..."
backend_loop() {
while true; do
echo "Starting cache-backed FastAPI backend on port 8000..."
cd /app/backend
python3 -m uvicorn lightweight_server:app --host 0.0.0.0 --port 8000
echo "Backend process exited; restarting in 2 seconds..."
sleep 2
done
}
# Start FastAPI backend on port 8000 with an automatic restart loop.
# Hugging Face uses the cache-backed lightweight API to avoid cold-starting
# local vector indexes and model dependencies on CPU.
backend_loop &
BACKEND_LOOP_PID=$!
# Wait for backend to be ready
echo "Waiting for backend..."
for i in {1..45}; do
if curl -sf http://localhost:8000/api/health > /dev/null 2>&1; then
echo "Backend ready!"
break
fi
sleep 2
done
if ! curl -sf http://localhost:8000/api/health > /dev/null 2>&1; then
echo "Backend still warming; Next.js cache-backed proxy will serve IRIS API routes."
fi
# Start Next.js frontend on port 7860 (HuggingFace default port)
cd /app
PORT=7860 HOSTNAME=0.0.0.0 node server.js &
FRONTEND_PID=$!
echo "IRIS is running:"
echo " Frontend -> http://0.0.0.0:7860"
echo " Backend -> http://localhost:8000"
echo " Fallback -> Next.js /api/proxy cache-backed IR API"
# Keep alive
trap "kill $BACKEND_LOOP_PID $FRONTEND_PID 2>/dev/null; exit" EXIT SIGTERM SIGINT
wait $FRONTEND_PID