chore: psycopg 改用 binary extra,精简 Dockerfile 的 apt 依赖

psycopg[binary] 替代并列声明的 psycopg + psycopg-binary。上游的
binary extra 是 psycopg-binary==<同版本> 的精确 pin,而原来两条各自
带范围,没有东西保证它们同步——单独升级其中一个就可能凑出上游没测过
的组合。解析结果不变,requirements.txt 只多了 extra 自带的
implementation_name != 'pypy' 标记。

apt 依赖从 10 个降到 4 个:
- curl / unzip / openssl:全仓库零引用。解压走 Python zipfile,
  健康检查走 xmlrpc,openssl 装的是 CLI 而 Python 要的是 libssl
- libpq5:psycopg_binary.libs 自带 libpq.so.5.18,容器内实测
  psycopg.pq.__impl__ == binary
- libjpeg62-turbo:pillow.libs 自带 libjpeg.so.62
- zlib1g:base 镜像的 CPython 已经带着

保留 ca-certificates(smtplib 走 TLS 时读系统信任库,不是 certifi)、
clang-format(submission/utils.py 调用)、passwd(entrypoint 建账号)、
supervisor。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
2026-08-05 23:11:33 -06:00
parent 8557f8a5f5
commit 8d35d5c2de
4 changed files with 13 additions and 15 deletions

View File

@@ -19,17 +19,13 @@ if [ -f /etc/apt/sources.list ]; then
sed -i 's|deb.debian.org|mirrors.tuna.tsinghua.edu.cn|g; s|security.debian.org|mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list sed -i 's|deb.debian.org|mirrors.tuna.tsinghua.edu.cn|g; s|security.debian.org|mirrors.tuna.tsinghua.edu.cn|g' /etc/apt/sources.list
fi fi
apt-get update apt-get update
# libpq / libjpeg 都在 wheel 里自带psycopg_binary.libs、pillow.libs不装系统版。
# zlib 由 base 镜像的 CPython 带着Pillow 用的是它。
apt-get install -y --no-install-recommends \ apt-get install -y --no-install-recommends \
ca-certificates \ ca-certificates \
clang-format \ clang-format \
curl \
libjpeg62-turbo \
libpq5 \
openssl \
passwd \ passwd \
supervisor \ supervisor
unzip \
zlib1g
pip install -r /app/deploy/requirements.txt pip install -r /app/deploy/requirements.txt
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
EOS EOS

View File

@@ -321,7 +321,7 @@ psycopg==3.3.4 \
--hash=sha256:b6bbc25ccf05c8fad3b061d9db2ef0909a555171b84b07f29458a447253d679a \ --hash=sha256:b6bbc25ccf05c8fad3b061d9db2ef0909a555171b84b07f29458a447253d679a \
--hash=sha256:e21207764952cff81b6b8bdacad9a3939f2793367fdac2987b3aac36a651b5bc --hash=sha256:e21207764952cff81b6b8bdacad9a3939f2793367fdac2987b3aac36a651b5bc
# via onlinejudge # via onlinejudge
psycopg-binary==3.3.4 \ psycopg-binary==3.3.4 ; implementation_name != 'pypy' \
--hash=sha256:018fbed325936da502feb546642c982dcc4b9ffdea32dfef78dbf3b7f7ad4070 \ --hash=sha256:018fbed325936da502feb546642c982dcc4b9ffdea32dfef78dbf3b7f7ad4070 \
--hash=sha256:136f199a407b5348b9b857c504aff60c77622a28482e7195839ce1b51238c4cc \ --hash=sha256:136f199a407b5348b9b857c504aff60c77622a28482e7195839ce1b51238c4cc \
--hash=sha256:17a21953a9e5ff3a16dab692625a3676e2f101db5e40072f39dbee2250194d68 \ --hash=sha256:17a21953a9e5ff3a16dab692625a3676e2f101db5e40072f39dbee2250194d68 \
@@ -355,7 +355,7 @@ psycopg-binary==3.3.4 \
--hash=sha256:eb05ee1c2b817d27c537333224c9e83c7afb86fe7296ba970990068baf819b16 \ --hash=sha256:eb05ee1c2b817d27c537333224c9e83c7afb86fe7296ba970990068baf819b16 \
--hash=sha256:ee17a2cf4943cde261adfad1bbc5bf38d6b3776d7afff74c7cabcbeaeb08c260 \ --hash=sha256:ee17a2cf4943cde261adfad1bbc5bf38d6b3776d7afff74c7cabcbeaeb08c260 \
--hash=sha256:fbd1d4ed566895ad2d3bf4ddfd8bae90026930ddf29df3b9d91d32c8c47866a7 --hash=sha256:fbd1d4ed566895ad2d3bf4ddfd8bae90026930ddf29df3b9d91d32c8c47866a7
# via onlinejudge # via psycopg
pydantic==2.13.3 \ pydantic==2.13.3 \
--hash=sha256:6db14ac8dfc9a1e57f87ea2c0de670c251240f43cb0c30a5130e9720dc612927 \ --hash=sha256:6db14ac8dfc9a1e57f87ea2c0de670c251240f43cb0c30a5130e9720dc612927 \
--hash=sha256:af09e9d1d09f4e7fe37145c1f577e1d61ceb9a41924bf0094a36506285d0a84d --hash=sha256:af09e9d1d09f4e7fe37145c1f577e1d61ceb9a41924bf0094a36506285d0a84d

