# Dockerfile
FROM python:3.13-slim-bookworm AS base

WORKDIR /var/app

# Update and install common packages
RUN apt-get update && apt-get install gcc curl -y

# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /bin/uv

RUN useradd uwsgi -s /bin/false -m
RUN mkdir /var/log/uwsgi
RUN chown -R uwsgi:uwsgi /var/log/uwsgi
RUN mkdir -p /root/.snowflake && chmod 755 /root && chmod 755 /root/.snowflake

# Install dependencies (layer-cached until pyproject.toml or uv.lock changes)
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev --no-install-project && uv cache clean

# Add application
COPY application.py dev.py ./
COPY reporting/ ./reporting/

ENV PATH="/var/app/.venv/bin:$PATH"

# Add startup script
ADD uwsgi-start.sh /
RUN chmod +x /uwsgi-start.sh
ENTRYPOINT ["/uwsgi-start.sh"]

EXPOSE 8080
