FROM python:3.11-slim

# Prevent Python from writing .pyc files and force unbuffered logs.
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

# Set working directory inside the container.
WORKDIR /app

# Install system dependencies commonly needed by scientific Python packages.
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    libproj-dev \
    proj-data \
    proj-bin \
    libgeos-dev \
    && rm -rf /var/lib/apt/lists/*

# Install Python dependencies first for better Docker layer caching.
COPY requirements.txt .

RUN pip install --no-cache-dir --upgrade pip \
    && pip install --no-cache-dir -r requirements.txt

# Copy project files.
COPY . .

# Make the src package importable.
ENV PYTHONPATH=/app/src

# Flask API port.
EXPOSE 5000

# Default command: run the API server.
CMD ["python", "-m", "dqn_path_planning.api_server"]