FROM python:3.11-slim

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    curl \
    gcc \
    g++ \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements
COPY requirements-http.txt .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements-http.txt

# Copy application code
COPY src/ ./src/
COPY run_http_server.py .

# Create data directory
RUN mkdir -p /app/data

# Set permissions
RUN chmod +x run_http_server.py

# Expose port
EXPOSE 8000

# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
    CMD curl -f http://localhost:8000/health || exit 1

# Run the server
CMD ["python", "run_http_server.py"]