Files
diary-news/backend/Dockerfile.postgres

50 lines
1.4 KiB
Docker
Raw Normal View History

FROM postgres:16-bookworm
# 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 \
postgresql-server-dev-16; \
rm -rf /var/lib/apt/lists/*
# 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
# 3) 编译 zhparser
RUN set -eux; \
cd /tmp; \
git clone --depth 1 https://github.com/zhparser/zhparser.git; \
cd zhparser; \
# PG_CONFIG 在 PATH 上(装 postgresql-server-dev-16 自带)
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