- 神识 Go:store 双实现(PG 自动建表+60s 就绪重试 / 内存回退)承载 usage_logs·byok_keys·quota_balances;BYOK 密钥库(AES-GCM 加密、API 脱敏、撤回即失效、主密钥未配置 fail-closed);配额三段式(预扣 max_tokens 钳位 1M→结算实际 token→全败幂等退款,HJ-2004);计量归属(IR user_id→usage_logs,/me/usage 用户维度聚合+配额总览,/admin/usage/sample 对账抽样);Anthropic/Gemini 出站适配器(SSE 解析、system 提升、用量映射);stub 端点补名修复计量空 endpoint - IR 契约:user_id/byok_key_id 双端同步(Go types.go + Py types.py) - 灵台:runs.owner_id(迁移 005,server_default 兼容存量)经 kernel 全链透传为 IR user_id;shenshi_client 扩展用户面方法(X-Hunjing-User-Id 代理,Echo 桩带内存实现);/me/byok-keys 登记·列表·撤回与 /me/usage 端点(4 用例) - 前端神识阁(/models 重建):偏好(生成参数表单)/自带密钥(登记加密保存、脱敏列表、撤回二次确认)/用量(聚合表+配额进度条)三区;me API 库+mock+5 用例;侧栏恢复入口 - 配置与部署:.env.example 增 SHENSHI_DATABASE_URL/SHENSHI_BYOK_MASTER_KEY/SHENSHI_USER_BUDGET_TOKENS;compose 神识容器接自有库(init-shenshi.sql 预建 hunjing_shenshi,与灵台不共库共表) - 证据:Go 34 用例(BYOK 独占/配额拒绝/结算退款/归属聚合)、后端 532、前端 210、BFF 4 全绿;跨进程 E2E 四场景(灵台 HttpShenshiClient→真 Go 神识:登记脱敏/BYOK 独占不可达整体失败/用量归属聚合/撤回即失效)通过;rewrite-plan M4 标记完成、能力矩阵神识行升已验证
368 lines
13 KiB
YAML
368 lines
13 KiB
YAML
# ==============================
|
||
# 魂镜数据基础设施编排(关系库 / 缓存 / 向量 / 图库 / 对象存储)。
|
||
# 与应用层 docker-compose.app.yml 解耦:本文件创建并拥有共享网络 hunjing-net 与全部命名卷,
|
||
# 应用层以 external 方式引用该网络连接数据库等服务。
|
||
# 本地开发默认 SQLite,无需启动本文件;详见根目录 CLAUDE.md 与 docker/README.md。
|
||
#
|
||
# 常用命令:
|
||
# # 启动全部基础设施(首次会创建 hunjing-net 网络)
|
||
# docker compose -f docker/docker-compose.infra.yml up -d
|
||
# # 仅启动部分按需服务
|
||
# docker compose -f docker/docker-compose.infra.yml up -d hunjing-postgres hunjing-redis
|
||
# # 启用后期大规模图数据库 NebulaGraph(需带 --profile)
|
||
# docker compose -f docker/docker-compose.infra.yml --profile nebulagraph up -d hunjing-nebula-graphd hunjing-nebula-console-init
|
||
# # 停止并保留数据卷
|
||
# docker compose -f docker/docker-compose.infra.yml down
|
||
# # 停止并清除数据卷(谨慎,会丢失数据)
|
||
# docker compose -f docker/docker-compose.infra.yml down -v
|
||
#
|
||
# 内存限制:每个服务通过 deploy.resources.limits/reservations 约束内存,
|
||
# 默认值为本地模拟正式环境的保守配置,可按宿主机规格调整。
|
||
# ==============================
|
||
name: hunjing
|
||
|
||
networks:
|
||
hunjing-net:
|
||
name: hunjing-net
|
||
driver: bridge
|
||
|
||
volumes:
|
||
hunjing-pg-data:
|
||
hunjing-redis-data:
|
||
hunjing-neo4j-data:
|
||
hunjing-neo4j-logs:
|
||
hunjing-nebula-data:
|
||
hunjing-nebula-logs:
|
||
hunjing-etcd-data:
|
||
hunjing-minio-data:
|
||
hunjing-milvus-data:
|
||
|
||
services:
|
||
# ============================== 金匮 · 正式环境关系型数据库(PostgreSQL) ==============================
|
||
hunjing-postgres:
|
||
image: postgres:16-alpine
|
||
container_name: hunjing-postgres
|
||
restart: unless-stopped
|
||
networks: [hunjing-net]
|
||
environment:
|
||
POSTGRES_DB: ${POSTGRES_DB:-hunjing}
|
||
POSTGRES_USER: ${POSTGRES_USER:-hunjing}
|
||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-change-me}
|
||
TZ: ${TIMEZONE:-Asia/Shanghai}
|
||
volumes:
|
||
- hunjing-pg-data:/var/lib/postgresql/data
|
||
- ./postgres/init-shenshi.sql:/docker-entrypoint-initdb.d/10-init-shenshi.sql:ro
|
||
ports:
|
||
- "${POSTGRES_PORT:-5432}:5432"
|
||
healthcheck:
|
||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-hunjing} -d ${POSTGRES_DB:-hunjing}"]
|
||
interval: 10s
|
||
timeout: 5s
|
||
retries: 5
|
||
deploy:
|
||
resources:
|
||
limits: { memory: 512M }
|
||
reservations: { memory: 128M }
|
||
|
||
# ============================== 灵泉 · 缓存与后台任务队列(Redis) ==============================
|
||
hunjing-redis:
|
||
image: redis:7-alpine
|
||
container_name: hunjing-redis
|
||
restart: unless-stopped
|
||
networks: [hunjing-net]
|
||
command: ["redis-server", "--appendonly", "yes"]
|
||
volumes:
|
||
- hunjing-redis-data:/data
|
||
ports:
|
||
- "${REDIS_PORT:-6379}:6379"
|
||
healthcheck:
|
||
test: ["CMD", "redis-cli", "ping"]
|
||
interval: 10s
|
||
timeout: 5s
|
||
retries: 5
|
||
deploy:
|
||
resources:
|
||
limits: { memory: 256M }
|
||
reservations: { memory: 64M }
|
||
|
||
# ============================== 玄络 · 图数据库 Neo4j(原型 / 中小规模,默认图库) ==============================
|
||
hunjing-neo4j:
|
||
image: neo4j:5-community
|
||
container_name: hunjing-neo4j
|
||
restart: unless-stopped
|
||
networks: [hunjing-net]
|
||
environment:
|
||
NEO4J_AUTH: ${NEO4J_USER:-neo4j}/${NEO4J_PASSWORD:-change-me}
|
||
NEO4J_PLUGINS: '["apoc"]'
|
||
TZ: ${TIMEZONE:-Asia/Shanghai}
|
||
volumes:
|
||
- hunjing-neo4j-data:/data
|
||
- hunjing-neo4j-logs:/logs
|
||
ports:
|
||
- "7474:7474" # Neo4j Browser(HTTP)
|
||
- "7687:7687" # Bolt 协议
|
||
deploy:
|
||
resources:
|
||
limits: { memory: 1G }
|
||
reservations: { memory: 256M }
|
||
|
||
# ============================== 玄络 · 图数据库 NebulaGraph(后期大规模,二选一) ==============================
|
||
# NebulaGraph 由 metad(元数据)、storaged(存储)、graphd(查询)三个服务组成,
|
||
# 首次启动需通过 console 注册 storage hosts 并创建 space(由下方 console-init 自动完成)。
|
||
# 启用方式(需带 --profile nebulagraph):
|
||
# docker compose -f docker/docker-compose.infra.yml --profile nebulagraph up -d hunjing-nebula-graphd hunjing-nebula-console-init
|
||
# 同时在 .env 中设置 GRAPH_DB_TYPE=nebulagraph;默认不启用、不随 up 拉起。
|
||
hunjing-nebula-metad:
|
||
image: vesoft/nebula-metad:v3.6.0
|
||
container_name: hunjing-nebula-metad
|
||
profiles: ["nebulagraph"]
|
||
restart: unless-stopped
|
||
networks: [hunjing-net]
|
||
environment:
|
||
USER: root
|
||
TZ: ${TIMEZONE:-Asia/Shanghai}
|
||
command:
|
||
- --meta_server_addrs=hunjing-nebula-metad:9559
|
||
- --local_ip=hunjing-nebula-metad
|
||
- --ws_ip=hunjing-nebula-metad
|
||
- --port=9559
|
||
- --data_path=/data/meta
|
||
- --log_dir=/logs/meta
|
||
volumes:
|
||
- hunjing-nebula-data:/data
|
||
- hunjing-nebula-logs:/logs
|
||
deploy:
|
||
resources:
|
||
limits: { memory: 512M }
|
||
reservations: { memory: 128M }
|
||
|
||
hunjing-nebula-storaged:
|
||
image: vesoft/nebula-storaged:v3.6.0
|
||
container_name: hunjing-nebula-storaged
|
||
profiles: ["nebulagraph"]
|
||
restart: unless-stopped
|
||
networks: [hunjing-net]
|
||
environment:
|
||
USER: root
|
||
TZ: ${TIMEZONE:-Asia/Shanghai}
|
||
command:
|
||
- --meta_server_addrs=hunjing-nebula-metad:9559
|
||
- --local_ip=hunjing-nebula-storaged
|
||
- --ws_ip=hunjing-nebula-storaged
|
||
- --port=9779
|
||
- --data_path=/data/storage
|
||
- --log_dir=/logs/storage
|
||
volumes:
|
||
- hunjing-nebula-data:/data
|
||
- hunjing-nebula-logs:/logs
|
||
depends_on:
|
||
hunjing-nebula-metad:
|
||
condition: service_started
|
||
deploy:
|
||
resources:
|
||
limits: { memory: 1G }
|
||
reservations: { memory: 256M }
|
||
|
||
hunjing-nebula-graphd:
|
||
image: vesoft/nebula-graphd:v3.6.0
|
||
container_name: hunjing-nebula-graphd
|
||
profiles: ["nebulagraph"]
|
||
restart: unless-stopped
|
||
networks: [hunjing-net]
|
||
environment:
|
||
USER: root
|
||
TZ: ${TIMEZONE:-Asia/Shanghai}
|
||
command:
|
||
- --meta_server_addrs=hunjing-nebula-metad:9559
|
||
- --ws_ip=hunjing-nebula-graphd
|
||
- --port=9669
|
||
- --log_dir=/logs/graph
|
||
volumes:
|
||
- hunjing-nebula-logs:/logs
|
||
ports:
|
||
- "${NEBULAGRAPH_PORT:-9669}:9669" # 应用连接端口
|
||
depends_on:
|
||
hunjing-nebula-metad:
|
||
condition: service_started
|
||
deploy:
|
||
resources:
|
||
limits: { memory: 512M }
|
||
reservations: { memory: 128M }
|
||
|
||
# 一次性初始化:注册 storage hosts 并创建 space。
|
||
# 若 storaged 尚未 ONLINE 导致失败,待几秒后重跑:
|
||
# docker compose -f docker/docker-compose.infra.yml --profile nebulagraph up hunjing-nebula-console-init
|
||
hunjing-nebula-console-init:
|
||
image: vesoft/nebula-console:v3.6.0
|
||
container_name: hunjing-nebula-console-init
|
||
profiles: ["nebulagraph"]
|
||
restart: "no"
|
||
networks: [hunjing-net]
|
||
depends_on:
|
||
hunjing-nebula-graphd:
|
||
condition: service_started
|
||
hunjing-nebula-storaged:
|
||
condition: service_started
|
||
environment:
|
||
NEBULA_USER: ${NEBULAGRAPH_USER:-root}
|
||
NEBULA_PASSWORD: ${NEBULAGRAPH_PASSWORD:-nebula}
|
||
NEBULA_SPACE: ${NEBULAGRAPH_SPACE:-hunjing}
|
||
entrypoint:
|
||
- sh
|
||
- -c
|
||
- |
|
||
echo "等待 graphd 就绪..."
|
||
for i in $$(seq 1 30); do
|
||
if nebula-console -addr=hunjing-nebula-graphd -port=9669 -u "$$NEBULA_USER" -p "$$NEBULA_PASSWORD" -e "SHOW HOSTS;" >/dev/null 2>&1; then
|
||
echo "graphd 就绪,开始注册 hosts 并创建 space"
|
||
nebula-console -addr=hunjing-nebula-graphd -port=9669 -u "$$NEBULA_USER" -p "$$NEBULA_PASSWORD" -e \
|
||
"ADD HOSTS \"hunjing-nebula-storaged\":9779; CREATE SPACE IF NOT EXISTS $$NEBULA_SPACE(vid_type=FIXED_STRING(64), partition_num=10, replica_factor=1);"
|
||
echo "初始化完成"
|
||
exit 0
|
||
fi
|
||
echo "graphd 尚未就绪,2s 后重试 ($$i/30)"
|
||
sleep 2
|
||
done
|
||
echo "graphd 在超时内未就绪" >&2
|
||
exit 1
|
||
deploy:
|
||
resources:
|
||
limits: { memory: 256M }
|
||
reservations: { memory: 64M }
|
||
|
||
# ============================== 灵犀 · 向量数据库(Milvus)及其依赖 ==============================
|
||
# 灵犀 standalone 依赖 etcd(灵犀·元册,元数据)与 minio(玉函,对象存储块)。
|
||
hunjing-etcd:
|
||
image: quay.io/coreos/etcd:v3.5.16
|
||
container_name: hunjing-etcd
|
||
restart: unless-stopped
|
||
networks: [hunjing-net]
|
||
environment:
|
||
- ETCD_AUTO_COMPACTION_MODE=revision
|
||
- ETCD_AUTO_COMPACTION_RETENTION=1000
|
||
- ETCD_QUOTA_BACKEND_BYTES=4294967296
|
||
- ETCD_SNAPSHOT_COUNT=50000
|
||
volumes:
|
||
- hunjing-etcd-data:/etcd
|
||
command: >-
|
||
etcd
|
||
-advertise-client-urls=http://127.0.0.1:2379
|
||
-listen-client-urls=http://0.0.0.0:2379
|
||
--data-dir=/etcd
|
||
healthcheck:
|
||
test: ["CMD", "etcdctl", "endpoint", "health"]
|
||
interval: 30s
|
||
timeout: 20s
|
||
retries: 3
|
||
deploy:
|
||
resources:
|
||
limits: { memory: 512M }
|
||
reservations: { memory: 128M }
|
||
|
||
# 玉函 · 对象存储 MinIO(兼灵犀块存储)
|
||
hunjing-minio:
|
||
image: minio/minio:RELEASE.2024-11-07T00-52-20Z
|
||
container_name: hunjing-minio
|
||
restart: unless-stopped
|
||
networks: [hunjing-net]
|
||
# MinIO 同时作为 Milvus 的存储后端与魂镜对象存储(STORAGE_PROVIDER=minio)。
|
||
environment:
|
||
MINIO_ROOT_USER: ${MINIO_ACCESS_KEY_ID:-minioadmin}
|
||
MINIO_ROOT_PASSWORD: ${MINIO_SECRET_ACCESS_KEY:-minioadmin}
|
||
volumes:
|
||
- hunjing-minio-data:/minio_data
|
||
command: minio server /minio_data --console-address ":9001"
|
||
ports:
|
||
- "${MINIO_EXTERNAL_PORT:-9000}:9000" # S3 API
|
||
- "9001:9001" # 管理控制台
|
||
healthcheck:
|
||
test: ["CMD-SHELL", "mc ready local || exit 0"]
|
||
interval: 30s
|
||
timeout: 20s
|
||
retries: 3
|
||
deploy:
|
||
resources:
|
||
limits: { memory: 512M }
|
||
reservations: { memory: 128M }
|
||
|
||
# 灵犀 · 向量数据库 Milvus
|
||
hunjing-milvus:
|
||
image: milvusdb/milvus:v2.4.17
|
||
container_name: hunjing-milvus
|
||
restart: unless-stopped
|
||
networks: [hunjing-net]
|
||
command: ["milvus", "run", "standalone"]
|
||
security_opt:
|
||
- seccomp:unconfined
|
||
environment:
|
||
ETCD_ENDPOINTS: hunjing-etcd:2379
|
||
MINIO_ADDRESS: hunjing-minio:9000
|
||
TZ: ${TIMEZONE:-Asia/Shanghai}
|
||
volumes:
|
||
- hunjing-milvus-data:/var/lib/milvus
|
||
ports:
|
||
- "${MILVUS_PORT:-19530}:19530"
|
||
- "9091:9091" # 健康检查 / metrics
|
||
depends_on:
|
||
hunjing-etcd:
|
||
condition: service_healthy
|
||
hunjing-minio:
|
||
condition: service_started
|
||
healthcheck:
|
||
test: ["CMD-SHELL", "curl -sf http://localhost:9091/healthz || exit 1"]
|
||
interval: 30s
|
||
start_period: 120s
|
||
timeout: 20s
|
||
retries: 3
|
||
deploy:
|
||
resources:
|
||
limits: { memory: 2G }
|
||
reservations: { memory: 512M }
|
||
|
||
# ============================== 灵犀·观 · Milvus 可视化管理(Attu) ==============================
|
||
# Attu 是 Milvus 官方 Web 管理界面,用于查看 collection、数据与运行查询。
|
||
# 启动 Milvus 后访问 http://localhost:${ATTU_PORT:-8001},连接地址默认指向 hunjing-milvus。
|
||
hunjing-attu:
|
||
image: zilliztech/attu:v2.4
|
||
container_name: hunjing-attu
|
||
restart: unless-stopped
|
||
networks: [hunjing-net]
|
||
environment:
|
||
MILVUS_URL: hunjing-milvus:19530
|
||
TZ: ${TIMEZONE:-Asia/Shanghai}
|
||
ports:
|
||
- "${ATTU_PORT:-8001}:3000"
|
||
depends_on:
|
||
hunjing-milvus:
|
||
condition: service_started
|
||
deploy:
|
||
resources:
|
||
limits: { memory: 256M }
|
||
reservations: { memory: 64M }
|
||
|
||
# ============================== 金匮·摹本 · PostgreSQL 备份 / 恢复(手动触发,profile: backup) ==============================
|
||
# 备份:docker compose -f docker/docker-compose.infra.yml --profile backup run --rm hunjing-pg-backup
|
||
# 恢复:见 docker/backup/backup-restore.sh 顶部命令(需 override entrypoint 并传 RESTORE_FILE)。
|
||
# 备份产物落在项目根 backups/ 目录(已加入 .gitignore)。
|
||
hunjing-pg-backup:
|
||
image: postgres:16-alpine
|
||
container_name: hunjing-pg-backup
|
||
profiles: ["backup"]
|
||
restart: "no"
|
||
networks: [hunjing-net]
|
||
environment:
|
||
PGHOST: hunjing-postgres
|
||
PGPORT: "5432"
|
||
PGUSER: ${POSTGRES_USER:-hunjing}
|
||
PGPASSWORD: ${POSTGRES_PASSWORD:-change-me}
|
||
PGDATABASE: ${POSTGRES_DB:-hunjing}
|
||
BACKUP_RETAIN_DAYS: ${BACKUP_RETAIN_DAYS:-7}
|
||
volumes:
|
||
- ./backup:/backup:ro
|
||
- ../backups:/backups
|
||
entrypoint: ["/bin/sh", "/backup/backup-postgres.sh"]
|
||
deploy:
|
||
resources:
|
||
limits: { memory: 256M }
|
||
reservations: { memory: 64M }
|