postgresql-citus-patroni-image/Dockerfile

176 lines
5.3 KiB
Docker
Raw Permalink Normal View History

2024-08-13 09:20:08 +03:00
ARG UPSTREAM_IMAGE_VERSION
ARG DEPS_IMAGE
FROM docker.io/library/postgres:${UPSTREAM_IMAGE_VERSION}-bookworm AS postgresql-upstream
FROM ${DEPS_IMAGE} AS deps
## ---
FROM deps AS pycache
SHELL [ "/bin/sh", "-ec" ]
COPY /scripts/* /usr/local/sbin/
ENV PYTHONDONTWRITEBYTECODE=''
## Python cache preseed
RUN libpython="${PYTHON_SITE_PACKAGES%/*}" ; \
find "${libpython}/" -mindepth 1 -maxdepth 1 -printf '%P\0' \
| sed -zEn \
-e '/^(collections|importlib|json|re)$/p' \
| sort -zV \
| env -C "${libpython}" xargs -0r \
python3 -m compileall -q -j 2 ; \
find "${PYTHON_SITE_PACKAGES}/" -mindepth 1 -maxdepth 1 -printf '%P\0' \
| sed -zE \
-e '/\.(dist-info|pth|txt)$/d' \
-e '/^(pip|pkg_resources|setuptools|wheel)$/d' \
| sort -zV \
| env -C "${PYTHON_SITE_PACKAGES}" xargs -0r \
python3 -m compileall -q -j 2
## Python cache warmup
RUN export PYTHONPROFILEIMPORTTIME=1 ; \
patronictl --help ; \
patroni --help ; \
ydiff --help ; \
cdiff --help
## Python cache adjustments
RUN d="@$(date '+%s')" ; \
find /usr/local/lib/ -name '*.pyc' -exec touch -m -d "$d" {} + ; \
find /usr/local/lib/ -name __pycache__ -exec touch -m -d "$d" {} +
2024-12-04 21:17:59 +03:00
WORKDIR /pycache
RUN find /usr/local/ -type f -name '*.py[co]' -printf '%P\0' \
| sort -zV \
| tar -C /usr/local --null -T - -cf - \
| tar -xf -
2024-08-13 09:20:08 +03:00
## ---
FROM deps AS postgresql
SHELL [ "/bin/sh", "-ec" ]
COPY /scripts/* /usr/local/sbin/
ENV PG_UID=11111 PG_GID=11111
ENV PGHOME=/var/lib/postgresql
ENV PGDATA=${PGHOME}/data
RUN echo "postgres:x:${PG_UID}:${PG_GID}:postgres:${PGHOME}:/bin/bash" >> /etc/passwd ; \
echo "postgres:x:${PG_GID}:" >> /etc/group ; \
echo 'postgres:!:::::::' >> /etc/shadow ; \
install -d -o postgres -g postgres -m 0755 "${PGHOME}"
RUN install -d -o postgres -g postgres -m 3755 /run/postgresql
VOLUME [ "/run/postgresql" ]
COPY /apt/sources.pgdg-ver.in /tmp/pgdg-ver.sources
COPY /apt/preferences.pgdg-ver.in /tmp/pgdg-ver.prefs
RUN sed "s/%{PG_MAJOR}/${PG_MAJOR}/g" < /tmp/pgdg-ver.sources > "/etc/apt/sources.list.d/pgdg-${PG_MAJOR}.sources" ; \
sed "s/%{PG_MAJOR}/${PG_MAJOR}/g" < /tmp/pgdg-ver.prefs > "/etc/apt/preferences.d/pgdg-${PG_MAJOR}" ; \
rm -f /tmp/pgdg-ver.sources /tmp/pgdg-ver.prefs
2024-12-04 21:17:59 +03:00
COPY --from=postgresql-upstream /etc/postgresql-common/createcluster.conf /etc/postgresql-common/
2024-08-13 09:20:08 +03:00
RUN apt-install.sh postgresql-common ; \
apt-install.sh \
"postgresql-${PG_MAJOR}" \
; \
apt-clean.sh ; \
f="/usr/share/postgresql/${PG_MAJOR}/postgresql.conf.sample" ; \
dpkg-divert --add --rename --divert "$f.dpkg" "$f" ; \
ln -sv ../postgresql.conf.sample "/usr/share/postgresql/${PG_MAJOR}/"
2024-12-04 21:17:59 +03:00
COPY --from=postgresql-upstream /usr/share/postgresql/postgresql.conf.sample /usr/share/postgresql/
2024-08-13 09:20:08 +03:00
ENV PATH=${PATH}:/usr/lib/postgresql/${PG_MAJOR}/bin
2024-12-04 21:17:59 +03:00
COPY --from=postgresql-upstream /docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d/
COPY --from=postgresql-upstream /usr/local/bin/*.sh /usr/local/bin/
2024-08-13 09:20:08 +03:00
## compatibility ;)
RUN ln -sv /usr/local/sbin/dumb-run-as.sh /usr/local/bin/gosu
## ---
FROM postgresql AS postgresql-extras
SHELL [ "/bin/sh", "-ec" ]
RUN apt-install.sh \
pgbouncer \
"postgresql-${PG_MAJOR}-cron" \
"postgresql-${PG_MAJOR}-hll" \
"postgresql-${PG_MAJOR}-hypopg" \
"postgresql-${PG_MAJOR}-icu-ext" \
"postgresql-${PG_MAJOR}-pg-catcheck" \
"postgresql-${PG_MAJOR}-pg-checksums" \
"postgresql-${PG_MAJOR}-pg-failover-slots" \
"postgresql-${PG_MAJOR}-pg-hint-plan" \
"postgresql-${PG_MAJOR}-pg-qualstats" \
"postgresql-${PG_MAJOR}-pg-stat-kcache" \
"postgresql-${PG_MAJOR}-pgextwlist" \
"postgresql-${PG_MAJOR}-pgfaceting" \
"postgresql-${PG_MAJOR}-pgfincore" \
"postgresql-${PG_MAJOR}-pglogical" \
"postgresql-${PG_MAJOR}-pglogical-ticker" \
"postgresql-${PG_MAJOR}-pgpcre" \
"postgresql-${PG_MAJOR}-powa" \
"postgresql-${PG_MAJOR}-repack" \
"postgresql-${PG_MAJOR}-roaringbitmap" \
"postgresql-${PG_MAJOR}-rum" \
"postgresql-${PG_MAJOR}-semver" \
"postgresql-${PG_MAJOR}-show-plans" \
"postgresql-${PG_MAJOR}-similarity" \
"postgresql-${PG_MAJOR}-squeeze" \
"postgresql-${PG_MAJOR}-tablelog" \
"postgresql-${PG_MAJOR}-tdigest" \
"postgresql-${PG_MAJOR}-timescaledb" \
"postgresql-${PG_MAJOR}-toastinfo" \
"postgresql-${PG_MAJOR}-unit" \
"postgresql-${PG_MAJOR}-wal2json" \
; \
2024-12-04 21:17:59 +03:00
apt-clean.sh ; \
jdupes -1LSpr /usr/
2024-08-13 09:20:08 +03:00
## ---
FROM postgresql-extras AS citus
2024-06-23 11:54:59 +03:00
SHELL [ "/bin/sh", "-ec" ]
2024-08-13 09:20:08 +03:00
COPY /apt/sources.citus /etc/apt/sources.list.d/citus.sources
RUN apt-install.sh \
"postgresql-${PG_MAJOR}-citus-12.1" \
"postgresql-${PG_MAJOR}-topn" \
2024-12-04 21:17:59 +03:00
; apt-clean.sh ; \
jdupes -1LSpr /usr/
2024-06-23 11:54:59 +03:00
2024-08-13 09:20:08 +03:00
VOLUME [ "${PGHOME}" ]
## ---
FROM citus
SHELL [ "/bin/sh", "-ec" ]
COPY /Dockerfile /usr/local/share/
## RFC: Python cache
2024-12-04 21:17:59 +03:00
COPY --from=pycache /pycache/ /usr/local/
2024-08-13 09:20:08 +03:00
COPY /ep.sh /usr/local/sbin/
COPY /postgres-shim.sh /usr/local/sbin/
2024-06-23 11:54:59 +03:00
## quirk
RUN ln -sv postgres-shim.sh /usr/local/sbin/postgres
2024-08-13 09:20:08 +03:00
WORKDIR "${PGHOME}"
## "Fast Shutdown mode" in PostgreSQL
## NB: override to SIGTERM in order to switch to "Smart Shutdown mode"
STOPSIGNAL SIGINT
ENV DUMB_INIT_SETSID=0 \
MALLOC_ARENA_MAX=4 \
GOMAXPROCS=4
2024-06-23 11:54:59 +03:00
ENTRYPOINT [ "ep.sh" ]
CMD [ "postgres" ]