From 8d35d5c2de3e94916864aed002e4e779892f0c74 Mon Sep 17 00:00:00 2001 From: yuetsh <517252939@qq.com> Date: Wed, 5 Aug 2026 23:11:33 -0600 Subject: [PATCH] =?UTF-8?q?chore:=20psycopg=20=E6=94=B9=E7=94=A8=20binary?= =?UTF-8?q?=20extra=EF=BC=8C=E7=B2=BE=E7=AE=80=20Dockerfile=20=E7=9A=84=20?= =?UTF-8?q?apt=20=E4=BE=9D=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- Dockerfile | 10 +++------- deploy/requirements.txt | 4 ++-- pyproject.toml | 3 +-- uv.lock | 11 +++++++---- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/Dockerfile b/Dockerfile index 3cd1198..ddc91a0 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 fi apt-get update +# libpq / libjpeg 都在 wheel 里自带(psycopg_binary.libs、pillow.libs),不装系统版。 +# zlib 由 base 镜像的 CPython 带着,Pillow 用的是它。 apt-get install -y --no-install-recommends \ ca-certificates \ clang-format \ - curl \ - libjpeg62-turbo \ - libpq5 \ - openssl \ passwd \ - supervisor \ - unzip \ - zlib1g + supervisor pip install -r /app/deploy/requirements.txt rm -rf /var/lib/apt/lists/* EOS diff --git a/deploy/requirements.txt b/deploy/requirements.txt index 903295c..72c8c9a 100644 --- a/deploy/requirements.txt +++ b/deploy/requirements.txt @@ -321,7 +321,7 @@ psycopg==3.3.4 \ --hash=sha256:b6bbc25ccf05c8fad3b061d9db2ef0909a555171b84b07f29458a447253d679a \ --hash=sha256:e21207764952cff81b6b8bdacad9a3939f2793367fdac2987b3aac36a651b5bc # via onlinejudge -psycopg-binary==3.3.4 \ +psycopg-binary==3.3.4 ; implementation_name != 'pypy' \ --hash=sha256:018fbed325936da502feb546642c982dcc4b9ffdea32dfef78dbf3b7f7ad4070 \ --hash=sha256:136f199a407b5348b9b857c504aff60c77622a28482e7195839ce1b51238c4cc \ --hash=sha256:17a21953a9e5ff3a16dab692625a3676e2f101db5e40072f39dbee2250194d68 \ @@ -355,7 +355,7 @@ psycopg-binary==3.3.4 \ --hash=sha256:eb05ee1c2b817d27c537333224c9e83c7afb86fe7296ba970990068baf819b16 \ --hash=sha256:ee17a2cf4943cde261adfad1bbc5bf38d6b3776d7afff74c7cabcbeaeb08c260 \ --hash=sha256:fbd1d4ed566895ad2d3bf4ddfd8bae90026930ddf29df3b9d91d32c8c47866a7 - # via onlinejudge + # via psycopg pydantic==2.13.3 \ --hash=sha256:6db14ac8dfc9a1e57f87ea2c0de670c251240f43cb0c30a5130e9720dc612927 \ --hash=sha256:af09e9d1d09f4e7fe37145c1f577e1d61ceb9a41924bf0094a36506285d0a84d diff --git a/pyproject.toml b/pyproject.toml index c9cc3ce..d3a1e3e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,8 +17,7 @@ dependencies = [ "httpx>=0.28.1,<1", "openai>=2.34.0,<3", "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", "tree-sitter>=0.25.2", "tree-sitter-c>=0.24.2", diff --git a/uv.lock b/uv.lock index 1c17856..460de85 100644 --- a/uv.lock +++ b/uv.lock @@ -395,8 +395,7 @@ dependencies = [ { name = "jieba" }, { name = "openai" }, { name = "pillow" }, - { name = "psycopg" }, - { name = "psycopg-binary" }, + { name = "psycopg", extra = ["binary"] }, { name = "sentry-sdk", extra = ["django"] }, { name = "tree-sitter" }, { name = "tree-sitter-c" }, @@ -425,8 +424,7 @@ requires-dist = [ { name = "jieba", specifier = ">=0.42.1" }, { name = "openai", specifier = ">=2.34.0,<3" }, { name = "pillow", specifier = ">=12.2.0,<13" }, - { name = "psycopg", specifier = ">=3.3.4,<4" }, - { name = "psycopg-binary", specifier = ">=3.3.4,<4" }, + { name = "psycopg", extras = ["binary"], specifier = ">=3.3.4,<4" }, { name = "sentry-sdk", extras = ["django"], specifier = ">=2.0.0,<3" }, { name = "tree-sitter", specifier = ">=0.25.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" }, ] +[package.optional-dependencies] +binary = [ + { name = "psycopg-binary", marker = "implementation_name != 'pypy'" }, +] + [[package]] name = "psycopg-binary" version = "3.3.4"