Files
sso/deploy/Dockerfile
T
adminandClaude Code f3df8b93a5 fix(deploy): build 时修正精简版 Dockerfile / nginx.conf 残留
**影响**:build 阶段 (`bash deploy/build.sh --no-push`) 报 Dockerfile COPY 错误,
镜像未生成。修正后镜像 `ipass-sso-v0.6.0` 本地构建成功,nginx -t 通过、
容器启动正常、`/admin/` 与 `/.well-known/openid-configuration` 双 200。

**改动**:
- `deploy/Dockerfile`:
  - 删 `COPY deploy/custom/ ...`(精简版无 deploy/custom/ 目录)
  - 删 `COPY deploy/legacy/ ...`(精简版无 deploy/legacy/ 目录)
  - `EXPOSE 18098 18099` → `EXPOSE 18098`(精简版没 LLM 数据面,18099 用不到)
- `deploy/nginx.conf`:
  - 删 `location /static/custom/ {...}`(精简版无 static-custom/)
  - 删 `location /legacy/ {...}`(精简版不集成老管理台)

**设计**:上一步 commit 漏了 Dockerfile / nginx.conf 与文件系统的同步:
rsync 自 ipass-all 时连带 rsync 来了 deploy/custom/ 与 deploy/legacy/,
后续又手动 rm 掉了这两个目录,但 Dockerfile 里的 COPY 与 nginx.conf
里的 alias location 没同步清。

Co-Authored-By: Claude Code <[email protected]>
2026-09-30 12:05:19 +08:00

120 lines
5.6 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)
#
# 从 ipass-all 派生的精简发行版:只装 ipass-core + ipass-plugin-sso(2 个 named
# context),gateway 装配层把内核 + sso 编进单个 libipass_sso_gateway.so。
#
# 设计:
# - builder 阶段:FROM crpi-yscq976uwza88qap.cn-shenzhen.personal.cr.aliyuncs.com/ssw188/nginx:1.30.4-rust-1.89
# base 已含 rust 1.89 + 已 configure/make 的 nginx 1.30.4 + pcre 8.45 + 编译链,
# 这里只跑 cargo build
# - runtime 阶段:debian:bookworm-slim,只带 nginx 二进制 + 模块 + 静态资源
#
# 构建命令(context = 本仓根;2 个 named context 缺一不可):
# bash scripts/collect-plugin-dist.sh # 前置:收集壳 + sso 管理页 dist
# docker build \
# --build-context ipass-core=../ipass-core \
# --build-context ipass-plugin-sso=../ipass-plugin-sso \
# -t crpi-yscq976uwza88qap.cn-shenzhen.personal.cr.aliyuncs.com/ssw188/nginx:ipass-sso-v0.6.0 .
#
# named context 落位约定:COPY 到 /ipass-core、/ipass-plugin-sso —— builder 的
# WORKDIR 是 /build,rust/Cargo.toml 里 `../../ipass-core/...` 与插件自己的
# `../ipass-core/...` 等 path 依赖按宿主机「同级目录」布局原样解析。
# ⚠️ 每个插件仓只 COPY 编译所需子集(Cargo.toml/src/vendor/rules),
# 避开几百 MB 的 target/ 与 data/。
#
# 升级 nginx/rust 版本时:先跑 ipass-sso/deploy/build-base-image.sh 推新 base,
# 再 bump 此处 FROM 的 tag。
# syntax=docker/dockerfile:1.7
ARG BASE_TAG=1.30.4-rust-1.89
# ===========================================================================
# builder: 复用 rust-nginx-base + Rust 模块编译(nginx 二进制 base 里已 make 好)
# ===========================================================================
FROM crpi-yscq976uwza88qap.cn-shenzhen.personal.cr.aliyuncs.com/ssw188/nginx:${BASE_TAG} AS builder
WORKDIR /build
# 内核(含 vendored ngx-rust 与 pcre 路径依赖的源码树约定)
COPY --from=ipass-core /rust/Cargo.toml /rust/Cargo.lock /ipass-core/rust/
COPY --from=ipass-core /rust/crates/ /ipass-core/rust/crates/
COPY --from=ipass-core /rust/vendor/ /ipass-core/rust/vendor/
# SSO 插件 crate(只 1 个 plugin)
COPY --from=ipass-plugin-sso /Cargo.toml /Cargo.lock /ipass-plugin-sso/
COPY --from=ipass-plugin-sso /src/ /ipass-plugin-sso/src/
# 装配层(本仓)
COPY rust/ /build/rust/
# cargo 国内镜像源(rsproxy):base 镜像没带 cargo 配置,直连 crates.io
# 在国内网络下会长时间悬挂在下载阶段(ipass-sso 同款)。
RUN printf '[source.crates-io]\nreplace-with = "rsproxy-sparse"\n\n[source.rsproxy-sparse]\nregistry = "sparse+https://rsproxy.cn/index/"\n\n[net]\ngit-fetch-with-cli = true\n' \
> "${CARGO_HOME:-/usr/local/cargo}/config.toml"
WORKDIR /build/rust
# nginx 源码树路径与 base 镜像内一致(bindgen 从 objs/Makefile 抽 -I)
ENV NGINX_SOURCE_DIR=/src/nginx-1.30.4
ENV NGINX_BUILD_DIR=/src/nginx-1.30.4/objs
ENV CARGO_TARGET_DIR=/build/rust/target
RUN cargo build --release 2>&1 | tail -15
# ===========================================================================
# 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=Asia/Shanghai,util::day_id 按上海时区 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/libipass_sso_gateway.so /usr/local/nginx/modules/
# 生产配置(deploy/nginx.conf:全插件 location 布局 + 非 root 适配)
COPY deploy/nginx.conf /usr/local/nginx/conf/nginx.conf
# 管理台前端(Ruling 16):构建前由 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/
# 装配层自定义页清单(精简版不挂自定义页,无 deploy/custom/)
# 老管理台多页应用(精简版不集成老管理台,无 deploy/legacy/)
# 种子数据(admin/alice + OAuth 接入方 + 插件启停注册表)
COPY data-seed/ /usr/local/nginx/data-seed/
# 目录与属主:k8s 租户准入强制 runAsUser=10106,data 与 /tmp/nginx 必须
# 预先可写(挂 PVC 后属主由 fsGroup=10106 接管,chown 只保无卷直跑)。
# 日志走 /dev/std* 符号链接(kubectl logs 直接可见)。
RUN mkdir -p /usr/local/nginx/data /usr/local/nginx/logs /tmp/nginx \
&& chown -R 10106:10106 /usr/local/nginx/data /tmp/nginx \
&& 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;"]