Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
78 lines (62 loc) · 2.93 KB
/
Copy pathDockerfile
File metadata and controls
78 lines (62 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Phase 7.A — fullstack image (FastAPI + built React bundle behind one process).
#
# Stage 1 builds the SPA with VITE_API_MOCK=0 so the bundle hits relative
# /api/... URLs at the same origin (uvicorn). Stage 2 installs the Python
# project as an editable install — that creates the same `.pth` Vite-style
# entry that the dev environment uses, which is how the top-level src/
# modules (cache.py, http_client.py, logbook.py, …) become importable
# without listing them in [tool.setuptools.py-modules].
# ---------------------------------------------------------------------------
# Stage 1: frontend build
# ---------------------------------------------------------------------------
FROM node:20-alpine AS frontend-builder
WORKDIR /build
# Install deps first to keep the npm-ci layer cacheable across source edits.
COPY frontend/package.json frontend/package-lock.json ./
RUN npm ci --no-audit --no-fund
# Build with VITE_API_MOCK=0 so client.ts emits relative /api/... URLs
# against the uvicorn origin instead of geo.api.gouv.fr-direct mocks.
ENV VITE_API_MOCK=0 \
VITE_REPLAY_DELAY_MS=1500
COPY frontend/ ./
RUN npm run build
# ---------------------------------------------------------------------------
# Stage 2: Python runtime
# ---------------------------------------------------------------------------
FROM python:3.13-slim AS runtime
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1 \
PIP_NO_CACHE_DIR=1
WORKDIR /app
# Build deps for statsmodels (numpy/scipy compile from sdist on slim).
# We install gcc/g++/gfortran in a single RUN so Docker can drop the apt
# cache in the same layer.
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
build-essential \
gfortran \
libopenblas-dev \
liblapack-dev \
wget \
&& rm -rf /var/lib/apt/lists/*
# Install Python deps via the project's editable install so the .pth
# trick that puts src/ on sys.path keeps top-level modules importable
# (cache.py, http_client.py, logbook.py, …).
COPY pyproject.toml README.md ./
COPY src/ ./src/
RUN pip install --upgrade pip setuptools wheel \
&& pip install -e .
# Static + runtime artefacts
COPY config/ ./config/
COPY --from=frontend-builder /build/dist /app/frontend/dist
# Pre-create the data + logs directories so the orchestrator can write
# without bailing on permissions if the volume mount is missing.
RUN mkdir -p /app/data/raw /app/data/processed /app/data/cache /app/data/output /app/logs
EXPOSE 8000
# Healthcheck mirrors what `web.server.healthz` returns. `wget --spider`
# would issue HEAD which FastAPI does not auto-handle for GET routes, so
# we use `-O /dev/null` to force a real GET request.
HEALTHCHECK --interval=30s --timeout=5s --retries=3 --start-period=10s \
CMD wget --quiet --tries=1 -O /dev/null http://127.0.0.1:8000/healthz || exit 1
CMD ["uvicorn", "web.server:app", "--host", "0.0.0.0", "--port", "8000", "--app-dir", "/app/src"]