Skip to content

Commit 729a62d

Browse files
committed
Add pg_cron
Signed-off-by: Piyush Raj <[email protected]>
1 parent eef3b32 commit 729a62d

File tree

7 files changed

+102
-8
lines changed

7 files changed

+102
-8
lines changed

.github/workflows/smoke-test.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ on:
33
pull_request:
44
push:
55
branches:
6-
- main
6+
- master
77

88
env:
99
ORG: timescaledev
@@ -52,6 +52,9 @@ jobs:
5252
fi
5353
if psql -c "select 1"
5454
then
55+
echo "Test pg_cron Extension"
56+
psql -c "CREATE EXTENSION pg_cron";
57+
psql -c "SELECT cron.schedule('30 3 * * 6',\$\$DELETE FROM events WHERE event_time < now() - interval '1 week'\$\$)";
5558
break
5659
fi
5760
sleep 1

Dockerfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ RUN set -ex \
7373
&& rm -rf /build \
7474
&& sed -r -i "s/[#]*\s*(shared_preload_libraries)\s*=\s*'(.*)'/\1 = 'timescaledb,\2'/;s/,'/'/" /usr/local/share/postgresql/postgresql.conf.sample
7575

76+
77+
# Update to shared_preload_libraries
78+
RUN echo "shared_preload_libraries = 'timescaledb,pg_cron'" >> /usr/local/share/postgresql/postgresql.conf.sample
7679
# Adding PG Vector
7780

7881
RUN cd /tmp
@@ -94,3 +97,38 @@ RUN apk add --no-cache --virtual .build-deps \
9497
&& ls \
9598
&& make \
9699
&& make install
100+
101+
# Adding pg_cron
102+
ARG PG_CRON_VERSION
103+
104+
RUN set -ex \
105+
&& cd /tmp\
106+
&& apk add --no-cache --virtual .pg_cron-deps \
107+
ca-certificates \
108+
openssl \
109+
tar \
110+
&& apk add --no-cache --virtual .pg_cron-build-deps \
111+
autoconf \
112+
automake \
113+
g++ \
114+
clang15 \
115+
llvm15 \
116+
libtool \
117+
libxml2-dev \
118+
make \
119+
perl \
120+
&& wget -O pg_cron.tar.gz "https://github.com/citusdata/pg_cron/archive/refs/tags/${PG_CRON_VERSION}.tar.gz" \
121+
&& mkdir -p /tmp/pg_cron \
122+
&& tar \
123+
--extract \
124+
--file pg_cron.tar.gz \
125+
--directory /tmp/pg_cron \
126+
--strip-components 1 \
127+
&& cd /tmp/pg_cron \
128+
&& make \
129+
&& make install \
130+
# clean
131+
&& cd / \
132+
&& rm /tmp/pg_cron.tar.gz \
133+
&& rm -rf /tmp/pg_cron \
134+
&& apk del .pg_cron-deps .pg_cron-build-deps

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ ORG=samagragovernance
55
PG_VER=pg15
66
PG_VER_NUMBER=$(shell echo $(PG_VER) | cut -c3-)
77
TS_VERSION=main
8+
PG_CRON_VERSION=v1.6.0
89
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 = !!')
910
PREV_TS_IMAGE="timescale/timescaledb:$(PREV_TS_VERSION)-pg$(PG_VER_NUMBER)$(PREV_EXTRA)"
1011
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
2829
docker buildx inspect multibuild --bootstrap
2930
docker buildx build --platform $(PLATFORM) \
3031
--build-arg TS_VERSION=$(TS_VERSION) \
32+
--build-arg PG_CRON_VERSION=$(PG_CRON_VERSION) \
3133
--build-arg PG_VERSION=$(PG_VER_NUMBER) \
3234
--build-arg PREV_IMAGE=$(PREV_IMAGE) \
3335
--build-arg OSS_ONLY=" -DAPACHE_ONLY=1" \
@@ -43,18 +45,19 @@ default: image
4345
docker buildx inspect multibuild --bootstrap
4446
docker buildx build --platform $(PLATFORM) \
4547
--build-arg TS_VERSION=$(TS_VERSION) \
48+
--build-arg PG_CRON_VERSION=$(PG_CRON_VERSION) \
4649
--build-arg PREV_IMAGE=$(PREV_IMAGE) \
4750
--build-arg PG_VERSION=$(PG_VER_NUMBER) \
4851
$(TAG) $(PUSH_MULTI) .
4952
touch .multi_$(TS_VERSION)_$(PG_VER)
5053
docker buildx rm multibuild
5154

5255
.build_$(TS_VERSION)_$(PG_VER)_oss: Dockerfile
53-
docker build --build-arg OSS_ONLY=" -DAPACHE_ONLY=1" --build-arg PG_VERSION=$(PG_VER_NUMBER) $(TAG_OSS) .
56+
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) .
5457
touch .build_$(TS_VERSION)_$(PG_VER)_oss
5558

