From 95103704ee068642825ae4a04d7f44566dcf14bd Mon Sep 17 00:00:00 2001 From: sooraj1002 Date: Thu, 25 Jul 2024 18:22:38 +0530 Subject: [PATCH 1/3] feat: pg_search --- Dockerfile | 44 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 42 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 0476912..f000116 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ ARG TS_VERSION ############################ # Build tools binaries in separate image ############################ -ARG GO_VERSION=1.18.7 +ARG GO_VERSION=1.21.0 FROM golang:${GO_VERSION}-alpine AS tools ENV TOOLS_VERSION 0.8.1 @@ -25,6 +25,39 @@ RUN rm -f $(pg_config --sharedir)/extension/timescaledb*mock*.sql \ && if [ -f $(pg_config --pkglibdir)/timescaledb-1*.so ]; then rm -f $(ls -1 $(pg_config --pkglibdir)/timescaledb-*.so | head -n -5); fi \ && if [ -f $(pg_config --sharedir)/extension/timescaledb--1*.sql ]; then rm -f $(ls -1 $(pg_config --sharedir)/extension/timescaledb--1*.sql | head -n -5); fi +########################### +# Build pg_search in an environment with dynamic loading +########################### +FROM rust:latest AS pg_search_builder +ARG PG_VERSION + +RUN apt-get update && apt-get install -y wget gnupg2 lsb-release + +RUN sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list' + +RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - + + +RUN apt-get update && apt-get install -y \ + git \ + postgresql-${PG_VERSION} \ + postgresql-server-dev-${PG_VERSION} \ + libclang-dev + +RUN git clone --branch main https://github.com/paradedb/paradedb.git /paradedb +WORKDIR /paradedb/pg_search + +RUN cargo install --locked cargo-pgrx --version 0.11.3 + +RUN PG_MAJOR_VERSION=$(echo ${PG_VERSION} | cut -d '.' -f 1) && \ + PG_CONFIG_PATH=$(which pg_config) && \ + export PATH=$PATH:/usr/lib/postgresql/${PG_VERSION}/bin && \ + cargo pgrx init --pg${PG_MAJOR_VERSION} ${PG_CONFIG_PATH} + + +RUN PG_MAJOR_VERSION=$(echo ${PG_VERSION} | cut -d '.' -f 1) && \ + cargo build --release --features "pg${PG_MAJOR_VERSION}" + ############################ # Now build image and copy in tools ############################ @@ -39,6 +72,12 @@ COPY --from=tools /go/bin/* /usr/local/bin/ COPY --from=oldversions /usr/local/lib/postgresql/timescaledb-*.so /usr/local/lib/postgresql/ COPY --from=oldversions /usr/local/share/postgresql/extension/timescaledb--*.sql /usr/local/share/postgresql/extension/ +# copy pg_search +COPY --from=pg_search_builder /paradedb/target/release/libpg_search.so /usr/local/lib/postgresql/ +COPY --from=pg_search_builder /paradedb/pg_search/pg_search.control /usr/local/share/postgresql/extension/ +COPY --from=pg_search_builder /paradedb/pg_search/sql/*.sql /usr/local/share/postgresql/extension/ + + ARG TS_VERSION RUN set -ex \ && apk add libssl1.1 \ @@ -75,7 +114,8 @@ RUN set -ex \ # Update to shared_preload_libraries -RUN echo "shared_preload_libraries = 'citus,timescaledb,pg_cron,pgautofailover'" >> /usr/local/share/postgresql/postgresql.conf.sample +RUN echo "shared_preload_libraries = 'citus,timescaledb,pg_cron,pgautofailover,pg_search'" >> /usr/local/share/postgresql/postgresql.conf.sample + # Adding PG Vector RUN cd /tmp From 474fba742c5acda9e7a27ee79e30f0c3f9336a70 Mon Sep 17 00:00:00 2001 From: sooraj1002 Date: Thu, 25 Jul 2024 18:35:54 +0530 Subject: [PATCH 2/3] test: smoke test for pg_search --- .github/workflows/smoke-test.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/smoke-test.yml b/.github/workflows/smoke-test.yml index 6a15e00..de6871f 100644 --- a/.github/workflows/smoke-test.yml +++ b/.github/workflows/smoke-test.yml @@ -55,6 +55,14 @@ jobs: fi if psql -c "select 1" then + echo "Test pg_search Extension" + psql -c "CREATE EXTENSION pg_search;" + + # Add pg_search smoke test + psql -c "CREATE TABLE test_pg_search_table (id serial PRIMARY KEY, content TEXT);" + psql -c "INSERT INTO test_pg_search_table (content) VALUES ('This is a test document'), ('Another test document');" + psql -c "SELECT * FROM pg_search_content('test', 'test_pg_search_table', 'content');" + echo "Test pg_cron Extension" psql -c "CREATE EXTENSION pg_cron"; psql -c "SELECT cron.schedule('30 3 * * 6',\$\$DELETE FROM events WHERE event_time < now() - interval '1 week'\$\$)"; From ffe56c75993daa41b8fc5e56f2f9a76d9e38e1f3 Mon Sep 17 00:00:00 2001 From: sooraj1002 Date: Sun, 28 Jul 2024 12:36:06 +0530 Subject: [PATCH 3/3] fix: added no-default-features in pg_search --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index f000116..aa32a91 100644 --- a/Dockerfile +++ b/Dockerfile @@ -56,7 +56,7 @@ RUN PG_MAJOR_VERSION=$(echo ${PG_VERSION} | cut -d '.' -f 1) && \ RUN PG_MAJOR_VERSION=$(echo ${PG_VERSION} | cut -d '.' -f 1) && \ - cargo build --release --features "pg${PG_MAJOR_VERSION}" + cargo build --release --no-default-features --features "pg${PG_MAJOR_VERSION}" ############################ # Now build image and copy in tools