From 729a62dffaf370c2fa6d906f6e480b280ba6a3f0 Mon Sep 17 00:00:00 2001 From: Piyush Raj Date: Thu, 21 Dec 2023 14:00:47 +0530 Subject: [PATCH] Add pg_cron Signed-off-by: Piyush Raj --- .github/workflows/smoke-test.yml | 5 ++- Dockerfile | 38 ++++++++++++++++++ Makefile | 7 +++- README.md | 1 + bitnami/Dockerfile | 49 +++++++++++++++++++++++ bitnami/Makefile | 6 +-- bitnami/timescaledb-bitnami-entrypoint.sh | 4 +- 7 files changed, 102 insertions(+), 8 deletions(-) diff --git a/.github/workflows/smoke-test.yml b/.github/workflows/smoke-test.yml index e5151234..4b4b1a9a 100644 --- a/.github/workflows/smoke-test.yml +++ b/.github/workflows/smoke-test.yml @@ -3,7 +3,7 @@ on: pull_request: push: branches: - - main + - master env: ORG: timescaledev @@ -52,6 +52,9 @@ jobs: fi if psql -c "select 1" then + 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'\$\$)"; break fi sleep 1 diff --git a/Dockerfile b/Dockerfile index 541994e1..79c8f8fb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -73,6 +73,9 @@ RUN set -ex \ && rm -rf /build \ && sed -r -i "s/[#]*\s*(shared_preload_libraries)\s*=\s*'(.*)'/\1 = 'timescaledb,\2'/;s/,'/'/" /usr/local/share/postgresql/postgresql.conf.sample + +# Update to shared_preload_libraries +RUN echo "shared_preload_libraries = 'timescaledb,pg_cron'" >> /usr/local/share/postgresql/postgresql.conf.sample # Adding PG Vector RUN cd /tmp @@ -94,3 +97,38 @@ RUN apk add --no-cache --virtual .build-deps \ && ls \ && make \ && make install + +# Adding pg_cron +ARG PG_CRON_VERSION + +RUN set -ex \ + && cd /tmp\ + && apk add --no-cache --virtual .pg_cron-deps \ + ca-certificates \ + openssl \ + tar \ + && apk add --no-cache --virtual .pg_cron-build-deps \ + autoconf \ + automake \ + g++ \ + clang15 \ + llvm15 \ + libtool \ + libxml2-dev \ + make \ + perl \ + && wget -O pg_cron.tar.gz "https://github.com/citusdata/pg_cron/archive/refs/tags/${PG_CRON_VERSION}.tar.gz" \ + && mkdir -p /tmp/pg_cron \ + && tar \ + --extract \ + --file pg_cron.tar.gz \ + --directory /tmp/pg_cron \ + --strip-components 1 \ + && cd /tmp/pg_cron \ + && make \ + && make install \ + # clean + && cd / \ + && rm /tmp/pg_cron.tar.gz \ + && rm -rf /tmp/pg_cron \ + && apk del .pg_cron-deps .pg_cron-build-deps \ No newline at end of file diff --git a/Makefile b/Makefile index 0e6d6029..d45cc664 100644 --- a/Makefile +++ b/Makefile @@ -5,6 +5,7 @@ ORG=samagragovernance PG_VER=pg15 PG_VER_NUMBER=$(shell echo $(PG_VER) | cut -c3-) TS_VERSION=main +PG_CRON_VERSION=v1.6.0 PREV_TS_VERSION=$(shell wget --quiet -O - https://raw.githubusercontent.com/timescale/timescaledb/${TS_VERSION}/version.config | grep update_from_version | sed -e 's!update_from_version = !!') PREV_TS_IMAGE="timescale/timescaledb:$(PREV_TS_VERSION)-pg$(PG_VER_NUMBER)$(PREV_EXTRA)" PREV_IMAGE=$(shell if docker pull $(PREV_TS_IMAGE) >/dev/null; then echo "$(PREV_TS_IMAGE)"; else echo "postgres:$(PG_VER_NUMBER)-alpine"; fi ) @@ -28,6 +29,7 @@ default: image docker buildx inspect multibuild --bootstrap docker buildx build --platform $(PLATFORM) \ --build-arg TS_VERSION=$(TS_VERSION) \ + --build-arg PG_CRON_VERSION=$(PG_CRON_VERSION) \ --build-arg PG_VERSION=$(PG_VER_NUMBER) \ --build-arg PREV_IMAGE=$(PREV_IMAGE) \ --build-arg OSS_ONLY=" -DAPACHE_ONLY=1" \ @@ -43,6 +45,7 @@ default: image docker buildx inspect multibuild --bootstrap docker buildx build --platform $(PLATFORM) \ --build-arg TS_VERSION=$(TS_VERSION) \ + --build-arg PG_CRON_VERSION=$(PG_CRON_VERSION) \ --build-arg PREV_IMAGE=$(PREV_IMAGE) \ --build-arg PG_VERSION=$(PG_VER_NUMBER) \ $(TAG) $(PUSH_MULTI) . @@ -50,11 +53,11 @@ default: image docker buildx rm multibuild .build_$(TS_VERSION)_$(PG_VER)_oss: Dockerfile - docker build --build-arg OSS_ONLY=" -DAPACHE_ONLY=1" --build-arg PG_VERSION=$(PG_VER_NUMBER) $(TAG_OSS) . + docker build --build-arg OSS_ONLY=" -DAPACHE_ONLY=1" --build-arg PG_VERSION=$(PG_VER_NUMBER) --build-arg PG_CRON_VERSION=$(PG_CRON_VERSION) $(TAG_OSS) . touch .build_$(TS_VERSION)_$(PG_VER)_oss .build_$(TS_VERSION)_$(PG_VER): Dockerfile - docker build --build-arg PG_VERSION=$(PG_VER_NUMBER) --build-arg TS_VERSION=$(TS_VERSION) --build-arg PREV_IMAGE=$(PREV_IMAGE) $(TAG) . + docker build --build-arg PG_VERSION=$(PG_VER_NUMBER) --build-arg TS_VERSION=$(TS_VERSION) --build-arg PG_CRON_VERSION=$(PG_CRON_VERSION) --build-arg PREV_IMAGE=$(PREV_IMAGE) $(TAG) . touch .build_$(TS_VERSION)_$(PG_VER) image: .build_$(TS_VERSION)_$(PG_VER) diff --git a/README.md b/README.md index 41678219..22f46298 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ - [x] [PgVector](https://github.com/pgvector/pgvector) - [x] [TimescaleDB](https://github.com/timescale/timescaledb) +- [x] [PgCron ](https://github.com/citusdata/pg_cron) - [ ] [Citus](https://www.citusdata.com/) Bootstrapped from [TimescaleDB](https://github.com/timescale/timescaledb-docker) diff --git a/bitnami/Dockerfile b/bitnami/Dockerfile index 1042b37a..1850e04f 100644 --- a/bitnami/Dockerfile +++ b/bitnami/Dockerfile @@ -106,6 +106,55 @@ RUN set -ex \ /var/lib/apt/lists/* \ /tmp/* \ /var/tmp/* + +# Adding pg_cron +ARG PG_CRON_VERSION + +RUN set -e \ + && cd /tmp\ + && apt-get update \ + && apt-get install -y \ + ca-certificates \ + openssl \ + tar \ + autoconf \ + automake \ + g++ \ + clang \ + llvm \ + libtool \ + libxml2-dev \ + make \ + perl \ + wget \ + && wget -O pg_cron.tar.gz "https://github.com/citusdata/pg_cron/archive/refs/tags/$PG_CRON_VERSION.tar.gz" \ + && mkdir -p /tmp/pg_cron \ + && tar \ + --extract \ + --file pg_cron.tar.gz \ + --directory /tmp/pg_cron \ + --strip-components 1 \ + && cd /tmp/pg_cron \ + && make \ + && make install \ + # clean + && cd / \ + && rm /tmp/pg_cron.tar.gz \ + && rm -rf /tmp/pg_cron \ + && apt-get autoremove --purge -y \ + autoconf \ + automake \ + g++ \ + clang \ + llvm \ + make \ + perl \ + wget \ + && apt-get clean -y \ + && rm -rf \ + /var/lib/apt/lists/* \ + /tmp/* \ + /var/tmp/* USER 1001 diff --git a/bitnami/Makefile b/bitnami/Makefile index dc4d5b85..780d89ac 100644 --- a/bitnami/Makefile +++ b/bitnami/Makefile @@ -2,9 +2,9 @@ NAME=timescaledb # Default is to timescaledev to avoid unexpected push to the main repo # Set ORG to timescale in the caller ORG=timescaledev -PG_VER=pg12 +PG_VER=pg15 PG_VER_NUMBER=$(shell echo $(PG_VER) | cut -c3-) - +PG_CRON_VERSION=v1.6.0 TS_VERSION=main PREV_TS_VERSION=$(shell wget --quiet -O - https://raw.githubusercontent.com/timescale/timescaledb/${TS_VERSION}/version.config | grep update_from_version | sed -e 's!update_from_version = !!') PREV_TS_IMAGE="timescale/timescaledb:$(PREV_TS_VERSION)-pg$(PG_VER_NUMBER)-bitnami" @@ -21,7 +21,7 @@ default: image .build_$(TS_VERSION)_$(PG_VER): Dockerfile test -n "$(TS_VERSION)" # TS_VERSION test -n "$(PREV_TS_VERSION)" # PREV_TS_VERSION - docker build -f ./Dockerfile --build-arg PG_VERSION=$(PG_VER_NUMBER) --build-arg TS_VERSION=$(TS_VERSION) --build-arg PREV_IMAGE=$(PREV_IMAGE) $(TAG) .. + docker build -f ./Dockerfile --build-arg PG_VERSION=$(PG_VER_NUMBER) --build-arg TS_VERSION=$(TS_VERSION) --build-arg PG_CRON_VERSION=$(PG_CRON_VERSION) --build-arg PREV_IMAGE=$(PREV_IMAGE) $(TAG) .. touch .build_$(TS_VERSION)_$(PG_VER)-bitnami image: .build_$(TS_VERSION)_$(PG_VER) diff --git a/bitnami/timescaledb-bitnami-entrypoint.sh b/bitnami/timescaledb-bitnami-entrypoint.sh index 62b94610..4ea4cfe1 100755 --- a/bitnami/timescaledb-bitnami-entrypoint.sh +++ b/bitnami/timescaledb-bitnami-entrypoint.sh @@ -4,9 +4,9 @@ # shared preload list, or else it gets overwritten. if [ -z "$POSTGRESQL_SHARED_PRELOAD_LIBRARIES" ] then - POSTGRESQL_SHARED_PRELOAD_LIBRARIES=timescaledb + POSTGRESQL_SHARED_PRELOAD_LIBRARIES="timescaledb,pg_cron" else - POSTGRESQL_SHARED_PRELOAD_LIBRARIES="$POSTGRESQL_SHARED_PRELOAD_LIBRARIES,timescaledb" + POSTGRESQL_SHARED_PRELOAD_LIBRARIES="$POSTGRESQL_SHARED_PRELOAD_LIBRARIES,timescaledb,pg_cron" fi export POSTGRESQL_SHARED_PRELOAD_LIBRARIES