-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
62 lines (44 loc) · 1.34 KB
/
Dockerfile
File metadata and controls
62 lines (44 loc) · 1.34 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
FROM python:3.11-slim AS deps
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
libglib2.0-0 \
libgl1 \
&& rm -rf /var/lib/apt/lists/*
RUN pip install -U pdm
ENV PDM_CHECK_UPDATE=false
COPY pyproject.toml pdm.lock LICENSE /app/
RUN pdm install --frozen-lockfile --prod --no-editable --no-self
FROM python:3.11-slim AS model-download
COPY --from=deps /app/.venv /app/.venv
ENV PATH="/app/.venv/bin:$PATH" \
TORCH_HOME=/model-cache \
HF_HOME=/model-cache/huggingface
RUN python - <<'EOF'
import open_clip
open_clip.create_model_and_transforms(
"ViT-B-16-SigLIP-256",
pretrained="webli",
device="cpu",
)
print("Model weights cached.")
EOF
FROM python:3.11-slim AS runtime
RUN apt-get update && apt-get install -y --no-install-recommends \
libglib2.0-0 \
libgl1 \
&& rm -rf /var/lib/apt/lists/*
RUN useradd --system --no-create-home --uid 1001 appuser
COPY --from=deps /app/.venv /app/.venv
COPY --chown=appuser --from=model-download /model-cache /model-cache
WORKDIR /app
COPY main.py .
RUN chown -R appuser /app
USER appuser
ENV PATH="/app/.venv/bin:$PATH" \
TORCH_HOME=/model-cache \
HF_HOME=/model-cache/huggingface \
MAX_CONCURRENT=4 \
PYTHONUNBUFFERED=1
EXPOSE 8000
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]