pipeline-app/README.md

129 lines
6.3 KiB
Markdown
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.

# Pipeline-App — 独立产线后端服务
基于 ahserver 的独立产线管理后端,提供产线定义、运营管理和分销功能。
## 架构
- **部署模式**:独立 ahserver Web 应用(端口 9090
- **数据库**`pipeline`(独立数据库,非 sage
- **认证**:复用 Sage RBACSAGE_RBAC_DB 环境变量指向 sage 库)
- **模块数**3 个业务模块
## 业务模块
### pipeline_core — 产线核心定义
产线的创建、步骤编排和版本管理。
| 表 | 说明 |
|----|------|
| `pipelines` | 产线主表名称、描述、状态、owner |
| `pipeline_steps` | 步骤表(产线下的有序步骤,支持并行/串行) |
| `pipeline_versions` | 版本表(产线快照,支持发布/回滚) |
**API 端点**pipelines/pipeline_steps/pipeline_versions 的 CRUD + pipeline_publish发布版本
### pipeline_ops — 产线运营管理
定价、供应量配置和使用记录。
| 表 | 说明 |
|----|------|
| `pipeline_pricing` | 定价表(按产线+步骤+模型定价,单价/包量) |
| `pipeline_capacity` | 供应量表(产线日/月配额,并发限制) |
| `pipeline_usage_log` | 使用记录表(调用日志、用量统计) |
**API 端点**pricing/capacity/usage_log 的 CRUD + get_search_pipeline_id下拉数据源
> 注:原 pipeline_dist分销管理模块已于 2026-09-10 删除,其功能(分销商/分销协议/分销折扣)
> 与 supplychain 模块重复,统一由 supplychain 承载(二级分销商/分销协议/分销折扣→渠道价)。
## 目录结构
```
pipeline-app/
├── app/
│ ├── pipeline_app.py # ahserver 主入口
│ └── global_func.py # 全局函数dbname 映射)
├── conf/
│ └── config.json # 配置文件(端口/数据库/认证)
├── pipeline_core/ # 产线核心模块
│ ├── pipeline_core/ # Python 包
│ ├── models/ # 3 张表定义
│ ├── json/ # 3 个 CRUD 定义
│ ├── wwwroot/ # API 端点 + 前端
│ ├── scripts/load_path.py # RBAC 注册
│ └── pyproject.toml
├── pipeline_ops/ # 运营模块(同上结构)
├── build.sh # 构建脚本venv + 依赖 + DDL + CRUD
├── start.sh / stop.sh # 启停脚本
└── README.md
```
## 部署步骤
### 1. 创建数据库
```sql
CREATE DATABASE pipeline CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
```
### 2. 配置数据库密码
编辑 `conf/config.json`,将数据库密码替换为实际值(当前为 `[REDACTED]`)。
### 3. 构建
```bash
cd ~/test/pipeline-app
bash build.sh
```
build.sh 会:创建 py3 venv → 安装依赖 → json2ddl 生成 DDL → xls2crud 生成 CRUD 界面
### 4. 建表
```bash
# 每个模块分别生成并执行 DDL
cd pipeline_core && ../py3/bin/json2ddl mysql models/ > mysql.ddl.sql
cd pipeline_ops && ../py3/bin/json2ddl mysql models/ > mysql.ddl.sql
# 在 MySQL 中执行所有 DDL
```
### 5. 初始化 RBAC
```bash
# 设置 SAGE_RBAC_DB 环境变量指向 sage 数据库
export SAGE_RBAC_DB=sage
# 运行各模块的 load_path.py
cd pipeline_core && ../py3/bin/python scripts/load_path.py
cd pipeline_ops && ../py3/bin/python scripts/load_path.py
```
### 6. 启动
```bash
cd ~/test/pipeline-app
bash start.sh # 启动服务(端口 9090
bash stop.sh # 停止服务
```
## 技术要点
### 匿名门户主页index.ui 未登录分支)
- `wwwroot/index.ui``scripts/gen_home_index.py` 生成(幂等:自动保留 `{% if get_user() %}` 工作台分支,可重复重跑)。改主页版式改生成器后重跑,不要手改 index.ui。
- 样式全在 `wwwroot/home.css``.pl-` 前缀 / `--pl-` 变量明暗双主题header.tmpl 的 cssfiles() 自动收集。
- 响应式三档:>900 桌面单行 header761-900 窄桌面logo 缩字号+按钮 nowrap≤760 手机两行 header行1 logo+登录行2 三锚点+主题+语言,靠 CSS order 重排)+ footer 竖排。
- 手机适配要点bricks Text 渲染为 flex 容器且子项 min-width:auto 不收缩logo 盒必须 `min-width:0` 才能 ellipsisurlwidget 描述符上的 mobile_hidden 无效urlwidget 只是取数包装options 不传给内层控件)。
- 锚点导航(能力/产线/流程)用 scrollIntoView script bindbinds 必须在 widget 顶层bricks 不读 options.binds
- **数据库名**:所有模块共用 `pipeline` 数据库(通过 `global_func.py` 映射)
- **sqlor API**:严格使用 `sor.C/U/D/R` 模式,`sor.U()` 只接受 2 个参数id 在 data 字典中)
- **dspy 规范**:零 import、零 print、零 uuid使用预加载全局函数
- **独立部署**:与 Sage 解耦,通过 HTTP API 对外提供服务
### Nuitka 二进制化生产部署形态2026-09-17 立项并验证)
- 构建:`bash scripts/build_binary.sh [输出目录]`(在测试机跑;产出 overlay逐模块 .so 保包目录结构 + 包内数据文件 + BUILD_INFO.json 逐仓哈希 + `_appbin/run_compiled.py` runner
- 编译形态实测定型:逐模块 `--module`(整包单 .so 会断 importlib 动态导入子模块);`__init__.py` 用改名 trick副本名=目录名,编译后 mv 成 `__init__.<tag>.so`源码态语法坏死文件零引用死文件py_compile 预门跳过;`.bak/.old` 排除;增量跳过(产物新于源码不重编)。
- 运行:`py3/bin/python <overlay>/_appbin/run_compiled.py -p <port> -w <app根>`sys.path 顺序 _appbin > overlay 根(遮蔽 site-packages 源码);`app/` 是命名空间包(无 __init__overlay/app/ 放 .so 副本。
- 数据文件(.dspy/.ui/.json/.tmpl/wwwroot不进二进制随包目录原样部署.git 仓库仍保留deploy/ 工具、迁移台账、技能树、哈希对账都依赖)。
- 验证记录(测试机 2026-09-17overlay 399 .so / 149M编译态 9199 端口起服务 health 200、登录/菜单/待办/商城全 200与源码态 9090 逐路径对照一致;进程 maps 1341 个 overlay .so 映射。
## 文件统计
- 数据表6 张core 3 + ops 3
- API 端点23 个 dspy 文件
- CRUD 管理6 个(自动生成)
- 总文件数:~80 个