Skip to content

Commit

Permalink
✨ feat(postgis/Dockerfile): Create a new Dockerfile for the PostGIS…
Browse files Browse the repository at this point in the history
… service.

✨ feat(`zhparser/Dockerfile`): Create a new Dockerfile for the zhparser service.

✨ feat(`Dockerfile`): Create a new Dockerfile for setting timezone and locale.

✨ feat(`zhparser.sql`): Add SQL script for creating the zhparser extension and configurations.

✨ feat(`.github/workflows/postgres-build.yml`): Add GitHub Actions workflow for building Postgres Docker images.
  • Loading branch information
vnobo committed Dec 12, 2024
1 parent 22952d1 commit ba69949
Show file tree
Hide file tree
Showing 6 changed files with 200 additions and 0 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/postgres-build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will build a Java project with Gradle and cache/restore any dependencies to improve the workflow execution time
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-gradle

name: Postgresql Build
run-name: ${{ github.actor }} is Build Postgresql Actions
on:
push:
branches: [ "main","dev" ]
tags:
- "v*.*.*"
pull_request:

env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: postgres
# Postgresql version
POSTGRES_VERSION: 17
jobs:
build-image:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# generate Docker tags based on the following events/attributes
tags: |
type=schedule
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
- name: Docker Setup Buildx
uses: docker/setup-buildx-action@v3

- name: Log into registry ${{ env.REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v3.3.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}

- name: Build and push Docker Local images
uses: docker/build-push-action@v6
with:
context: ./boot/postgres
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

- name: Build zhparser Docker image
run: docker buildx build --push -t ${{ vars.DOCKER_PREFIX }}/postgres:17-zhparser ./boot/postgres/zhparser

- name: Build postgis Docker image
run: docker buildx build --push -t ${{ vars.DOCKER_PREFIX }}/postgres:17-postgis ./boot/postgres/postgis

- name: Build latest Docker image
run: docker buildx build --push -t ${{ vars.DOCKER_PREFIX }}/postgres:latest ./boot/postgres/postgis
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**
!**/src/test/**

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
8 changes: 8 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM postgres:17

# 设置时区
RUN ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
RUN localedef -i zh_CN -c -f UTF-8 -A /usr/share/locale/locale.alias zh_CN.UTF-8
RUN localedef -i zh_HK -c -f UTF-8 -A /usr/share/locale/locale.alias zh_HK.UTF-8
RUN localedef -i zh_TW -c -f UTF-8 -A /usr/share/locale/locale.alias zh_TW.UTF-8
ENV LANG=zh_CN.utf8
31 changes: 31 additions & 0 deletions postgis/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
ARG PG_CONTAINER_VERSION=latest
FROM postgis/postgis:${PG_CONTAINER_VERSION} AS builder

ARG DEBIAN_FRONTEND=noninteractive
RUN set -ex \
&& apt-get update \
&& apt-get install -y build-essential git postgresql-server-dev-${PG_MAJOR} pkg-config binutils automake libtool \
&& apt-get clean

RUN set -ex \
&& git clone --branch 1.2.3 --single-branch --depth 1 https://github.com/hightman/scws.git \
&& cd scws \
&& touch README;aclocal;autoconf;autoheader;libtoolize;automake --add-missing \
&& ./configure \
&& make install

RUN set -ex \
&& git clone --branch master --single-branch --depth 1 https://github.com/amutu/zhparser.git \
&& cd zhparser \
&& make install

FROM postgis/postgis:${PG_CONTAINER_VERSION}
RUN localedef -i zh_CN -c -f UTF-8 -A /usr/share/locale/locale.alias zh_CN.UTF-8
ENV LANG=zh_CN.UTF-8

COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/zhparser.so /usr/lib/postgresql/${PG_MAJOR}/lib/
COPY --from=builder /usr/local/lib/libscws.* /usr/local/lib/
COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension/zhparser* /usr/share/postgresql/${PG_MAJOR}/extension/
COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/bitcode/zhparser* /usr/lib/postgresql/${PG_MAJOR}/lib/bitcode/
COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/tsearch_data/*.utf8.* /usr/share/postgresql/${PG_MAJOR}/tsearch_data/

28 changes: 28 additions & 0 deletions zhparser.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
-- create the extension
create extension zhparser;

-- make test configuration using parser
create text search configuration chinese (parser = zhparser);

-- add token mapping
alter text search configuration chinese add mapping for n,v,a,i,e,l,x with simple;
set default_text_search_config = 'chinese';
show default_text_search_config;
--add custom word
insert into zhparser.zhprs_custom_word
values ('支付宝');
insert into zhparser.zhprs_custom_word
values ('资金压力');
select sync_zhprs_custom_word();
alter extension zhparser update;
select ts_token_type('zhparser');
select ts_debug('chinese', '支付宝使用很方便');
select ts_debug('chinese', '保障房资金压力');
-- test custom word
select ts_parse('zhparser', '支付宝使用很方便');
select ts_parse('zhparser', '保障房资金压力');
-- test to_tsvector
select to_tsvector('chinese', '支付宝使用很方便');
select to_tsquery('chinese', '支付宝使用很方便');
select to_tsvector('chinese', '保障房资金压力');
select to_tsquery('chinese', '保障房资金压力');
30 changes: 30 additions & 0 deletions zhparser/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
ARG PG_CONTAINER_VERSION=17
FROM docker.io/library/postgres:${PG_CONTAINER_VERSION}-bookworm AS builder

ARG DEBIAN_FRONTEND=noninteractive
RUN set -ex \
&& apt-get update \
&& apt-get install -y build-essential git postgresql-server-dev-${PG_MAJOR} pkg-config binutils automake libtool \
&& apt-get clean

RUN set -ex \
&& git clone --branch 1.2.3 --single-branch --depth 1 https://github.com/hightman/scws.git \
&& cd scws \
&& touch README;aclocal;autoconf;autoheader;libtoolize;automake --add-missing \
&& ./configure \
&& make install

RUN set -ex \
&& git clone --branch master --single-branch --depth 1 https://github.com/amutu/zhparser.git \
&& cd zhparser \
&& make install

FROM docker.io/library/postgres:${PG_CONTAINER_VERSION}-bookworm
RUN localedef -i zh_CN -c -f UTF-8 -A /usr/share/locale/locale.alias zh_CN.UTF-8
ENV LANG=zh_CN.UTF-8

COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/zhparser.so /usr/lib/postgresql/${PG_MAJOR}/lib/
COPY --from=builder /usr/local/lib/libscws.* /usr/local/lib/
COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/extension/zhparser* /usr/share/postgresql/${PG_MAJOR}/extension/
COPY --from=builder /usr/lib/postgresql/${PG_MAJOR}/lib/bitcode/zhparser* /usr/lib/postgresql/${PG_MAJOR}/lib/bitcode/
COPY --from=builder /usr/share/postgresql/${PG_MAJOR}/tsearch_data/*.utf8.* /usr/share/postgresql/${PG_MAJOR}/tsearch_data/

0 comments on commit ba69949

Please sign in to comment.