5659
.build_$(TS_VERSION)_$(PG_VER): Dockerfile
57-
docker build --build-arg PG_VERSION=$(PG_VER_NUMBER) --build-arg TS_VERSION=$(TS_VERSION) --build-arg PREV_IMAGE=$(PREV_IMAGE) $(TAG) .
60+
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) .
5861
touch .build_$(TS_VERSION)_$(PG_VER)
5962

6063
image: .build_$(TS_VERSION)_$(PG_VER)

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
- [x] [PgVector](https://github.com/pgvector/pgvector)
77
- [x] [TimescaleDB](https://github.com/timescale/timescaledb)
8+
- [x] [PgCron ](https://github.com/citusdata/pg_cron)
89
- [ ] [Citus](https://www.citusdata.com/)
910

1011
Bootstrapped from [TimescaleDB](https://github.com/timescale/timescaledb-docker)

bitnami/Dockerfile

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,55 @@ RUN set -ex \
106106
/var/lib/apt/lists/* \
107107
/tmp/* \
108108
/var/tmp/*
109+
110+
# Adding pg_cron
111+
ARG PG_CRON_VERSION
112+
113+
RUN set -e \
114+
&& cd /tmp\
115+
&& apt-get update \
116+
&& apt-get install -y \
117+
ca-certificates \
118+
openssl \
119+
tar \
120+
autoconf \
121+
automake \
122+
g++ \
123+
clang \
124+
llvm \
125+
libtool \
126+
libxml2-dev \
127+
make \
128+
perl \
129+
wget \
130+
&& wget -O pg_cron.tar.gz "https://github.com/citusdata/pg_cron/archive/refs/tags/$PG_CRON_VERSION.tar.gz" \
131+
&& mkdir -p /tmp/pg_cron \
132+
&& tar \
133+
--extract \
134+
--file pg_cron.tar.gz \
135+
--directory /tmp/pg_cron \
136+
--strip-components 1 \
137+
&& cd /tmp/pg_cron \
138+
&& make \
139+
&& make install \
140+
# clean
141+
&& cd / \
142+
&& rm /tmp/pg_cron.tar.gz \
143+
&& rm -rf /tmp/pg_cron \
144+
&& apt-get autoremove --purge -y \
145+
autoconf \
146+
automake \
147+
g++ \
148+
clang \
149+
llvm \
150+
make \
151+
perl \
152+
wget \
153+
&& apt-get clean -y \
154+
&& rm -rf \
155+
/var/lib/apt/lists/* \
156+
/tmp/* \
157+
/var/tmp/*
109158

110159
USER 1001
111160

bitnami/Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ NAME=timescaledb
22
# Default is to timescaledev to avoid unexpected push to the main repo
33
# Set ORG to timescale in the caller
44
ORG=timescaledev
5-
PG_VER=pg12
5+
PG_VER=pg15
66
PG_VER_NUMBER=$(shell echo $(PG_VER) | cut -c3-)
7-
7+
PG_CRON_VERSION=v1.6.0
88
TS_VERSION=main
99
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 = !!')
1010
PREV_TS_IMAGE="timescale/timescaledb:$(PREV_TS_VERSION)-pg$(PG_VER_NUMBER)-bitnami"
@@ -21,7 +21,7 @@ default: image
2121
.build_$(TS_VERSION)_$(PG_VER): Dockerfile
2222
test -n "$(TS_VERSION)" # TS_VERSION
2323
test -n "$(PREV_TS_VERSION)" # PREV_TS_VERSION
24-
docker build -f ./Dockerfile --build-arg PG_VERSION=$(PG_VER_NUMBER) --build-arg TS_VERSION=$(TS_VERSION) --build-arg PREV_IMAGE=$(PREV_IMAGE) $(TAG) ..
24+
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) ..
2525
touch .build_$(TS_VERSION)_$(PG_VER)-bitnami
2626

2727
image: .build_$(TS_VERSION)_$(PG_VER)

bitnami/timescaledb-bitnami-entrypoint.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
# shared preload list, or else it gets overwritten.
55
if [ -z "$POSTGRESQL_SHARED_PRELOAD_LIBRARIES" ]
66
then
7-
POSTGRESQL_SHARED_PRELOAD_LIBRARIES=timescaledb
7+
POSTGRESQL_SHARED_PRELOAD_LIBRARIES="timescaledb,pg_cron"
88
else
9-
POSTGRESQL_SHARED_PRELOAD_LIBRARIES="$POSTGRESQL_SHARED_PRELOAD_LIBRARIES,timescaledb"
9+
POSTGRESQL_SHARED_PRELOAD_LIBRARIES="$POSTGRESQL_SHARED_PRELOAD_LIBRARIES,timescaledb,pg_cron"
1010
fi
1111
export POSTGRESQL_SHARED_PRELOAD_LIBRARIES
1212

0 commit comments

Comments
 (0)