新增 Dockerfile + docker/entrypoint.sh: - 基础 crpi-.../ssw188/postgres:16-alpine + ontology 二进制,单镜像 - 默认端口 8081 / 库 ssw-ontology / 用户 ssw / 密码 ssw - /data/pg 自动挂 PG 数据,/data/archive 挂文档根目录 - trap 收尸保证 PG + ontology 同生命周期 seed 极简化为 1 个对象类型「合作企业」+ 3 条示例 (尚数网/腾讯/阿里巴巴),便于演示也便于清理。 默认 HTTP_PORT 统一为 8081(覆盖 server/config.go、run.sh、 vite.config.js、importer/import-from-xeo.js、docs/README.md、 docs/USAGE.md、docs/IMPORT.md、.env.example 等所有文档/代码)。 docs/README.md / .env.example 默认 DATABASE_URL 改为 ssw/[email protected]:5432/ssw-ontology(与 Docker 镜像自带 PG 一致); run.sh 删 dacli 硬编码 fallback,改从 .env 读(不存在则报错退出)。 README 重整:分「方式 A Docker 镜像 / 方式 B 本机 ./run.sh」, 新增 AI 智能导入(-e AI_*)与管理接口鉴权(-e MANAGER_API_KEY)说明。
78 lines
3.0 KiB
Bash
Executable File
78 lines
3.0 KiB
Bash
Executable File
#!/bin/sh
|
|
# 尚数网本体管理平台 · 单镜像 entrypoint
|
|
#
|
|
# 设计要点:
|
|
# 1. 用户挂 -v /host/x:/data 时: /data/pg -> PG 数据; /data/archive -> 文档
|
|
# 2. 不挂: PG 用匿名卷 (不持久化), archive 用镜像内自带目录
|
|
# 3. PG 用官方 docker-entrypoint.sh 初始化 (用户/库/权限都由它管)
|
|
# 4. ontology exec 成 PID 1 (接 SIGTERM 优雅退出), PG 在后台, trap 保证一起收
|
|
set -eu
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# 1. 数据目录决策
|
|
# ----------------------------------------------------------------------------
|
|
# /data/pg 存在 -> 用户明确要持久化 PG 到挂载卷
|
|
if [ -d /data ] && [ -d /data/pg ]; then
|
|
export PGDATA=/data/pg
|
|
echo "[entrypoint] PGDATA=/data/pg (mounted)"
|
|
else
|
|
export PGDATA=/var/lib/postgresql/data
|
|
echo "[entrypoint] PGDATA=/var/lib/postgresql/data (anonymous)"
|
|
fi
|
|
|
|
# /data/archive 存在 -> 软链到 /app/archive, 让 ontology 写入透明生效
|
|
if [ -d /data ] && [ -d /data/archive ]; then
|
|
rm -rf /app/archive
|
|
ln -sfn /data/archive /app/archive
|
|
echo "[entrypoint] archive -> /data/archive (mounted)"
|
|
else
|
|
mkdir -p /app/archive
|
|
echo "[entrypoint] archive -> /app/archive (ephemeral)"
|
|
fi
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# 2. 启动 Postgres (用官方 entrypoint 完成 initdb/建用户/建库等)
|
|
# ----------------------------------------------------------------------------
|
|
echo "[entrypoint] starting postgres..."
|
|
/usr/local/bin/docker-entrypoint.sh postgres &
|
|
PG_PID=$!
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# 3. 等 PG 就绪 (最多 60s)
|
|
# ----------------------------------------------------------------------------
|
|
echo "[entrypoint] waiting for postgres at 127.0.0.1:5432..."
|
|
READY=no
|
|
for i in $(seq 1 60); do
|
|
if pg_isready -h 127.0.0.1 -p 5432 \
|
|
-U "${POSTGRES_USER:-ssw}" \
|
|
-d "${POSTGRES_DB:-ssw-ontology}" -q 2>/dev/null; then
|
|
READY=yes
|
|
break
|
|
fi
|
|
sleep 1
|
|
done
|
|
|
|
if [ "$READY" != "yes" ]; then
|
|
echo "[entrypoint] FATAL: postgres not ready after 60s, dumping logs..."
|
|
kill -TERM "$PG_PID" 2>/dev/null || true
|
|
wait "$PG_PID" 2>/dev/null || true
|
|
exit 1
|
|
fi
|
|
echo "[entrypoint] postgres ready (db=${POSTGRES_DB:-ssw-ontology})"
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# 4. trap: ontology 退出时, 顺手把 PG 也带走 (避免孤儿进程)
|
|
# ----------------------------------------------------------------------------
|
|
cleanup() {
|
|
echo "[entrypoint] stopping postgres (pid=$PG_PID)..."
|
|
kill -TERM "$PG_PID" 2>/dev/null || true
|
|
wait "$PG_PID" 2>/dev/null || true
|
|
}
|
|
trap cleanup EXIT TERM INT
|
|
|
|
# ----------------------------------------------------------------------------
|
|
# 5. 前台启动 ontology (exec -> 它就是 PID 1, 接收 docker stop 的 SIGTERM)
|
|
# ----------------------------------------------------------------------------
|
|
echo "[entrypoint] starting ontology on :${HTTP_PORT:-8081}..."
|
|
exec /app/server
|