-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
48 lines (36 loc) · 1.57 KB
/
Copy pathDockerfile
File metadata and controls
48 lines (36 loc) · 1.57 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
# ---------- base stage: heavy wheels installed once (chromadb / scipy / numpy) ----------
# Splitting the heavy DB layer from the light deps so changes to small packages
# don't trigger a ~500s chromadb rebuild.
FROM python:3.11-slim-bookworm AS heavy-deps
ENV PIP_NO_CACHE_DIR=1 \
PIP_NO_COMPILE=1
WORKDIR /app
COPY <<'EOF' /tmp/requirements-heavy.txt
chromadb>=0.5.0
langchain-chroma>=0.1.0
numpy>=1.24.0
PyMuPDF>=1.28.0
jieba>=0.42.0
rank_bm25>=0.2.2
EOF
RUN pip install --no-cache-dir --no-compile -r /tmp/requirements-heavy.txt
# ---------- light deps stage: smaller packages, change more often ----------
FROM heavy-deps AS deps
WORKDIR /app
COPY requirements-docker.txt .
# Strip the heavy packages already installed above to avoid re-resolving them.
RUN grep -vE '^(chromadb|langchain-chroma|numpy|PyMuPDF|jieba|rank_bm25)' requirements-docker.txt > /tmp/requirements-light.txt \
&& pip install --no-cache-dir --no-compile -r /tmp/requirements-light.txt
# ---------- runtime stage: small app layer on top of cached deps ----------
FROM deps AS runtime
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
HOST=0.0.0.0 \
PORT=8766
WORKDIR /app
# site-packages and python binary already inherited from the deps stage chain.
COPY . .
EXPOSE 8766
HEALTHCHECK --interval=30s --timeout=5s --start-period=20s --retries=3 \
CMD python -c "import os, urllib.request; port=os.getenv('PORT','8766'); urllib.request.urlopen(f'http://127.0.0.1:{port}/api/v1/health/', timeout=5).read()"
CMD ["sh", "-c", "uvicorn app.main:app --host ${HOST:-0.0.0.0} --port ${PORT:-8766}"]