11# oasis/models/crime_predictor/Dockerfile
2- # Stage 1: Training
2+
3+ # ── Stage 1: Training ──────────────────────────
34FROM python:3.11-slim AS trainer
45
6+ LABEL stage="training"
7+
58WORKDIR /app
69COPY requirements.txt .
7- RUN pip install --no-cache-dir -r requirements.txt
10+ RUN pip install --no-cache-dir --upgrade pip \
11+ && pip install --no-cache-dir -r requirements.txt
812
913COPY . .
14+
1015ARG DATA_URL
1116RUN python train.py --data-url ${DATA_URL}
1217
13- # Stage 2: Production (minimal)
18+ # ── Stage 2: Production (minimal) ─────────────
1419FROM python:3.11-slim AS production
1520
21+ LABEL maintainer="Dreipfelt" \
22+ project="OASIS Security" \
23+ version="1.0" \
24+ description="Crime predictor inference API — CDSD Project"
25+
26+ # Utilisateur non-root (sécurité)
27+ RUN adduser --disabled-password --gecos "" appuser
28+
1629WORKDIR /app
30+
31+ # Dépendances de serving uniquement (pas sklearn, statsmodels, etc.)
32+ COPY requirements-serving.txt .
33+ RUN pip install --no-cache-dir --upgrade pip \
34+ && pip install --no-cache-dir -r requirements-serving.txt
35+
36+ # Artefact ML depuis le stage trainer
1737COPY --from=trainer /app/models/crime_predictor.pkl ./models/
18- COPY requirements.txt .
19- RUN pip install --no-cache-dir -r requirements.txt
2038
39+ # Code applicatif
2140COPY predict.py model.py config.yaml ./
41+
42+ USER appuser
43+
2244EXPOSE 8000
2345
46+ HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
47+ CMD curl -f http://localhost:8000/health || exit 1
48+
2449CMD ["uvicorn" , "predict:app" , "--host" , "0.0.0.0" , "--port" , "8000" ]
0 commit comments