fix(postgres): 源码编译 scws + zhparser(全链无 apt 包)

This commit is contained in:
mavis
2026-06-15 18:49:34 +08:00
parent 363fd42f80
commit 96a463858c

View File

@@ -1,34 +1,49 @@
FROM postgres:16-bookworm
# zhparser 编译依赖 + scws(中文分词库)
# zhparser 在 PGDG / Debian 仓库里都没现成包,需要从源码编译
# 参考: https://github.com/zhparser/zhparser
# zhparser 中文分词扩展 — 全源码编译
# Debian / PGDG 仓库里都没现成的 postgresql-16-zhparser / libscws-dev 包,
# 必须从 GitHub 拉源码自己 make
#
# 步骤:
# 1) 装编译工具 + PG dev headers
# 2) 编译装 scws(https://github.com/hightman/scws,zhparser 依赖的分词库)
# 3) 编译装 zhparser(https://github.com/zhparser/zhparser)
#
# build 时间:~3-5 分钟
# 产物:/usr/lib/postgresql/16/lib/zhparser.so + libscws.so
RUN set -eux; \
# 1) 编译工具链
apt-get update; \
apt-get install -y --no-install-recommends \
build-essential \
git \
ca-certificates \
# scws 依赖
libscws-dev \
# pg_config / pgxs(编译 PG 扩展用,来自 postgresql-server-dev)
postgresql-server-dev-16; \
rm -rf /var/lib/apt/lists/*
# 装 scws 命令行工具(可选,扩展本身只需要 libscws.so)
# Debian 包 libscws-dev 已经包含了运行时 .so
# 2) 编译 scws(中文分词库)
RUN set -eux; \
cd /tmp; \
git clone --depth 1 https://github.com/hightman/scws.git; \
cd scws; \
./configure --prefix=/usr; \
make -j$(nproc); \
make install; \
ldconfig; \
cd /; \
rm -rf /tmp/scws
# 编译 zhparser
# 注意:zhparser 默认要装到 $pkglibdir(/usr/lib/postgresql/16/lib/),
# make install 用 PGXS 系统,会读取 pg_config
# 3) 编译 zhparser
RUN set -eux; \
cd /tmp; \
git clone --depth 1 https://github.com/zhparser/zhparser.git; \
cd zhparser; \
make; \
# PG_CONFIG 在 PATH 上(装 postgresql-server-dev-16 自带)
make -j$(nproc); \
make install; \
cd /; \
rm -rf /tmp/zhparser
# 验证:扩展文件应该已经就位
RUN ls -la /usr/lib/postgresql/16/lib/zhparser.so 2>&1 | head -2
# 验证:扩展文件 + scws .so 都已就位
RUN ls -la /usr/lib/postgresql/16/lib/zhparser.so /usr/lib/libscws.so* 2>&1 | head -5