Files
OnlineJudge/Dockerfile
yuetsh 92e1c2b75d refactor(deploy): 容器内 nginx 换成 Caddy
TLS 和域名由前面的 Nginx Proxy Manager 负责,容器里这层只做静态文件
和反代,用 Caddy 配置更短,也消掉了两个坑:add_header 不继承、
entrypoint 里 __IP_HEADER__ 的 sed 替换。

- deploy/nginx/ 四个配置文件合并成一个 deploy/caddy/Caddyfile
- Dockerfile 去掉 nginx 包,改从官方镜像拷 Caddy 静态二进制
- supervisord 的 nginx 程序换成 caddy,跑在非特权的 server 账号下
- entrypoint 删掉自签证书、http_locations.conf 软链、IP header sed

行为对齐:body 上限写 200MiB 才等于 nginx 的 200M;心跳和 /assets/
继续不记访问日志;安全头、缓存策略、gzip 覆盖范围保持不变。

两处行为变化:
- 访问日志变成 JSON,路径 /data/log/caddy_access.log
- X-Accel-Buffering 是 nginx 私有头,AI 的 SSE 改由 flush_interval -1
  保证不缓冲,上线需实测

FORCE_HTTPS 和 LOWER_IP_HEADER 两个环境变量随之作废,真实 IP 改由
trusted_proxies + {client_ip} 从 NPM 的 XFF 解析。

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-05 09:50:46 -06:00

47 lines
1.4 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
apt-get install -y --no-install-recommends \
ca-certificates \
clang-format \
curl \
libjpeg62-turbo \
libpq5 \
openssl \
passwd \
supervisor \
unzip \
zlib1g
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" ]