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>
43 lines
1.5 KiB
Docker
43 lines
1.5 KiB
Docker
FROM python:3.13-slim
|
||
ARG TARGETARCH
|
||
ARG TARGETVARIANT
|
||
|
||
ENV OJ_ENV=production
|
||
WORKDIR /app
|
||
|
||
COPY ./deploy/requirements.txt /app/deploy/
|
||
|
||
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=apt-cache-$TARGETARCH$TARGETVARIANT-final \
|
||
--mount=type=cache,target=/root/.cache/pip,id=pip-cache-$TARGETARCH$TARGETVARIANT-final \
|
||
<<EOS
|
||
set -ex
|
||
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
|
||
if [ -f /etc/apt/sources.list.d/debian.sources ]; 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.d/debian.sources
|
||
fi
|
||
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 \
|
||
passwd \
|
||
supervisor
|
||
pip install -r /app/deploy/requirements.txt
|
||
rm -rf /var/lib/apt/lists/*
|
||
EOS
|
||
|
||
# Caddy 官方镜像里是静态链接的 Go 二进制,直接拷进 slim 就能跑,不需要额外依赖。
|
||
COPY --from=caddy:2-alpine /usr/bin/caddy /usr/bin/caddy
|
||
|
||
COPY --chmod=755 ./ /app/
|
||
RUN mkdir -p /app/dist/
|
||
|
||
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
|
||
CMD python3 /app/deploy/health_check.py
|
||
EXPOSE 8000
|
||
ENTRYPOINT [ "/app/deploy/entrypoint.sh" ]
|