FROM python:3.11-slim AS builder RUN apt-get update && apt-get install -y --no-install-recommends \ gcc libpq-dev curl && rm -rf /var/lib/apt/lists/* # Install uv RUN curl -LsSf https://astral.sh/uv/install.sh | sh ENV PATH="/root/.local/bin:$PATH" WORKDIR /app COPY pyproject.toml . COPY production/ ./production/ # Sync dependencies with uv RUN uv sync --frozen FROM python:3.11-slim AS production RUN apt-get update && apt-get install -y --no-install-recommends \ libpq5 curl && rm -rf /var/lib/apt/lists/* # Install uv in production too RUN curl -LsSf https://astral.sh/uv/install.sh | sh ENV PATH="/root/.local/bin:$PATH" RUN useradd --create-home --shell /bin/bash appuser WORKDIR /app COPY --from=builder /app/.venv /app/.venv COPY --chown=appuser:appuser production/ ./production/ COPY --chown=appuser:appuser pyproject.toml . ENV PATH="/app/.venv/bin:$PATH" ENV PYTHONPATH="/app" RUN chown -R appuser:appuser /app USER appuser EXPOSE 8000 HEALTHCHECK --interval=30s --timeout=10s --start-period=40s --retries=3 \ CMD curl -f http://localhost:8000/health || exit 1 CMD ["uvicorn", "production.production_server:app", "--host", "0.0.0.0", "--port", "8000"]