Spaces:
Sleeping
Sleeping
Simplify Dockerfile: single-stage build with --prefer-binary
Browse filesThe previous two-stage build pre-built wheels under /wheels and then
ran `pip install --no-index --find-links=/wheels .` at runtime, but
the project's hatchling build backend wasn't in /wheels and pypi was
disabled, so the runtime install failed to bootstrap the backend.
Single stage avoids the hand-off entirely; --prefer-binary keeps pip
from compiling scipy / matplotlib from source on Render's small builder.
Switched the base image from python:3.12-slim to python:3.11-slim for
slightly broader wheel coverage on transitive deps.
- Dockerfile +25 -43
Dockerfile
CHANGED
|
@@ -1,61 +1,43 @@
|
|
| 1 |
-
# Dockerfile for the FastAPI backend (cdpr.interface.api)
|
| 2 |
#
|
| 3 |
-
#
|
| 4 |
-
#
|
| 5 |
-
#
|
| 6 |
-
#
|
| 7 |
-
#
|
| 8 |
-
#
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
#
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
FROM python:3.
|
| 14 |
|
| 15 |
-
ENV
|
|
|
|
| 16 |
PIP_NO_CACHE_DIR=1 \
|
| 17 |
-
|
| 18 |
-
PYTHONUNBUFFERED=1
|
| 19 |
|
| 20 |
-
WORKDIR /
|
| 21 |
-
|
| 22 |
-
# System build deps (removed in the runtime stage).
|
| 23 |
-
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 24 |
-
build-essential \
|
| 25 |
-
gcc \
|
| 26 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 27 |
-
|
| 28 |
-
# Copy only metadata first to maximise layer caching.
|
| 29 |
-
COPY pyproject.toml README.md LICENSE ./
|
| 30 |
-
COPY src/ ./src/
|
| 31 |
-
|
| 32 |
-
RUN pip install --upgrade pip wheel \
|
| 33 |
-
&& pip wheel --wheel-dir /wheels ".[api,viz,data]"
|
| 34 |
-
|
| 35 |
-
# ---- runtime -----------------------------------------------------------
|
| 36 |
-
|
| 37 |
-
FROM python:3.12-slim AS runtime
|
| 38 |
-
|
| 39 |
-
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 40 |
-
PYTHONUNBUFFERED=1
|
| 41 |
|
| 42 |
-
# Runtime
|
| 43 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 44 |
libgomp1 \
|
| 45 |
&& rm -rf /var/lib/apt/lists/*
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
COPY --from=builder /wheels /wheels
|
| 50 |
COPY pyproject.toml README.md LICENSE ./
|
| 51 |
COPY src/ ./src/
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
# Render injects $PORT at runtime; default to 8000
|
| 57 |
ENV PORT=8000
|
| 58 |
EXPOSE 8000
|
| 59 |
|
| 60 |
-
#
|
| 61 |
CMD uvicorn cdpr.interface.api:app --host 0.0.0.0 --port "${PORT}"
|
|
|
|
| 1 |
+
# Dockerfile for the FastAPI backend (cdpr.interface.api).
|
| 2 |
#
|
| 3 |
+
# Single-stage build. The earlier two-stage variant pre-built wheels
|
| 4 |
+
# under /wheels then ran `pip install --no-index --find-links=/wheels .`
|
| 5 |
+
# at runtime --- but the project itself uses hatchling as its build
|
| 6 |
+
# backend, and `--no-index` prevented pip from fetching it. This version
|
| 7 |
+
# installs everything in one pass with `--prefer-binary` so pip takes
|
| 8 |
+
# pre-built wheels from PyPI for scipy / numpy / matplotlib / pillow /
|
| 9 |
+
# pydantic-core rather than trying to build them from source on Render's
|
| 10 |
+
# small free-tier builder.
|
| 11 |
+
#
|
| 12 |
+
# Python 3.11 chosen for the broadest wheel coverage on PyPI; 3.12 also
|
| 13 |
+
# works but a handful of transitive deps still lag.
|
| 14 |
|
| 15 |
+
FROM python:3.11-slim
|
| 16 |
|
| 17 |
+
ENV PYTHONDONTWRITEBYTECODE=1 \
|
| 18 |
+
PYTHONUNBUFFERED=1 \
|
| 19 |
PIP_NO_CACHE_DIR=1 \
|
| 20 |
+
PIP_DISABLE_PIP_VERSION_CHECK=1
|
|
|
|
| 21 |
|
| 22 |
+
WORKDIR /app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
+
# Runtime system deps. libgomp1 = scipy/numpy LAPACK OpenMP threads.
|
| 25 |
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 26 |
libgomp1 \
|
| 27 |
&& rm -rf /var/lib/apt/lists/*
|
| 28 |
|
| 29 |
+
# Package metadata + source. Order maximises layer caching.
|
|
|
|
|
|
|
| 30 |
COPY pyproject.toml README.md LICENSE ./
|
| 31 |
COPY src/ ./src/
|
| 32 |
|
| 33 |
+
# Install. --prefer-binary keeps pip from compiling scipy / matplotlib
|
| 34 |
+
# from source on a memory-constrained builder.
|
| 35 |
+
RUN pip install --upgrade pip wheel setuptools \
|
| 36 |
+
&& pip install --prefer-binary ".[api,viz,data]"
|
| 37 |
|
| 38 |
+
# Render injects $PORT at runtime; default to 8000 locally.
|
| 39 |
ENV PORT=8000
|
| 40 |
EXPOSE 8000
|
| 41 |
|
| 42 |
+
# Shell form so ${PORT} is expanded at start time.
|
| 43 |
CMD uvicorn cdpr.interface.api:app --host 0.0.0.0 --port "${PORT}"
|