2026-06-15 18:46:09 +08:00
|
|
|
FROM postgres:16-bookworm
|
|
|
|
|
|
2026-06-15 18:49:34 +08:00
|
|
|
# zhparser 中文分词扩展 — 全源码编译
|
2026-06-15 18:51:23 +08:00
|
|
|
# Debian / PGDG 仓库里都没有 postgresql-16-zhparser / libscws-dev / scws 包,
|
|
|
|
|
# 必须从 GitHub 拉源码自己 make。
|
2026-06-15 18:49:34 +08:00
|
|
|
#
|
2026-06-15 18:57:48 +08:00
|
|
|
# 关键点:scws 仓库年代久远,自带的 autotools 脚本跟新 automake (>=1.16) 不兼容
|
|
|
|
|
# (Makefile.am:24: error: '#' comment at start of rule is unportable)
|
|
|
|
|
# 所以绕过 autotools,直接 gcc 编译 libscws/*.c 然后 ld 拼 .so
|
|
|
|
|
#
|
2026-06-15 18:49:34 +08:00
|
|
|
# 步骤:
|
2026-06-15 18:51:23 +08:00
|
|
|
# 1) 装编译工具链 + PG dev headers
|
2026-06-15 18:57:48 +08:00
|
|
|
# 2) 手编 libscws(绕过 autotools)+ 装到 /usr/local
|
2026-06-15 18:51:23 +08:00
|
|
|
# 3) 编译 zhparser(PGXS 扩展,直接 make)
|
2026-06-15 18:49:34 +08:00
|
|
|
#
|
|
|
|
|
# build 时间:~3-5 分钟
|
2026-06-15 18:57:48 +08:00
|
|
|
# 产物:
|
|
|
|
|
# /usr/local/lib/libscws.so*
|
|
|
|
|
# /usr/local/include/scws/*.h
|
|
|
|
|
# /usr/lib/postgresql/16/lib/zhparser.so
|
2026-06-15 18:49:34 +08:00
|
|
|
|
2026-06-15 18:48:19 +08:00
|
|
|
RUN set -eux; \
|
|
|
|
|
apt-get update; \
|
|
|
|
|
apt-get install -y --no-install-recommends \
|
|
|
|
|
build-essential \
|
|
|
|
|
git \
|
2026-06-15 18:46:09 +08:00
|
|
|
ca-certificates \
|
2026-06-15 18:51:23 +08:00
|
|
|
# pg_config / pgxs(编译 PG 扩展用)
|
2026-06-15 18:48:19 +08:00
|
|
|
postgresql-server-dev-16; \
|
|
|
|
|
rm -rf /var/lib/apt/lists/*
|
2026-06-15 18:46:09 +08:00
|
|
|
|
2026-06-15 18:57:48 +08:00
|
|
|
# 2) 手编 libscws(绕过 autotools — Makefile.am 不兼容新 automake)
|
2026-06-15 18:49:34 +08:00
|
|
|
RUN set -eux; \
|
|
|
|
|
cd /tmp; \
|
|
|
|
|
git clone --depth 1 https://github.com/hightman/scws.git; \
|
2026-06-15 18:57:48 +08:00
|
|
|
cd scws/libscws; \
|
|
|
|
|
# scws 的 autotools 会生成 version.h,手编自己造
|
|
|
|
|
printf '#define SCWS_VERSION "1.2.3"\n#define SCWS_BUILT __DATE__ " " __TIME__\n' > version.h; \
|
|
|
|
|
# 编译所有 .c
|
|
|
|
|
gcc -c -O2 -fPIC -Wall \
|
|
|
|
|
charset.c crc32.c pool.c scws.c xdict.c darray.c rule.c lock.c xdb.c xtree.c; \
|
|
|
|
|
# 装头文件
|
|
|
|
|
mkdir -p /usr/local/include/scws; \
|
|
|
|
|
cp charset.h crc32.h pool.h scws.h xdict.h darray.h rule.h xdb.h xtree.h version.h /usr/local/include/scws/; \
|
|
|
|
|
# 拼 .so
|
|
|
|
|
gcc -shared -Wl,-soname,libscws.so.1 -o libscws.so.1.0.0 *.o -lc; \
|
|
|
|
|
cp libscws.so.1.0.0 /usr/local/lib/; \
|
|
|
|
|
ln -sf libscws.so.1.0.0 /usr/local/lib/libscws.so.1; \
|
|
|
|
|
ln -sf libscws.so.1.0.0 /usr/local/lib/libscws.so; \
|
2026-06-15 18:49:34 +08:00
|
|
|
ldconfig; \
|
|
|
|
|
cd /; \
|
|
|
|
|
rm -rf /tmp/scws
|
2026-06-15 18:46:09 +08:00
|
|
|
|
2026-06-15 18:57:48 +08:00
|
|
|
# 3) 编译 zhparser(PGXS — 直接 make)
|
|
|
|
|
# 注意:zhparser 内部用 #include <scws/scws.h>,需要 /usr/local/include 在 CPATH 上
|
|
|
|
|
ENV CPATH=/usr/local/include
|
2026-06-15 18:48:19 +08:00
|
|
|
RUN set -eux; \
|
|
|
|
|
cd /tmp; \
|
2026-06-15 18:59:09 +08:00
|
|
|
git clone --depth 1 https://github.com/amutu/zhparser.git; \
|
2026-06-15 18:48:19 +08:00
|
|
|
cd zhparser; \
|
2026-06-15 18:49:34 +08:00
|
|
|
make -j$(nproc); \
|
2026-06-15 18:48:19 +08:00
|
|
|
make install; \
|
|
|
|
|
cd /; \
|
|
|
|
|
rm -rf /tmp/zhparser
|
|
|
|
|
|
2026-06-15 18:57:48 +08:00
|
|
|
# 验证
|
|
|
|
|
RUN ls -la /usr/lib/postgresql/16/lib/zhparser.so /usr/local/lib/libscws.so* 2>&1 | head -5
|