# Multi-stage Docker build for Agent Monitoring System FROM node:18-slim AS frontend-builder WORKDIR /app/frontend COPY frontend/package*.json ./ RUN npm ci COPY frontend/ ./ RUN npm run build FROM python:3.11-slim AS backend # Install system dependencies RUN apt-get update && apt-get install -y \ curl \ git \ build-essential \ && rm -rf /var/lib/apt/lists/* # Create user with home directory (required for HF Spaces) RUN useradd -m -u 1000 user USER user # Set environment variables ENV HOME=/home/user \ PATH="/home/user/.local/bin:$PATH" \ PYTHONPATH=/app \ PYTHONUNBUFFERED=1 \ PIP_TIMEOUT=600 \ PIP_RETRIES=3 # Set working directory WORKDIR /app # Copy Python dependencies first for better caching COPY --chown=user pyproject.toml ./ # Install dependencies directly with pip (more reliable than uv) # Force fresh install with langchain packages (2025-10-23) RUN pip install --user --upgrade pip && \ pip install --user --timeout=600 --retries=3 --no-cache-dir \ "langchain>=0.3.0" \ "langchain-community>=0.3.0" \ "langchain-text-splitters>=0.3.0" && \ pip install --user --timeout=600 --retries=3 --no-cache-dir -e . # Copy application code with proper ownership COPY --chown=user . . # Copy built frontend with proper ownership COPY --from=frontend-builder --chown=user /app/frontend/dist ./frontend/dist # Create necessary directories with proper ownership RUN mkdir -p logs datasets db cache evaluation_results # Ensure the package is properly installed for imports RUN pip install --user --no-deps -e . # Expose port (7860 is standard for Hugging Face Spaces) EXPOSE 7860 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD curl -f http://localhost:7860/api/observability/health-check || exit 1 # Run the application CMD ["python", "main.py", "--server", "--host", "0.0.0.0", "--port", "7860"]