-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDockerfile
74 lines (58 loc) · 2.79 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# base image with env vars
FROM timescale/timescaledb:latest-pg12 AS base
ENV POSTGRES_DB defaultdb
ENV POSTGRES_PASSWORD password
ENV PG_CRON_VERSION 1.3.1
# build pgextwlist
FROM base AS pgextwlist
RUN apk update && apk add --no-cache --virtual .deps \
git \
make \
gcc \
musl-dev \
clang \
llvm \
&& git clone https://github.com/dimitri/pgextwlist.git \
&& cd pgextwlist \
&& make \
&& make install \
&& apk del .deps
# build pg_cron
FROM base AS pg_cron
RUN apk update && apk add --no-cache --virtual .deps \
build-base \
ca-certificates \
clang-dev llvm12 \
openssl \
tar \
&& wget -O /pg_cron.tgz https://github.com/citusdata/pg_cron/archive/v$PG_CRON_VERSION.tar.gz \
&& tar xvzf /pg_cron.tgz \
&& cd pg_cron-$PG_CRON_VERSION \
&& sed -i.bak -e 's/-Werror//g' Makefile \
&& sed -i.bak -e 's/-Wno-implicit-fallthrough//g' Makefile \
&& make \
&& make install \
&& apk del .deps
# final image
FROM base
# pgextwlist
RUN mkdir -p /usr/local/lib/postgresql/plugins \
&& sed -r -i "s/[#]*\s*(local_preload_libraries)\s*=\s*'(.*)'/\1 = 'pgextwlist,\2'/;s/,'/'/" /usr/local/share/postgresql/postgresql.conf.sample \
&& echo "extwlist.extensions = 'tablefunc,hstore,pgcrypto'" >> /usr/local/share/postgresql/postgresql.conf.sample \
&& echo "extwlist.custom_path = '/var/lib/pgsql-extwlist-custom'" >> /usr/local/share/postgresql/postgresql.conf.sample
COPY --from=pgextwlist /pgextwlist/pgextwlist.so /usr/local/lib/postgresql/plugins/pgextwlist.so
# pg_cron
COPY --from=pg_cron /usr/local/lib/postgresql/pg_cron.so /usr/local/lib/postgresql/
COPY --from=pg_cron /usr/local/share/postgresql/extension/pg_cron* usr/local/share/postgresql/extension/
RUN mkdir -p /var/lib/pgsql-extwlist-custom/pg_cron \
&& sed -r -i "s/[#]*\s*(shared_preload_libraries)\s*=\s*'(.*)'/\1 = 'pg_cron,\2'/;s/,'/'/" /usr/local/share/postgresql/postgresql.conf.sample \
# TODO: set this at runtime \
&& echo "cron.database_name = 'defaultdb'" >> /usr/local/share/postgresql/postgresql.conf.sample \
&& echo "GRANT USAGE ON SCHEMA cron TO @database_owner@" >> /var/lib/pgsql-extwlist-custom/pg_cron/after-create.sql \
&& sed -r -i "s/[#]*\s*(extwlist.extensions)\s*=\s*'(.*)'/\1 = 'pg_cron,\2'/;s/,'/'/" /usr/local/share/postgresql/postgresql.conf.sample
# postgres_fdw
RUN mkdir -p /var/lib/pgsql-extwlist-custom/postgres_fdw \
&& echo "GRANT USAGE ON FOREIGN DATA WRAPPER postgres_fdw TO @database_owner@" >> /var/lib/pgsql-extwlist-custom/postgres_fdw/after-create.sql \
&& sed -r -i "s/[#]*\s*(extwlist.extensions)\s*=\s*'(.*)'/\1 = 'postgres_fdw,\2'/;s/,'/'/" /usr/local/share/postgresql/postgresql.conf.sample
# custom bootstrap script to run at startup
COPY bootstrap-docker.sql /docker-entrypoint-initdb.d/bootstrap-docker.sql