Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
93 lines (76 loc) · 3.75 KB
/
Copy pathDockerfile
File metadata and controls
93 lines (76 loc) · 3.75 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# exporter:一次性导出 ONNX(含 torch,不进入最终镜像)
FROM python:3.12-slim-bookworm AS exporter
ARG APT_MIRROR=mirrors.tencent.com
ARG PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
ARG HF_ENDPOINT=https://hf-mirror.com
WORKDIR /export
ENV HF_ENDPOINT=${HF_ENDPOINT} \
HF_HUB_ENABLE_HF_TRANSFER=0 \
CUDA_VISIBLE_DEVICES=""
RUN if [ -f /etc/apt/sources.list.d/debian.sources ]; then \
sed -i "s|deb.debian.org|${APT_MIRROR}|g; s|security.debian.org|${APT_MIRROR}/debian-security|g" \
/etc/apt/sources.list.d/debian.sources; \
else \
sed -i "s|deb.debian.org|${APT_MIRROR}|g; s|security.debian.org|${APT_MIRROR}/debian-security|g" \
/etc/apt/sources.list; \
fi \
&& apt-get update \
&& apt-get install -y --no-install-recommends build-essential \
&& rm -rf /var/lib/apt/lists/*
# 只走清华源。直接调用 pip,避免 $$ 被原样传给 /bin/sh 造成语法错误。
RUN ( pip install --no-cache-dir --timeout 120 --retries 5 \
--trusted-host pypi.tuna.tsinghua.edu.cn \
-i "${PIP_INDEX_URL}" --upgrade pip \
|| pip install --no-cache-dir --timeout 120 --retries 5 \
--trusted-host pypi.tuna.tsinghua.edu.cn \
-i "${PIP_INDEX_URL}" --upgrade pip ) \
&& ( pip install --no-cache-dir --timeout 120 --retries 5 \
--trusted-host pypi.tuna.tsinghua.edu.cn \
-i "${PIP_INDEX_URL}" "sentence-transformers>=3.3.0" torch onnxscript \
|| pip install --no-cache-dir --timeout 120 --retries 5 \
--trusted-host pypi.tuna.tsinghua.edu.cn \
-i "${PIP_INDEX_URL}" "sentence-transformers>=3.3.0" torch onnxscript )
COPY scripts/export_onnx_model.py ./scripts/
RUN python scripts/export_onnx_model.py --output-dir /export/onnx
# builder:安装生产依赖(onnxruntime,无 PyTorch)
FROM python:3.12-slim-bookworm AS builder
ARG APT_MIRROR=mirrors.tencent.com
ARG PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
WORKDIR /app
RUN if [ -f /etc/apt/sources.list.d/debian.sources ]; then \
sed -i "s|deb.debian.org|${APT_MIRROR}|g; s|security.debian.org|${APT_MIRROR}/debian-security|g" \
/etc/apt/sources.list.d/debian.sources; \
else \
sed -i "s|deb.debian.org|${APT_MIRROR}|g; s|security.debian.org|${APT_MIRROR}/debian-security|g" \
/etc/apt/sources.list; \
fi \
&& apt-get update \
&& apt-get install -y --no-install-recommends build-essential \
&& rm -rf /var/lib/apt/lists/*
COPY pyproject.toml README.md ./
COPY app ./app
# 只走清华源。直接调用 pip,避免 $$ 被原样传给 /bin/sh 造成语法错误。
RUN ( pip install --no-cache-dir --timeout 120 --retries 5 \
--trusted-host pypi.tuna.tsinghua.edu.cn \
-i "${PIP_INDEX_URL}" --upgrade pip \
|| pip install --no-cache-dir --timeout 120 --retries 5 \
--trusted-host pypi.tuna.tsinghua.edu.cn \
-i "${PIP_INDEX_URL}" --upgrade pip ) \
&& ( pip install --no-cache-dir --timeout 120 --retries 5 \
--trusted-host pypi.tuna.tsinghua.edu.cn \
-i "${PIP_INDEX_URL}" . \
|| pip install --no-cache-dir --timeout 120 --retries 5 \
--trusted-host pypi.tuna.tsinghua.edu.cn \
-i "${PIP_INDEX_URL}" . )
FROM python:3.12-slim-bookworm AS runtime
WORKDIR /app
COPY --from=builder /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
COPY --from=exporter /export/onnx ./models/onnx/bge-small-zh-v1.5
COPY scripts/__init__.py scripts/sync_es_from_comm.py ./scripts/
ENV HF_HOME=/data/huggingface \
SENTENCE_TRANSFORMERS_HOME=/data/huggingface \
EMBEDDING_BACKEND=onnx \
EMBEDDING_ONNX_DIR=models/onnx/bge-small-zh-v1.5
EXPOSE 8080
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8080"]