From 21c0f6f12d292fad46591dca3c59287ac566d6d9 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 24 Sep 2026 18:08:19 +0800 Subject: [PATCH] fix(deploy): wire core shell + plugin dist collection; drop admin.html/alias exposure; seed plugin-config; refresh lock Co-Authored-By: Claude Opus 4.8 --- .dockerignore | 7 ++- .gitignore | 10 ++++ Dockerfile | 13 ++++- conf/nginx.conf | 38 ++++++++++---- data-seed/plugin-config.json | 1 + deploy/nginx.conf | 28 +++++++--- deploy/shell/.gitkeep | 0 deploy/static-plugins/.gitkeep | 0 rust/Cargo.lock | 1 + scripts/collect-plugin-dist.sh | 95 ++++++++++++++++++++++++++++++++++ 10 files changed, 169 insertions(+), 24 deletions(-) create mode 100644 data-seed/plugin-config.json create mode 100644 deploy/shell/.gitkeep create mode 100644 deploy/static-plugins/.gitkeep create mode 100755 scripts/collect-plugin-dist.sh diff --git a/.dockerignore b/.dockerignore index 45b09ee..78e85d9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -17,7 +17,6 @@ logs/ !scripts/container-entrypoint.sh !scripts/seed-data.sh -# deps/ipass 是 cargo workspace 必需(ipass-core + plugin-domain + ngx-rust vendor) -# 只排除子模块内的 cargo target / .git,保留所有 build.rs 等源码 -deps/**/target/ -deps/**/.git/ +# deps/ipass vendored 副本已移除(b2e59c4 起 cargo 走兄弟仓库 path 依赖), +# deploy/shell 与 deploy/static-plugins(collect-plugin-dist.sh 的收集产物) +# 是 Dockerfile COPY 源,必须留在构建上下文里,勿加忽略。 diff --git a/.gitignore b/.gitignore index ff7f5f3..3203dfb 100644 --- a/.gitignore +++ b/.gitignore @@ -16,6 +16,16 @@ # --------------------------------------------------------------------------- /data/ +# --------------------------------------------------------------------------- +# scripts/collect-plugin-dist.sh 收集的前端构建产物(docker build 前置步骤生成) +# .gitkeep 占位随仓库共享,保证 Dockerfile COPY deploy/shell、deploy/static-plugins +# 在全新 clone 后目录结构仍存在 +# --------------------------------------------------------------------------- +/deploy/shell/* +!/deploy/shell/.gitkeep +/deploy/static-plugins/* +!/deploy/static-plugins/.gitkeep + # --------------------------------------------------------------------------- # 参考资料:来源项目与第三方实现,仅本地阅读,不入库 # refs/ipass —— 被剥离的网关项目(来源) diff --git a/Dockerfile b/Dockerfile index 2c9b7fc..81248f8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,12 @@ # 加速效果:冷构建从 ~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 @@ -30,8 +34,10 @@ 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/ -COPY deps/ /build/deps/ WORKDIR /build/rust ENV NGINX_SOURCE_DIR=/src/nginx-${NGINX_VERSION} @@ -69,7 +75,10 @@ COPY --from=builder /build/rust/target/release/libsso_gateway.so /usr/local/ngin # 用 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/ +# 管理台前端(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 落盘失败 diff --git a/conf/nginx.conf b/conf/nginx.conf index da770ad..c0382a9 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -85,17 +85,35 @@ http { client_max_body_size 2m; client_body_buffer_size 1m; - # 管理台单页(只读静态资源,数据全部走 /api/admin/*) - location = /admin { - default_type text/html; - alias /usr/local/nginx/www/admin.html; - } - location = /admin/ { - default_type text/html; - alias /usr/local/nginx/www/admin.html; - } + # 管理台(核心壳 + 插件管理页,Ruling 16:admin.html 已删除,www/ 不再随本仓维护)。 + # 产物来源:scripts/collect-plugin-dist.sh 把 ipass-core www dist 收集为壳、 + # 各启用插件 www dist 收集为 /static/plugins//dist/-admin.umd.js。 + # 裸机部署:ASSEMBLY_DIR=/usr/local/nginx SHELL_SUB=www bash scripts/collect-plugin-dist.sh + # (即壳 → /usr/local/nginx/www,插件 → /usr/local/nginx/static-plugins; + # 本机联调也可 ASSEMBLY_DIR=build 收集到 build/www-shell + build/static-plugins, + # 用 nginx -p <仓根> 或按 build/ 前缀改写本段路径) + root /usr/local/nginx/www; + index index.html; + location = / { - return 302 /admin; + return 302 /admin/; + } + location = /admin { + return 302 /admin/; + } + # SPA history 路由深链兜底:/admin/* 未命中文件一律回壳 index.html。 + # 静态 location 都不开 ipass_api——开了则未认领路径被统一回 JSON 404。 + location /admin/ { + try_files $uri $uri/ /index.html; + } + # 壳入口与打包资源(index.html 引用绝对路径 /assets/*) + location = /index.html { } + location /assets/ { } + + # 插件管理页产物(壳按 /static/plugins//dist/-admin.umd.js 拉取)。 + # 严禁 alias 到 workspace 根——会连带暴露 data/*.json 等全部兄弟仓文件。 + location /static/plugins/ { + alias /usr/local/nginx/static-plugins/; } # 其余全部交给模块分发。**不要**逐条列 location: diff --git a/data-seed/plugin-config.json b/data-seed/plugin-config.json new file mode 100644 index 0000000..6d77169 --- /dev/null +++ b/data-seed/plugin-config.json @@ -0,0 +1 @@ +{"plugins":{"plugin-sso":{"enabled":true,"admin_prefix":"plugin-sso"}}} \ No newline at end of file diff --git a/deploy/nginx.conf b/deploy/nginx.conf index 2da983e..677a09f 100644 --- a/deploy/nginx.conf +++ b/deploy/nginx.conf @@ -54,9 +54,10 @@ http { listen 18098 default_server; server_name _; - # 管理台静态页(复用 sso 仓 www/) + # 管理台核心壳(ipass-core www dist;构建前由 scripts/collect-plugin-dist.sh + # 收集进 deploy/shell,Dockerfile 拷到 /usr/local/nginx/www) root /usr/local/nginx/www; - index admin.html; + index index.html; # API 网关:身份端点(/api/admin/* + /api/v1/*)由 sso 模块 dispatch location /api/ { @@ -68,21 +69,32 @@ http { ipass_api on; } + # ---- 管理台静态资源 ---- + # 注意:这些 location 均不开 ipass_api。开着的路径一旦被模块认领不到路由, + # 会统一回 JSON 404(见 gateway dispatch_api),壳的 index.html / assets 只能 + # 走 nginx 默认 content handler 读文件。 + # 管理台入口 location = / { return 302 /admin/; } - location /admin/ { - alias /usr/local/nginx/www/; - index admin.html; - } location = /admin { return 302 /admin/; } + # SPA history 路由深链兜底:/admin/* 未命中文件一律回壳 index.html + location /admin/ { + try_files $uri $uri/ /index.html; + } + # 壳的入口与打包资源(index.html 里是绝对路径 /assets/*) + location = /index.html { } + location /assets/ { } - # 插件静态资源(由 ipass-core 核心壳统一提供,所有插件共用此路径) + # 插件管理页产物:壳按 ipass-core loader.ts 约定拉取 + # /static/plugins//dist/-admin.umd.js + # (collect-plugin-dist.sh 收集到 deploy/static-plugins,Dockerfile 拷到 + # /usr/local/nginx/static-plugins;严禁 alias 到 workspace 根) location /static/plugins/ { - alias /Users/xs/Desktop/workspace/ipass/; + alias /usr/local/nginx/static-plugins/; } } } diff --git a/deploy/shell/.gitkeep b/deploy/shell/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/deploy/static-plugins/.gitkeep b/deploy/static-plugins/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/rust/Cargo.lock b/rust/Cargo.lock index 4346a95..3f435a5 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -194,6 +194,7 @@ dependencies = [ "ngx", "serde", "serde_json", + "sha2", ] [[package]] diff --git a/scripts/collect-plugin-dist.sh b/scripts/collect-plugin-dist.sh new file mode 100755 index 0000000..bdadbe2 --- /dev/null +++ b/scripts/collect-plugin-dist.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env bash +# ============================================================================ +# collect-plugin-dist.sh —— 收集管理台前端产物到可部署目录(Ruling 16) +# +# 背景:管理台已迁出本仓。 +# - 核心壳来自 ipass-core/www(index.html + assets) +# - 插件管理页是 UMD 产物,壳按 +# /static/plugins//dist/-admin.umd.js 动态加载 +# (寻址约定见 ipass-core www/src/loader.ts, 即 plugin-config.json 的键) +# Docker 构建上下文只覆盖本仓,COPY 不到兄弟仓库,故本脚本先把产物聚合进 +# $ASSEMBLY_DIR,再由 Dockerfile / nginx 静态目录消费。 +# +# 输出布局(默认 ASSEMBLY_DIR=deploy,供 docker build 前的准备步骤): +# $ASSEMBLY_DIR/shell/ ← ../ipass-core/www/dist +# $ASSEMBLY_DIR/static-plugins//dist/ ← ../ipass-/www/dist(仅 enabled) +# +# 用法: +# bash scripts/collect-plugin-dist.sh # → deploy/ +# ASSEMBLY_DIR=build bash scripts/collect-plugin-dist.sh # 本机 dev → build/(gitignored,壳目录名用 www-shell) +# ASSEMBLY_DIR=/usr/local/nginx SHELL_SUB=www sudo bash scripts/collect-plugin-dist.sh +# # 裸机部署:壳 → /usr/local/nginx/www,插件 → /usr/local/nginx/static-plugins +# +# 前置:ipass-core/www 与各启用插件仓 www 已 npm run build(dist 为最新)。 +# 启用的插件清单读 data/plugin-config.json,缺失时回退 data-seed/ 模板。 +# ============================================================================ +set -euo pipefail + +HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +ROOT="$(cd "$HERE/.." && pwd)" +IPASS_DIR="${IPASS_DIR:-$(cd "$ROOT/.." && pwd)}" +ASSEMBLY_DIR="${ASSEMBLY_DIR:-deploy}" + +# 相对路径按仓根解析,绝对路径直接使用 +case "$ASSEMBLY_DIR" in + /*) OUT="$ASSEMBLY_DIR" ;; + *) OUT="$ROOT/$ASSEMBLY_DIR" ;; +esac + +# 壳目录名:deploy 布局用 shell/,dev(build) 布局用 www-shell/,可用 SHELL_SUB 覆盖 +if [ -z "${SHELL_SUB:-}" ]; then + if [ "$ASSEMBLY_DIR" = "build" ]; then SHELL_SUB="www-shell"; else SHELL_SUB="shell"; fi +fi +PLUGINS_SUB="static-plugins" + +CONFIG="$ROOT/data/plugin-config.json" +[ -f "$CONFIG" ] || CONFIG="$ROOT/data-seed/plugin-config.json" + +PYTHON="${PYTHON:-python3}" +command -v "$PYTHON" >/dev/null 2>&1 || { echo "!! 缺 python3(解析 plugin-config.json 用)" >&2; exit 1; } + +# enabled 插件名清单(如 plugin-sso;对应仓库目录 ipass-) +PLUGINS="$("$PYTHON" - "$CONFIG" <<'PY' +import json, sys +cfg = json.load(open(sys.argv[1], encoding="utf-8")) +for name, p in cfg.get("plugins", {}).items(): + if p.get("enabled"): + print(name) +PY +)" + +# --------------------------------------------------------------------------- +# 1) 核心壳(ipass-core www dist) +# --------------------------------------------------------------------------- +SHELL_SRC="$IPASS_DIR/ipass-core/www/dist" +SHELL_OUT="$OUT/$SHELL_SUB" +[ -d "$SHELL_SRC" ] || { echo "!! core shell dist 缺失:$SHELL_SRC(先在 ipass-core/www 跑 npm run build)" >&2; exit 1; } +mkdir -p "$SHELL_OUT" +rsync -a --delete --exclude .gitkeep "$SHELL_SRC/" "$SHELL_OUT/" +echo "shell : $SHELL_SRC → $SHELL_OUT" + +# --------------------------------------------------------------------------- +# 2) 启用插件的管理页 dist +# --------------------------------------------------------------------------- +PLUGINS_OUT="$OUT/$PLUGINS_SUB" +mkdir -p "$PLUGINS_OUT" +# 清空旧收集产物但保留 .gitkeep(Dockerfile COPY 依赖目录存在) +find "$PLUGINS_OUT" -mindepth 1 -maxdepth 1 ! -name .gitkeep -exec rm -rf {} + + +count=0 +while IFS= read -r name; do + [ -n "$name" ] || continue + src="$IPASS_DIR/ipass-${name}/www/dist" + if [ ! -d "$src" ]; then + echo "!! $name:$src 缺失(先在 ipass-${name}/www 跑 npm run build),跳过" >&2 + continue + fi + mkdir -p "$PLUGINS_OUT/$name/dist" + rsync -a --delete "$src/" "$PLUGINS_OUT/$name/dist/" + echo "plugin: $src → $PLUGINS_OUT/$name/dist" + count=$((count + 1)) +done <