ARG PYTHON_VERSION=3.14
FROM python:${PYTHON_VERSION}

ENV PYTHONUNBUFFERED=1 \
  UV_COMPILE_BYTECODE=1 \
  UV_SYSTEM_PYTHON=true \
  UV_PYTHON_DOWNLOADS=never \
  UV_PROJECT_ENVIRONMENT=/usr/local

WORKDIR /app

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

RUN apt-get update -qq && apt-get install -y -qq iproute2 > /dev/null 2>&1 \
    && rm -rf /var/lib/apt/lists/* \
    && curl -sL https://hey-release.s3.us-east-2.amazonaws.com/hey_linux_amd64 -o /usr/local/bin/hey \
    && chmod +x /usr/local/bin/hey

# Install Rust toolchain
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

# Copy everything needed for maturin to build a correctly-structured wheel.
# maturin needs django_vcache/ present to place the .so inside it.
COPY pyproject.toml Cargo.toml Cargo.lock README.md LICENSE /app/
COPY src/ /app/src/
COPY django_vcache/ /app/django_vcache/
RUN pip install maturin \
    && maturin build --release --interpreter python

# Install Python dependencies and the pre-built wheel
COPY . /app/
RUN uv sync --frozen --no-install-project \
    && pip install --no-deps target/wheels/*.whl
