# Use official Python image
FROM python:3.12-slim

# Set working directory
WORKDIR /app

# Install system dependencies (needed for some python packages like psycopg2)
# libpq-dev is often needed for psycopg2
RUN apt-get update && apt-get install -y \
    gcc \
    libpq-dev \
    && rm -rf /var/lib/apt/lists/*

# Copy requirements first for caching
COPY requirements.txt .

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

# Copy the rest of the application
COPY . .

# Expose ports
# 8080 for HTTP API
# 8081 for WebSocket
EXPOSE 8080
EXPOSE 8081

# Define environment variables
ENV PYTHONUNBUFFERED=1
ENV PORT=8080
ENV WS_PORT=8081

# Command to run the application
CMD ["python", "app.py"]