-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
54 lines (41 loc) · 1.97 KB
/
Dockerfile
File metadata and controls
54 lines (41 loc) · 1.97 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
# syntax=docker/dockerfile:1.7
# =============================================================================
# Machine Learning Model — multi-stage Dockerfile
#
# Stages
# deps – install Python dependencies (shared cache layer)
# test – run the full pytest suite (CI target)
# app – lean production image (CLI / batch ML)
# =============================================================================
# ── deps ──────────────────────────────────────────────────────────────────────
FROM python:3.11-slim AS deps
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
WORKDIR /app
RUN apt-get update \
&& apt-get install -y --no-install-recommends build-essential git \
&& rm -rf /var/lib/apt/lists/*
COPY requirements.txt requirements-dev.txt ./
RUN pip install --upgrade pip \
&& pip install -r requirements.txt -r requirements-dev.txt
# ── test ──────────────────────────────────────────────────────────────────────
FROM deps AS test
COPY . .
RUN pip install -e . --no-deps
ENV PYTHONPATH=/app/src
# Run tests; exit code propagated to docker build / CI
CMD ["python", "-m", "pytest", "tests/", \
"--ignore=tests/gui", \
"-q", "--no-cov", "--tb=short"]
# ── app ───────────────────────────────────────────────────────────────────────
FROM deps AS app
COPY . .
RUN pip install -e . --no-deps \
&& groupadd -r appuser \
&& useradd -r -g appuser appuser \
&& chown -R appuser:appuser /app
USER appuser
ENV PYTHONPATH=/app/src
CMD ["machine-learning-model"]