-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.python
More file actions
180 lines (158 loc) · 7.79 KB
/
Dockerfile.python
File metadata and controls
180 lines (158 loc) · 7.79 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# syntax=docker/dockerfile:1.7
# -------- worker 容器:Python 3.13 + Node 20 同住 --------
# 作用:跑 Express (webui/server) + 通过 child_process.spawn 拉起
# python -m dataflow_edu.task_runner / dataflow_edu.competency_suggest
# 等子进程,实现教师端任务执行链路。
#
# 设计说明(与 agent_notes.md「Docker 部署」一致):
# - 不打包本地 OCR (mineru / torch / modelscope),OCR 仅 remote 模式可用
# 或在镜像内被 stub 替代,启动时不报错、调用时显式拒绝。
# - 不打包 DataFlow/requirements.txt 的全套依赖(torch/transformers 几个 G),
# 而是把 DataFlow/dataflow/__init__.py 改成最小导出版(只 get_logger + 注册中心),
# 避免拉起整个算子库导致镜像膨胀。
# - 字体:装 fonts-noto-cjk + fonts-wqy-microhei,并支持把合法获取的 msyh*.ttf/ttc
# 放到 deploy/fonts/ 一起打进镜像。fontconfig 会优先匹配真 Microsoft YaHei,
# 缺字时再回落到 wqy/noto,避免 LibreOffice 转 PDF 时掉到 DejaVu。
FROM python:3.13-slim AS runtime
ENV PYTHONUNBUFFERED=1 \
PYTHONIOENCODING=utf-8 \
PYTHONUTF8=1 \
PYTHON_BIN=python \
PYTHONPATH=/app/DataFlow:/app \
NODE_ENV=production \
DATAFLOW_NONINTERACTIVE=1 \
PORT=3000
# ---- 切换 apt 源到清华镜像(trixie / Debian 13),大幅加速国内构建 ----
RUN set -eux; \
if [ -f /etc/apt/sources.list.d/debian.sources ]; then \
sed -i 's|http://deb.debian.org|https://mirrors.tuna.tsinghua.edu.cn|g; s|http://security.debian.org|https://mirrors.tuna.tsinghua.edu.cn/debian-security|g' /etc/apt/sources.list.d/debian.sources; \
fi; \
if [ -f /etc/apt/sources.list ]; then \
sed -i 's|http://deb.debian.org|https://mirrors.tuna.tsinghua.edu.cn|g; s|http://security.debian.org|https://mirrors.tuna.tsinghua.edu.cn/debian-security|g' /etc/apt/sources.list; \
fi
# ---- 系统依赖:LibreOffice + CJK 字体 + 编译工具(Node 单独装,见下一层)----
# 用 BuildKit cache mount 缓存 apt 下载产物(跨构建复用,省掉重复拉包)
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
set -eux; \
rm -f /etc/apt/apt.conf.d/docker-clean; \
apt-get update; \
apt-get install -y --no-install-recommends \
ca-certificates curl gnupg xz-utils \
build-essential \
libreoffice-core libreoffice-writer \
fontconfig \
fonts-noto-cjk fonts-wqy-microhei fonts-wqy-zenhei \
poppler-utils \
libpng16-16 libjpeg62-turbo zlib1g
# ---- Node 20:直接从清华 nodejs-release 拉官方 tar.xz 解压到 /usr/local ----
# 不走 NodeSource:那边 setup 脚本国内常拉空 + 清华没镜像 nodesource deb 仓库,
# 静默失败后会回落到 Debian 自带 nodejs(不带 npm)→ 后续 npm ci 直接 not found。
# 这里改成下 prebuilt tar.xz,node / npm / npx 一并到位,不依赖任何 apt 源。
ARG NODE_VERSION=20.18.1
ARG TARGETARCH
RUN set -eux; \
case "${TARGETARCH:-amd64}" in \
amd64) NODE_ARCH=x64 ;; \
arm64) NODE_ARCH=arm64 ;; \
*) echo "Unsupported TARGETARCH: ${TARGETARCH}"; exit 1 ;; \
esac; \
NODE_PKG="node-v${NODE_VERSION}-linux-${NODE_ARCH}.tar.xz"; \
curl -fsSLO "https://mirrors.tuna.tsinghua.edu.cn/nodejs-release/v${NODE_VERSION}/${NODE_PKG}"; \
tar -xJf "${NODE_PKG}" -C /usr/local --strip-components=1 \
--exclude CHANGELOG.md --exclude LICENSE --exclude README.md; \
rm -f "${NODE_PKG}"; \
node --version; \
npm --version
WORKDIR /app
# ---- Python 依赖(先拷 requirements 利用层缓存 + pip 缓存 mount + 清华 PyPI)----
COPY requirements-cloud.txt /tmp/requirements-cloud.txt
RUN --mount=type=cache,target=/root/.cache/pip,sharing=locked \
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && \
pip install --upgrade pip && \
pip install -r /tmp/requirements-cloud.txt
# ---- 拷整个仓库(.dockerignore 已排除 node_modules / data/users / utils_from_CNLaw-Bench 等)----
COPY . /app
# ---- 字体配置:deploy/fonts/ 可放合法获取的 msyh.ttc / msyhbd.ttc / msyhl.ttc 等。
# 即便没有真实微软雅黑,也把「微软雅黑」/ "Microsoft YaHei" 映射到中文黑体兜底,
# 防止 LibreOffice 转 PDF 时落到 DejaVu Sans。----
COPY deploy/fonts/ /usr/local/share/fonts/dataflow-edu/
RUN set -eux; \
cat > /etc/fonts/local.conf <<'EOF'
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "urn:fontconfig:fonts.dtd">
<fontconfig>
<alias binding="strong">
<family>微软雅黑</family>
<prefer>
<family>Microsoft YaHei</family>
<family>Microsoft YaHei UI</family>
<family>WenQuanYi Micro Hei</family>
<family>Noto Sans CJK SC</family>
<family>Noto Sans CJK</family>
</prefer>
</alias>
<alias binding="strong">
<family>Microsoft YaHei</family>
<prefer>
<family>Microsoft YaHei</family>
<family>Microsoft YaHei UI</family>
<family>WenQuanYi Micro Hei</family>
<family>Noto Sans CJK SC</family>
<family>Noto Sans CJK</family>
</prefer>
</alias>
<alias binding="strong">
<family>Microsoft YaHei UI</family>
<prefer>
<family>Microsoft YaHei UI</family>
<family>Microsoft YaHei</family>
<family>WenQuanYi Micro Hei</family>
<family>Noto Sans CJK SC</family>
<family>Noto Sans CJK</family>
</prefer>
</alias>
</fontconfig>
EOF
RUN set -eux; \
fc-cache -f; \
fc-match '微软雅黑'; \
fc-match 'Microsoft YaHei'
# ---- patch DataFlow/dataflow/__init__.py:仅暴露 get_logger / 注册中心,
# 不导入 .operators 与 .prompts,避免拉入 torch / transformers / etc. ----
RUN cat > /app/DataFlow/dataflow/__init__.py <<'PYEOF'
"""Cloud-slim shim of dataflow package.
仅保留 dataflow_edu 必需的导出(get_logger / 版本号 / 注册中心)。
不导入 .operators / .prompts,避免引入 torch / transformers 等重依赖。
详见 agent_notes.md 「Docker 部署」一节。
"""
from .utils import * # noqa: F401,F403
from .version import __version__, version_info # noqa: F401
from .logger import get_logger # noqa: F401
__all__ = ['__version__', 'version_info', 'get_logger']
def hello():
return "Hello from open-dataflow (cloud-slim)!"
PYEOF
# utils_from_CNLaw-Bench/mineru_ocr.py 由 .dockerignore ! 规则 + COPY 带入真实 remote 实现
# (见 agent_notes.md 「MinerU OCR」节),不再写 stub。
# ---- 构建后端 TS(用淘宝 npm 镜像 + npm 缓存 mount)----
# 注意 --include=dev:本镜像顶层 ENV NODE_ENV=production,npm ci 默认会跳过
# devDependencies,但 typescript / tsx / @types/* 都在 devDeps 里,不装就编不了。
# 编完用 npm prune --omit=dev 把 devDeps 清掉,最终运行时镜像不带 ts 工具链。
RUN --mount=type=cache,target=/root/.npm,sharing=locked \
npm config set registry https://registry.npmmirror.com && \
cd /app/webui/server && npm ci --include=dev --no-audit --no-fund && \
npm run build && \
npm prune --omit=dev
# ---- 构建前端 dist(让 Express 在 NODE_ENV=production 下走 SPA fallback)----
# 同样需要 --include=dev:vite / typescript 等构建工具都在 devDependencies。
# 构建完直接 rm -rf node_modules,dist 由 Express 在 production 下静态托管。
RUN --mount=type=cache,target=/root/.npm,sharing=locked \
cd /app/webui/frontend && npm ci --include=dev --no-audit --no-fund && \
npm run build && \
rm -rf node_modules
# ---- 数据目录占位(docker-compose 的 named volume 会挂载到这里)----
RUN mkdir -p /app/dataflow_edu/data/users /app/webui/server/data
EXPOSE 3000
# Express 在 NODE_ENV=production 下自带 SPA fallback(webui/server/src/index.ts:75-81)
CMD ["node", "/app/webui/server/dist/index.js"]