# PyStreamDocuments REST API Server
FROM python:3.11-bookworm

WORKDIR /app

# Install system dependencies
RUN apt-get update && apt-get install -y \
    ca-certificates \
    libpq5 \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Copy Python application
COPY python/ ./python/

# Install Python dependencies
RUN pip install --no-cache-dir \
    fastapi==0.104.1 \
    uvicorn==0.24.0 \
    pydantic==2.4.2 \
    psycopg2-binary==2.9.9

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

# Default environment variables
ENV PYTHONUNBUFFERED=1
ENV SERVER_HOST=0.0.0.0
ENV SERVER_PORT=8080
ENV DATABASE_HOST=postgres
ENV DATABASE_PORT=5432
ENV DATABASE_USER=pystreamdocuments
ENV DATABASE_PASSWORD=pystreamdocuments
ENV DATABASE_NAME=pystreamdocuments

# Expose port
EXPOSE 8080

# Run server
CMD ["python", "-m", "pystreamdocuments.server"]
