Repository navigation
Expand file tree
/
Copy pathDockerfile.standalone
More file actions
76 lines (58 loc) · 2.34 KB
/
Copy pathDockerfile.standalone
File metadata and controls
76 lines (58 loc) · 2.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Self-contained Docker Image - clones from GitHub
# Build: docker build --build-arg ENGINE=slim -t infinity:slim .
# docker build --build-arg ENGINE=full -t infinity:full .
ARG ENGINE=slim
FROM python:3.13-slim-bookworm AS builder
ARG ENGINE
ENV ENGINE=${ENGINE}
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1
WORKDIR /app
# Install git and uv
RUN apt-get update && apt-get install -y --no-install-recommends git \
&& rm -rf /var/lib/apt/lists/* \
&& pip install uv
# Clone repository
RUN git clone --depth 1 https://github.com/Sed21/py-infinity.git .
# Install dependencies based on ENGINE
RUN if [ "$ENGINE" = "full" ]; then \
echo "Installing FULL dependencies (torch + optimum)..." && \
uv pip install --system ".[full]" \
--extra-index-url https://download.pytorch.org/whl/cpu; \
else \
echo "Installing SLIM dependencies (ONNX-only)..." && \
uv pip install --system ".[slim]"; \
fi
# Cleanup
RUN find /usr/local/lib/python*/site-packages -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true \
&& find /usr/local/lib/python*/site-packages -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true \
&& find /usr/local/lib/python*/site-packages -type f -name "*.pyc" -delete 2>/dev/null || true \
&& rm -rf /root/.cache 2>/dev/null || true
# Runtime stage
FROM python:3.13-slim-bookworm AS runtime
ARG ENGINE
ENV ENGINE=${ENGINE} \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
HF_HOME=/app/.cache/huggingface \
INFINITY_ENGINE=optimum
# Runtime dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
libgomp1 \
&& rm -rf /var/lib/apt/lists/*
# Copy installed packages
COPY --from=builder /usr/local/lib/python3.13/site-packages /usr/local/lib/python3.13/site-packages
COPY --from=builder /usr/local/bin/infinity_emb /usr/local/bin/
# Non-root user
RUN useradd --create-home --shell /bin/bash appuser \
&& mkdir -p /app/.cache/huggingface \
&& chown -R appuser:appuser /app
USER appuser
WORKDIR /app
EXPOSE 7997
ENTRYPOINT ["infinity_emb"]
CMD ["v2", "--port", "7997"]
LABEL org.opencontainers.image.title="infinity-emb" \
org.opencontainers.image.description="Text embedding server - ENGINE=${ENGINE}" \
org.opencontainers.image.source="https://github.com/Sed21/py-infinity"