-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
61 lines (47 loc) · 2.18 KB
/
Copy pathDockerfile
File metadata and controls
61 lines (47 loc) · 2.18 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
# syntax=docker/dockerfile:1
# Multi-stage build for Argus.
# Stage 1 (builder) compiles all dependencies into an isolated venv.
# Stage 2 (runtime) copies ONLY that finished venv + the app — no compilers,
# no build tools shipped to production. Smaller image, smaller attack surface.
# ---------- Stage 1: builder ----------
FROM python:3.11-slim AS builder
# Build-time hygiene: no .pyc files, no pip cache bloating layers.
ENV PYTHONDONTWRITEBYTECODE=1 \
PIP_NO_CACHE_DIR=1 \
PIP_DISABLE_PIP_VERSION_CHECK=1
# An isolated virtualenv we will lift wholesale into the runtime stage.
RUN python -m venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
WORKDIR /build
# Copy only what pip needs to resolve and install the project + its deps.
# (Kept before any future code-only changes so this slow layer caches well.)
COPY pyproject.toml ./
COPY app ./app
COPY pipeline ./pipeline
# Installs fastapi, sqlalchemy, psycopg, pgvector, ... into /opt/venv.
RUN pip install .
# ---------- Stage 2: runtime ----------
FROM python:3.11-slim AS runtime
# Runtime hygiene: unbuffered logs (so container logs stream), no .pyc.
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PATH="/opt/venv/bin:$PATH"
# Never run app processes as root. A dedicated non-root user limits blast radius.
RUN useradd --create-home --uid 1000 argus
WORKDIR /app
# The finished dependency venv from the builder — none of the build tooling.
COPY --from=builder /opt/venv /opt/venv
# Application code + migration assets (alembic is not part of the pip package,
# so it must be copied explicitly to run `alembic upgrade head` in-container).
COPY app ./app
COPY pipeline ./pipeline
COPY alembic ./alembic
COPY alembic.ini ./
USER argus
EXPOSE 8000
# Liveness probe: the orchestrator restarts the container if /health stops responding.
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD python -c "import httpx,sys; sys.exit(0 if httpx.get('http://localhost:8000/health').status_code==200 else 1)"
# Default process = the API. Override for CLIs:
# docker run --rm argus python -m pipeline.run --source labels --drug ibuprofen --total 10
CMD ["uvicorn", "app.api.main:app", "--host", "0.0.0.0", "--port", "8000"]