Files
ipass__ipass/Dockerfile
T
admin 5c307ba1aa iPass 山海关:Rust 动态模块版全量入库
- vanilla nginx + Rust 动态模块(取代 OpenResty+Lua),共享内存为运行期真源
- 三域名分流 18098 ssl:mdm 管理台 / lm LLM 代理 / *.dm 企业转发,共用 *.mayishangshu.cn 通配符证书(证书不入库)
- LLM 统一出口:同 Key 鉴权、上游 Key 替换、白名单、限流配额、SSE
- 回归夹具 tests/(网关 55 + LLM 34 = 89 断言,夹具 cp 覆盖重置)
- 文档:readme(16 章)+ CLAUDE.md + conf/tls/README(acme.sh 证书管理、hairpin 环回链路)
2026-09-11 15:37:09 +08:00

88 lines
3.3 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/
# 与旧版保持一致的工作目录约定,便于沿用现成的挂载与运维习惯
RUN mkdir -p /usr/local/nginx/conf /usr/local/nginx/www /usr/local/nginx/data /usr/local/nginx/logs \
&& 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;"]