-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
51 lines (39 loc) · 2.23 KB
/
Dockerfile
File metadata and controls
51 lines (39 loc) · 2.23 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
# ─── Render Free Tier Optimised Dockerfile ───────────────────────────────
# Free tier: 512 MB RAM, shared CPU.
# Key rules:
# 1. CPU-only torch — saves ~800 MB image size vs default CUDA build
# 2. Pre-download ML models at build time — avoids cold-start timeout
# 3. web3 NOT installed — payments run in local ledger mode by default
FROM python:3.11-slim
# Build tools needed by some C-extension packages
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc g++ curl \
&& rm -rf /var/lib/apt/lists/*
WORKDIR /app
# ── 1. Install CPU-only torch first (must be before requirements.txt) ─────
# Pulling the CPU wheel avoids downloading 2+ GB of CUDA binaries
RUN pip install --no-cache-dir \
torch==2.1.0 \
--index-url https://download.pytorch.org/whl/cpu
# ── 2. Install remaining dependencies ─────────────────────────────────────
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# ── 3. Pre-cache ML models into the image layer ───────────────────────────
# Runs once at build time. Cold starts then take ~5s not ~3 min.
RUN python -c "\
from sentence_transformers import SentenceTransformer, CrossEncoder; \
SentenceTransformer('all-MiniLM-L6-v2'); \
CrossEncoder('cross-encoder/ms-marco-MiniLM-L-6-v2'); \
print('Models pre-cached OK') \
"
# ── 4. Copy application ────────────────────────────────────────────────────
COPY . .
RUN mkdir -p data identity
# ── 5. Runtime ────────────────────────────────────────────────────────────
ENV PYTHONPATH=/app
ENV PYTHONUNBUFFERED=1
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=15s --start-period=90s --retries=3 \
CMD curl -f http://localhost:${PORT:-8000}/health || exit 1
# Render injects $PORT automatically
CMD ["sh", "-c", "uvicorn main:app --host 0.0.0.0 --port ${PORT:-8000} --workers 1"]