IntegraChat / Dockerfile
nothingworry's picture
Deploy to HF Spaces
916e12b
raw
history blame
2.65 kB
FROM python:3.10-slim
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
g++ \
postgresql-client \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements and install Python dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Copy application code
COPY . .
# Create data directory for SQLite fallback
RUN mkdir -p /app/data
# Expose ports
# - 7860: Gradio UI (default HF Spaces port)
# - 8000: FastAPI backend
# - 8900: MCP server
EXPOSE 7860 8000 8900
# Set environment variables with defaults
ENV PYTHONPATH=/app
ENV API_PORT=8000
ENV MCP_PORT=8900
ENV BACKEND_BASE_URL=http://localhost:8000
ENV RAG_MCP_URL=http://localhost:8900/rag
ENV WEB_MCP_URL=http://localhost:8900/web
ENV ADMIN_MCP_URL=http://localhost:8900/admin
# Create startup script that runs all services
RUN echo '#!/bin/bash\n\
set -e\n\
\n\
# Function to wait for a service to be ready\n\
wait_for_service() {\n\
local url=$1\n\
local max_attempts=30\n\
local attempt=0\n\
\n\
echo "Waiting for $url to be ready..."\n\
while [ $attempt -lt $max_attempts ]; do\n\
if curl -s -f "$url" > /dev/null 2>&1; then\n\
echo "$url is ready!"\n\
return 0\n\
fi\n\
attempt=$((attempt + 1))\n\
sleep 1\n\
done\n\
\n\
echo "Warning: $url did not become ready after $max_attempts attempts"\n\
return 1\n\
}\n\
\n\
# Start MCP server in background\n\
echo "Starting MCP server on port $MCP_PORT..."\n\
python -m backend.mcp_server.server &\n\
MCP_PID=$!\n\
\n\
# Wait for MCP server to be ready\n\
sleep 5\n\
if ! kill -0 $MCP_PID 2>/dev/null; then\n\
echo "Error: MCP server failed to start"\n\
exit 1\n\
fi\n\
\n\
# Start FastAPI backend in background\n\
echo "Starting FastAPI backend on port $API_PORT..."\n\
uvicorn backend.api.main:app --host 0.0.0.0 --port $API_PORT &\n\
API_PID=$!\n\
\n\
# Wait for FastAPI to be ready\n\
sleep 5\n\
if ! kill -0 $API_PID 2>/dev/null; then\n\
echo "Error: FastAPI backend failed to start"\n\
exit 1\n\
fi\n\
\n\
# Wait for health check\n\
wait_for_service "http://localhost:$API_PORT/health" || true\n\
\n\
# Start Gradio UI (foreground - this is the main process)\n\
echo "Starting Gradio UI on port 7860..."\n\
echo "All services are running:"\n\
echo " - MCP Server: http://localhost:$MCP_PORT"\n\
echo " - FastAPI Backend: http://localhost:$API_PORT"\n\
echo " - Gradio UI: http://localhost:7860"\n\
python app.py\n\
' > /app/start.sh && chmod +x /app/start.sh
# Use the startup script as entrypoint
CMD ["/app/start.sh"]