View File

@@ -17,8 +17,7 @@ dependencies = [
"httpx>=0.28.1,<1", "httpx>=0.28.1,<1",
"openai>=2.34.0,<3", "openai>=2.34.0,<3",
"pillow>=12.2.0,<13", "pillow>=12.2.0,<13",
"psycopg>=3.3.4,<4", "psycopg[binary]>=3.3.4,<4",
"psycopg-binary>=3.3.4,<4",
"sentry-sdk[django]>=2.0.0,<3", "sentry-sdk[django]>=2.0.0,<3",
"tree-sitter>=0.25.2", "tree-sitter>=0.25.2",
"tree-sitter-c>=0.24.2", "tree-sitter-c>=0.24.2",

11
uv.lock generated
View File

@@ -395,8 +395,7 @@ dependencies = [
{ name = "jieba" }, { name = "jieba" },
{ name = "openai" }, { name = "openai" },
{ name = "pillow" }, { name = "pillow" },
{ name = "psycopg" }, { name = "psycopg", extra = ["binary"] },
{ name = "psycopg-binary" },
{ name = "sentry-sdk", extra = ["django"] }, { name = "sentry-sdk", extra = ["django"] },
{ name = "tree-sitter" }, { name = "tree-sitter" },
{ name = "tree-sitter-c" }, { name = "tree-sitter-c" },
@@ -425,8 +424,7 @@ requires-dist = [
{ name = "jieba", specifier = ">=0.42.1" }, { name = "jieba", specifier = ">=0.42.1" },
{ name = "openai", specifier = ">=2.34.0,<3" }, { name = "openai", specifier = ">=2.34.0,<3" },
{ name = "pillow", specifier = ">=12.2.0,<13" }, { name = "pillow", specifier = ">=12.2.0,<13" },
{ name = "psycopg", specifier = ">=3.3.4,<4" }, { name = "psycopg", extras = ["binary"], specifier = ">=3.3.4,<4" },
{ name = "psycopg-binary", specifier = ">=3.3.4,<4" },
{ name = "sentry-sdk", extras = ["django"], specifier = ">=2.0.0,<3" }, { name = "sentry-sdk", extras = ["django"], specifier = ">=2.0.0,<3" },
{ name = "tree-sitter", specifier = ">=0.25.2" }, { name = "tree-sitter", specifier = ">=0.25.2" },
{ name = "tree-sitter-c", specifier = ">=0.24.2" }, { name = "tree-sitter-c", specifier = ">=0.24.2" },
@@ -548,6 +546,11 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/5c/e0/7b3dee031daae7743609ce3c746565d4a3ed7c2c186479eb48e34e838c64/psycopg-3.3.4-py3-none-any.whl", hash = "sha256:b6bbc25ccf05c8fad3b061d9db2ef0909a555171b84b07f29458a447253d679a", size = 213001, upload-time = "2026-05-01T23:20:50.816Z" }, { url = "https://files.pythonhosted.org/packages/5c/e0/7b3dee031daae7743609ce3c746565d4a3ed7c2c186479eb48e34e838c64/psycopg-3.3.4-py3-none-any.whl", hash = "sha256:b6bbc25ccf05c8fad3b061d9db2ef0909a555171b84b07f29458a447253d679a", size = 213001, upload-time = "2026-05-01T23:20:50.816Z" },
] ]
[package.optional-dependencies]
binary = [
{ name = "psycopg-binary", marker = "implementation_name != 'pypy'" },
]
[[package]] [[package]]
name = "psycopg-binary" name = "psycopg-binary"
version = "3.3.4" version = "3.3.4"