Files
sso/Dockerfile
T

101 lines
4.8 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-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 仓根):
# bash scripts/collect-plugin-dist.sh # 前置:收集 core shell + 启用插件 dist 到 deploy/(Ruling 16)
# docker build -t ipass-sso:dev .
#
# 管理台前端不再随本仓维护:壳来自 ipass-core/www,插件管理页来自各 ipass-plugin-*/www,
# 由上述脚本聚合进 deploy/shell 与 deploy/static-plugins 后由下方 COPY 进镜像。
#
# 升级 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
# deps/(vendored ipass)已随 b2e59c4 移除,cargo 改走兄弟仓库 path 依赖;
# 该 path 依赖不在本 context 内,容器内 cargo build 需后续用 BuildKit named context
# 补 ipass-core / ipass-plugin-sso(与 ipass-ssw 同一遗留,见 task 3.9 验收项)。
COPY rust/ /build/rust/
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
# 管理台前端(Ruling 16):本仓不再有 www/,构建前由 scripts/collect-plugin-dist.sh
# 把 ipass-core 壳收集进 deploy/shell、各启用插件 dist 收集进 deploy/static-plugins。
COPY deploy/shell/ /usr/local/nginx/www/
COPY deploy/static-plugins/ /usr/local/nginx/static-plugins/
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;"]