Files
ssw__ipass/Dockerfile
T
admin 401f9be351 feat(llm): token 计量 + 对话审计日志(10GiB 容量触发式清理)
- llm_usage.rs: body filter 旁路(FFI 注册 top_body_filter,无需额外 C 模块),
  透传 SSE 的同时抓尾部 usage chunk(OpenAI stream_options.include_usage / Anthropic message_delta),
  解析 prompt/completion tokens 写 shm utt:/utms: 键
- llm_audit.rs: log 阶段把请求体临时文件复制进审计目录(audit/ = data 兄弟目录),
  meta.jsonl 记 user/slot/status/token;10 GiB 容量阈值触发式清理,按日期目录从最旧删起
- conf/nginx.conf: LLM location 去掉 proxy_request_buffering off(它管请求体方向、
  与 SSE 无关且与 client_body_in_file_only 互斥),SSE 流式由 proxy_buffering off 保障
- stats/api: 用量接口增加 tokens 维度(today/total per user per slot)
- ipass-agent.py: 容器重建时自动挂审计卷(宿主 audit/ = data 兄弟目录,自动建目录)
- update-agent-face.sh: 控制面自更新脚本(.11 上一行命令完成下载/备份/校验/重启/自检)
- tests: LLM 117/117(+6: 审计 4 + token 2)、网关 90/90,共 207 全绿
2026-09-12 17:59:34 +08:00

98 lines
4.0 KiB
Docker
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ipass-gateway —— 多阶段构建
#
# 与旧版(官方 openresty 镜像)的区别:这里必须自己编译 nginx。
# 原因见 CLAUDE.md:ngx-rust 官方明确要求「针对生产上真正要用的那份 nginx 源码 +
# 完全相同的 configure 参数」编译模块,否则 bindgen 看到的符号/API 与实际运行时不一致。
# OpenResty 的 nginx 打了大量补丁,不属于受支持组合,因此本项目改用官方 nginx。
# ---------------------------------------------------------------------------
# 构建阶段:编译 nginx + 编译 Rust 动态模块
# ---------------------------------------------------------------------------
FROM rust:1.89-slim-bookworm AS builder
ARG NGINX_VERSION=1.30.4
# nginx 构建依赖 + bindgen 需要的 libclang + 下载工具
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libpcre2-dev \
zlib1g-dev \
libssl-dev \
clang \
libclang-dev \
pkg-config \
curl \
ca-certificates \
xz-utils \
&& rm -rf /var/lib/apt/lists/*
# 1) 拉取并编译 nginx(objs/ 里的头文件是 bindgen 的输入)
WORKDIR /src
RUN curl -fsSL "https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz" -o nginx.tar.gz \
&& tar -xzf nginx.tar.gz \
&& rm nginx.tar.gz
WORKDIR /src/nginx-${NGINX_VERSION}
RUN ./configure \
--prefix=/usr/local/nginx \
--with-pcre \
--with-http_realip_module \
--with-http_ssl_module \
--without-http_gzip_module \
--without-http_ssi_module \
--without-http_userid_module \
--without-http_autoindex_module \
--without-http_geo_module \
--without-http_split_clients_module \
--without-http_referer_module \
--without-http_uwsgi_module \
--without-http_scgi_module \
--without-http_grpc_module \
&& make -j"$(nproc)"
# 2) 编译 Rust 动态模块。只需 configure 过的源码树 + objs/,不必等 nginx 编完。
WORKDIR /build/rust
COPY rust/ ./
RUN NGINX_SOURCE_DIR="/src/nginx-${NGINX_VERSION}" \
NGINX_BUILD_DIR="/src/nginx-${NGINX_VERSION}/objs" \
cargo build --release
# ---------------------------------------------------------------------------
# 运行阶段:只带 nginx 二进制 + 模块 + 静态资源
# ---------------------------------------------------------------------------
FROM debian:bookworm-slim AS runtime
ARG NGINX_VERSION=1.30.4
RUN apt-get update && apt-get install -y --no-install-recommends \
libpcre2-8-0 \
zlib1g \
libssl3 \
ca-certificates \
curl \
&& rm -rf /var/lib/apt/lists/*
COPY --from=builder /src/nginx-${NGINX_VERSION}/objs/nginx /usr/local/nginx/sbin/nginx
COPY --from=builder /src/nginx-${NGINX_VERSION}/conf/mime.types /usr/local/nginx/conf/mime.types
COPY --from=builder /build/rust/target/release/libipass_gateway.so /usr/local/nginx/modules/
# 配置 / 证书(正式证书随镜像分发;勿把镜像推到公共仓库)/ 管理台静态页 / 种子数据
# conf/nginx.conf 里的 include tls/*.conf 不递归,子目录内的供应商 .conf 不会被误加载
COPY conf/nginx.conf /usr/local/nginx/conf/nginx.conf
COPY conf/tls/ /usr/local/nginx/conf/tls/
COPY www/ /usr/local/nginx/www/
COPY deploy/data-seed/ /usr/local/nginx/data/
# 与旧版保持一致的工作目录约定,便于沿用现成的挂载与运维习惯
# data 必须对 worker(默认 nobody)可写:状态写穿 JSON 依赖它
# audit 同理:LLM 对话审计落盘目录(docs/llm/AUDIT_LOG.md),生产建议挂宿主机卷
RUN mkdir -p /usr/local/nginx/conf /usr/local/nginx/www /usr/local/nginx/data /usr/local/nginx/audit /usr/local/nginx/logs \
&& chown -R nobody:nogroup /usr/local/nginx/data /usr/local/nginx/audit \
&& ln -sf /dev/stdout /usr/local/nginx/logs/access.log \
&& ln -sf /dev/stderr /usr/local/nginx/logs/error.log
WORKDIR /usr/local/nginx
EXPOSE 80 18098 443
STOPSIGNAL SIGQUIT
CMD ["/usr/local/nginx/sbin/nginx", "-g", "daemon off;"]