#!/bin/bash set -e cdir=$(cd "$(dirname "$0")"; pwd) export SAGE_RBAC_DB=rag if [ ! -d py3 ]; then python3 -m venv py3 fi source py3/bin/activate pip install -q xls2ddl mkdir -p pkgs logs files # Foundation modules for repo in apppublic sqlor ahserver rbac appbase bricks-for-python; do [ -d pkgs/$repo ] || git clone git@git.opencomputing.cn:yumoqing/$repo.git pkgs/$repo pip install -q -e pkgs/$repo done # Clone and install rag business module [ -d pkgs/rag ] || git clone git@git.opencomputing.cn:yumoqing/rag.git pkgs/rag pip install -q -e pkgs/rag # rag-pipeline (core engine - PYTHONPATH only) [ -d pkgs/rag-pipeline ] || git clone git@git.opencomputing.cn:yumoqing/rag-pipeline.git pkgs/rag-pipeline # Service modules (reference only) for svc in clip_embedding vdb face-service graph-service ner-service; do [ -d pkgs/$svc ] || git clone git@git.opencomputing.cn:yumoqing/$svc.git pkgs/$svc 2>/dev/null || echo "Skip $svc" done [ -d pkgs/bge-reranker ] || git clone git@git.opencomputing.cn:yumoqing/bge-reranker.git pkgs/bge-reranker 2>/dev/null || echo "Skip bge-reranker" [ -d pkgs/speaker-id ] || git clone git@git.opencomputing.cn:yumoqing/speaker-id.git pkgs/speaker-id 2>/dev/null || echo "Skip speaker-id" # Build bricks frontend if [ ! -d pkgs/bricks ]; then git clone git@git.opencomputing.cn:yumoqing/bricks.git pkgs/bricks fi mkdir -p pkgs/bricks/dist/i18n cd pkgs/bricks bash build.sh cd $cdir # Symlink bricks + module wwwroots (one link per module) ln -sf ../pkgs/bricks/dist wwwroot/bricks 2>/dev/null || true ln -sf ../pkgs/rbac/wwwroot wwwroot/rbac 2>/dev/null || true ln -sf ../pkgs/rag/wwwroot wwwroot/rag 2>/dev/null || true # Migrate legacy table names to rag_ prefix (idempotent, must run BEFORE DDL) # rag 模块表统一加 rag_ 前缀,避免模块跨应用复用时与业务表名冲突 if [ -f pkgs/rag/init/migrate_rag_prefix.sql ]; then echo "== migrating legacy table names to rag_ prefix ==" mysql -h db -utest -ptest123 rag < pkgs/rag/init/migrate_rag_prefix.sql || { echo "ERROR: table prefix migration failed" >&2; exit 1; } fi # Generate DDL from rag module models (creates any missing rag_* tables) if ls pkgs/rag/models/*.json >/dev/null 2>&1; then cd pkgs/rag/models # 不再吞掉错误:models/ 曾误放 CRUD 格式(缺 summary)导致 json2ddl 全量失败被静默忽略 json2ddl mysql . > /tmp/rag_ddl.sql || { echo "ERROR: json2ddl failed" >&2; cd $cdir; exit 1; } if [ ! -s /tmp/rag_ddl.sql ]; then echo "ERROR: generated DDL is empty — check models/*.json format (need summary+fields)" >&2 cd $cdir; exit 1 fi mysql -h db -utest -ptest123 rag < /tmp/rag_ddl.sql || echo "WARN: some DDL statements failed (tables may already exist)" cd $cdir fi # Sync password_key from Sage if [ -f /d/apitest/sage/conf/config.json ]; then sage_key=$(python3 -c "import json; print(json.load(open('/d/apitest/sage/conf/config.json'))['password_key'])") python3 -c " import json c = json.load(open('$cdir/conf/config.json')) c['password_key'] = '$sage_key' json.dump(c, open('$cdir/conf/config.json', 'w'), indent=4, ensure_ascii=False) " 2>/dev/null echo "password_key synced" fi echo "=== RAG Server build complete ==="