FROM python:3.12-slim

WORKDIR /app

# Install uv (build-time only — runtime uses the venv's python directly to
# avoid uv's start-of-process sync, which would re-download dev deps on
# every cold start and blow past Scaleway's deploy timeout).
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/

# Copy dependency files first for layer caching
COPY backend/pyproject.toml backend/uv.lock /app/

# Install dependencies (production only, no project — project source is
# copied next and resolved via PYTHONPATH at runtime).
RUN uv sync --frozen --no-dev --no-install-project

# Copy backend source
COPY backend/ /app/

# Make sure the app module is importable and venv binaries are first on PATH.
ENV PYTHONPATH=/app
ENV PATH=/app/.venv/bin:$PATH

EXPOSE 8001

# DIAGNOSTIC: run a minimal HTTP server instead of the full app, to isolate
# whether the Scaleway probe failure is granian/app-related or something
# at the network/runtime layer.
CMD ["python", "-c", "import http.server, socketserver, os, sys; port=int(os.environ.get('PORT', '8001')); print(f'starting on 0.0.0.0:{port}', flush=True); s=socketserver.TCPServer(('0.0.0.0', port), http.server.SimpleHTTPRequestHandler); s.serve_forever()"]
