File size: 1,921 Bytes
c2ea5ed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9da434e
 
 
 
 
 
 
 
 
 
 
 
 
 
c2ea5ed
 
9da434e
c2ea5ed
 
0b205c4
9da434e
87ee823
 
0b205c4
 
9da434e
c2ea5ed
9da434e
 
c2ea5ed
9da434e
 
c2ea5ed
9da434e
c2ea5ed
 
 
9da434e
c2ea5ed
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# 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"]