Files
ipass__ipass/Dockerfile
T
admin eea0a15b9c 部署构建配置:.dockerignore / .gitignore(deploy) / Dockerfile 镜像分层
- 新增 .dockerignore,构建上下文减脂(排除 build/tests/.run/data/logs/rust/target 等)
- .gitignore 排除 deploy/:种子数据含 API Key 与上游真 Key,只进镜像不入库
- Dockerfile 将 conf/nginx.conf、conf/tls/、www/、deploy/data-seed/ 拷入镜像
  凭据与正式证书不进版本库,随镜像分发时勿推公共仓库
2026-09-11 16:15:39 +08:00

95 lines
3.7 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/
# 与旧版保持一致的工作目录约定,便于沿用现成的挂载与运维习惯
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;"]