Files
sso/Dockerfile
T
admin 67a8e731cc feat(deploy): 容器化构建(多阶段 Dockerfile + compose + entrypoint + 共用 base)
- 主镜像 Dockerfile:多阶段构建,复用 rust-nginx-base 镜像(nginx 1.30.4 + rust 1.89
  + 已 configure 的 pcre/openssl/编译链),冷构建从 ~17min 压到 ~5min
- deploy/nginx.conf:容器内 nginx 配置(端口 18098 / /usr/local/nginx/... 路径)
- docker-compose.yml:本机一键起服务(端口 8881→18098)+ S10 健康探测
- scripts/container-entrypoint.sh:容器入口脚本(启动前 healthcheck 等)
- .dockerignore:避免把 build/target/data/refs 误打进镜像
- deploy/Dockerfile.base:rust-nginx-base 镜像定义(apt 链 + nginx/pcre 源码 + 已
  ./configure 过的源码树)
- deploy/build-base-image.sh:构建并推送 base 镜像到阿里云 CR
  (crpi-yscq976uwza88qap.cn-shenzhen.personal.cr.aliyuncs.com/ssw188/nginx)
2026-09-24 16:27:05 +08:00

92 lines
3.9 KiB
Docker
Raw Permalink 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-sso 网关镜像 —— 多阶段构建(复用 rust-nginx-base)
#
# 设计:
# - builder 阶段:FROM crpi-yscq976uwza88qap.cn-shenzhen.personal.cr.aliyuncs.com/ssw188/nginx:1.30.4-rust-1.89
# - base 镜像已含 rust 1.89 + 已 configure 的 nginx 1.30.4 + pcre 8.45 + apt 编译链
# - 不需要再次 apt install / curl / configure nginx(这些已在 base 里完成)
# - 这里只跑 nginx make + cargo build --release
# - runtime 阶段:debian:bookworm-slim,只装运行时库 + COPY 编译产物
#
# 加速效果:冷构建从 ~17min(apt + curl + configure + cargo)压到 ~5min(仅 cargo build + make)
#
# 构建命令(context = sso 仓根):
# docker build -t ipass-sso:dev .
#
# 升级 nginx/rust 版本时:先跑 deploy/build-base-image.sh 推新 base,再 bump 此处 FROM 的 tag
# syntax=docker/dockerfile:1.7
ARG NGINX_VERSION=1.30.4
ARG BASE_TAG=1.30.4-rust-1.89
# ===========================================================================
# builder: 复用 rust-nginx-base + 编译 nginx 二进制 + Rust 模块
# ===========================================================================
FROM crpi-yscq976uwza88qap.cn-shenzhen.personal.cr.aliyuncs.com/ssw188/nginx:${BASE_TAG} AS builder
# ⚠️ ARG 必须每个 stage 内重新声明才能用 —— 顶层的 NGINX_VERSION 在 builder 内不可见
ARG NGINX_VERSION=1.30.4
# base 镜像里 nginx 已 configure + make 过;这里只跑 Rust 模块编译
# --- Rust 动态模块 -----------------------------------------------------------
WORKDIR /build
COPY rust/ /build/rust/
COPY deps/ /build/deps/
WORKDIR /build/rust
ENV NGINX_SOURCE_DIR=/src/nginx-${NGINX_VERSION}
ENV NGINX_BUILD_DIR=/src/nginx-${NGINX_VERSION}/objs
ENV CARGO_TARGET_DIR=/build/rust/target
RUN cargo build --release 2>&1 | tail -10
# ===========================================================================
# runtime: 极简镜像,只带 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 \
tzdata \
python3 \
&& rm -rf /var/lib/apt/lists/*
# 与 ipass 一致:容器默认 TZ=UTC,所有时间显示比北京慢 8h。
# TZ=Asia/Shanghai 后 util::day_id 走 localtime_r 按上海时区 0:00 切日。
ENV TZ=Asia/Shanghai
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/libsso_gateway.so /usr/local/nginx/modules/
# 配置 / 证书(生产证书随镜像分发;勿把镜像推到公共仓库)
# 用 deploy/nginx.conf 替代 sso 仓 conf/nginx.test.conf:后者引用 ipass_proxy
# (plugin-domain 注册),sso 模块不编译 plugin-domain。
COPY deploy/nginx.conf /usr/local/nginx/conf/nginx.conf
COPY www/ /usr/local/nginx/www/
COPY data-seed/ /usr/local/nginx/data-seed/
# 数据目录:worker 是 nobody(uid 65534),必须可写,否则 seed-data 落盘失败
RUN mkdir -p /usr/local/nginx/data /usr/local/nginx/logs \
&& chown -R 65534:65534 /usr/local/nginx/data \
&& ln -sf /dev/stdout /usr/local/nginx/logs/access.log \
&& ln -sf /dev/stderr /usr/local/nginx/logs/error.log
# 首次启动播种 admin/alice + 渲染配置 + 起 nginx
COPY scripts/container-entrypoint.sh /usr/local/nginx/scripts/container-entrypoint.sh
COPY scripts/seed-data.sh /usr/local/nginx/scripts/seed-data.sh
RUN chmod +x /usr/local/nginx/scripts/container-entrypoint.sh /usr/local/nginx/scripts/seed-data.sh
WORKDIR /usr/local/nginx
EXPOSE 18098
STOPSIGNAL SIGQUIT
ENTRYPOINT ["/usr/local/nginx/scripts/container-entrypoint.sh"]
CMD ["nginx", "-g", "daemon off;"]