FROM python:3.12-slim

# System deps:
#   postgresql-client  - pg_isready in entrypoint
#   gcc, libpq-dev     - psycopg2 build
#   libcairo2-dev      - pycairo (required by svglib -> xhtml2pdf)
#   pkg-config         - required by pycairo's meson build
RUN apt-get update && apt-get install -y --no-install-recommends \
    postgresql-client \
    gcc \
    libpq-dev \
    libcairo2-dev \
    pkg-config \
    && rm -rf /var/lib/apt/lists/*

WORKDIR /app

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

# Copy the Django project (the inner busManager/ directory)
COPY busManager/ .

# Copy entrypoint
COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

# Static files will be collected to /app/staticfiles at runtime
ENV STATIC_ROOT=/app/staticfiles
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

EXPOSE 8000

ENTRYPOINT ["/entrypoint.sh"]
