Files
knowledge-governance/scripts/library-capture-v090.sh
T
姚章浩 0aa9f273e6
build / build (push) Failing after 1m33s
feat(library): 采集接入 RDS 型 0.9.0 栈
为什么:测试 0.9.0 栈(Compose 项目 weknora-v090)没有源库容器,治理库也不在
容器里,两者都是 RDS。旧实现用 -source-pg/-governance-pg 的容器地址拼 DSN、
用 docker exec psql 读路由绑定,在这类栈上采集根本起不来——不是权限问题,是
地址解析方式错了。

怎么改:
- 新增 internal/librarydsn 收敛"这次 DSN 从哪来":容器模式保持原形状
  (sslmode=disable,目标不变);-source-pg 为空时改用源应用容器 env 的 DB_*
  直连托管实例,TLS 取 LIBRARY_SOURCE_DB_SSLMODE(默认 require,prefer/allow
  这类会静默降级的取值直接拒);-governance-pg 为空时从
  LIBRARY_GOVERNANCE_DSN_FILE 的 0600 文件读 DSN(复用 dobotaiops.ReadDSNFile,
  不另写一份同义实现)。两条路径都不进日志/错误/describe,错误只点名缺哪个变量、
  缺哪个文件。
- libraryctl 的路由绑定读取按模式分派,只共用行解析;外部路径用只读会话。
  libraryagent 的 identity/health 增报 source_db/governance_db 模式;-describe
  只打这两项,不再 dump 配置。
- 新增 scripts/library-capture-v090.sh:weknora-v090 的唯一写入者 app + 逐个
  声明的 non-writers,两个 -pg 传空走外部模式,归档根可环境变量覆盖,
  LIBRARYCTL_BIN 缺失即失败;0.7.1 入口脚本一字未动。

怎么验:internal/librarydsn 三条路径(容器/RDS/文件)各有用例,缺变量、缺文件、
0644 文件、非 PostgreSQL 内容均失败关闭且断言错误不含口令;cmd/libraryctl 侧
钉住文件模式接线与"错误不带地址";v090 脚本进 CI 做 bash -n 加标志/服务声明
断言,并拒绝 0.7.1 容器名出现在新入口。make verify 17 项全绿。

未做:真实采集、生产 executor、Key/KB 绑定。
2026-11-16 20:53:40 +08:00

56 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Whole-library capture entry point for the RDS-backed WeKnora 0.9.0 test stack
# (Compose project weknora-v090).
#
# Why a separate file instead of a parameterised one: this stack has no source
# PostgreSQL container and no governance PostgreSQL container. Both databases are
# managed instances (RDS). -source-pg / -governance-pg are therefore passed empty,
# which is libraryctl's documented signal to resolve them from the source app
# container env (DB_HOST/DB_PORT/DB_NAME/DB_USER/DB_PASSWORD + LIBRARY_SOURCE_DB_SSLMODE)
# and from LIBRARY_GOVERNANCE_DSN_FILE (0600 file). Keeping the 0.7.1 entry point
# untouched means a change here can never alter a stack that already ran.
#
# Every service of the Compose project is declared below: exactly one writer (app)
# and a reason for each sibling which must NOT be stopped. ProjectController
# refuses to run if the project gains a service that is not declared here, so a
# new container cannot be silently left outside the maintenance window.
#
# Credentials are read at call time (container env / 0600 file) and are never
# printed. Nothing here writes to the source stack except SIGTERM/SIGSTART of the
# declared writer.
set -euo pipefail
# The binary is pinned by the caller on purpose: there is no "whatever is in this
# directory" fallback, so a stale build next to the script cannot be executed by
# accident against a live stack.
BIN="${LIBRARYCTL_BIN:-}"
if [ -z "$BIN" ]; then
echo "LIBRARYCTL_MISSING: set LIBRARYCTL_BIN to the libraryctl binary built for this run" >&2
exit 1
fi
if [ ! -x "$BIN" ]; then
echo "LIBRARYCTL_NOT_EXECUTABLE: $BIN is not an executable file" >&2
exit 1
fi
# Archives/journals live outside the home directory on this host (they survive the
# operator account); both roots stay overridable for an isolated rehearsal.
ARCHIVE_ROOT="${LIBRARY_ARCHIVE_ROOT:-/var/lib/knowledge-governance/library}"
JOURNAL_ROOT="${LIBRARY_JOURNAL_ROOT:-/var/lib/knowledge-governance/freeze}"
# Reasons must not contain commas: the flag is comma-separated.
NON_WRITERS="frontend=UI only; no knowledge writes"
NON_WRITERS+=",docreader=parse RPC service; app persists parse output"
NON_WRITERS+=",elasticsearch=search store; not an initiator"
NON_WRITERS+=",redis=queue/cache store; not an initiator"
exec "$BIN" "$@" \
-project weknora-v090 \
-writers app \
-source-app weknora-v090-app \
-source-es weknora-v090-elasticsearch \
-source-pg "" \
-governance-pg "" \
-non-writers "$NON_WRITERS" \
-archive "$ARCHIVE_ROOT" \
-journal "$JOURNAL_ROOT"