-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
71 lines (56 loc) · 2.07 KB
/
Copy pathDockerfile
File metadata and controls
71 lines (56 loc) · 2.07 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
# builder
# Installs deps, builds the IVF+SQ8 index from
# references.json.gz. No compiler needed, faiss-cpu ships pre-built wheels.
FROM python:3.12-slim AS builder
WORKDIR /build
# Install ALL runtime deps here so site-packages can be copied to runtime stage
COPY app/requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY scripts/build_index.py .
COPY resources/ /resources/
# Build the Faiss IVF+SQ8 index, outputs ~66 MB index.faiss
# nlist=1000: 1000 clusters over 3M vectors
# nprobe=10: search 10 clusters per query (1% of data) , fast + accurate
RUN python build_index.py \
--references /resources/references.json.gz \
--output-dir /data \
--nlist 1000 \
--nprobe 10
# runtime
# Lean image: no compiler, no pip. Everything copied pre-built from builder.
# Memory budget per container:
# Faiss IVF+SQ8 index : ~64 MB
# labels.npy : ~3 MB
# Python + granian : ~50 MB
# Total : ~117 MB : fits inside 160 MB limit
FROM python:3.12-slim AS runtime
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*
# Copy pre-compiled Python packages — no compiler needed in runtime
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin/granian /usr/local/bin/granian
# Application source
COPY app/ .
# Pre-built Faiss index
COPY --from=builder /data /data
# Env vars
ENV INDEX_PATH=/data/index.faiss
ENV LABELS_PATH=/data/labels.npy
ENV PORT=8000
# Raise NPROBE for better recall at the cost of slightly higher latency
ENV NPROBE=10
EXPOSE 8000
# Granian - Rust ASGI server
# 1 worker: index is ~64 MB; 2 workers would use ~128 MB + overhead = OOM risk
# The load balancer round-robins across api1 and api2, so we still have
# 2 parallel workers at the system level.
CMD ["sh", "-c", \
"python -m granian \
--interface asgi \
--host 0.0.0.0 \
--port $PORT \
--workers 1 \
--runtime-threads 1 \
main:app"]