Files
diary-news/backend/Dockerfile.postgres

55 lines
1.6 KiB
Docker
Raw Normal View History

FROM postgres:16-bookworm
# zhparser 中文分词扩展 — 全源码编译
# Debian / PGDG 仓库里都没有 postgresql-16-zhparser / libscws-dev / scws 包,
# 必须从 GitHub 拉源码自己 make。
#
# 步骤:
# 1) 装编译工具链 + PG dev headers
# 2) 编译 scws(autotools 项目,先 ./acprep 生成 configure)
# 3) 编译 zhparser(PGXS 扩展,直接 make)
#
# build 时间:~3-5 分钟
# 产物:/usr/lib/postgresql/16/lib/zhparser.so + /usr/lib/libscws.so
RUN set -eux; \
# 1) 编译工具 + PG dev headers
apt-get update; \
apt-get install -y --no-install-recommends \
build-essential \
git \
ca-certificates \
# autotools(scws 依赖)
autoconf \
automake \
libtool \
# pg_config / pgxs(编译 PG 扩展用)
postgresql-server-dev-16; \
rm -rf /var/lib/apt/lists/*
# 2) 编译装 scws(autotools:先 ./acprep 生成 configure,再 ./configure && make)
RUN set -eux; \
cd /tmp; \
git clone --depth 1 https://github.com/hightman/scws.git; \
cd scws; \
./acprep; \
./configure --prefix=/usr; \
make -j$(nproc); \
make install; \
ldconfig; \
cd /; \
rm -rf /tmp/scws
# 3) 编译装 zhparser(PGXS 扩展,直接 make)
RUN set -eux; \
cd /tmp; \
git clone --depth 1 https://github.com/zhparser/zhparser.git; \
cd zhparser; \
make -j$(nproc); \
make install; \
cd /; \
rm -rf /tmp/zhparser
# 验证:扩展文件 + scws .so 都已就位
RUN ls -la /usr/lib/postgresql/16/lib/zhparser.so /usr/lib/libscws.so* 2>&1 | head -5