refactor
This commit is contained in:
172
Dockerfile
172
Dockerfile
@@ -1,22 +1,168 @@
|
||||
FROM docker.io/rockdrilla/postgresql:16.3-base
|
||||
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 /Dockerfile /usr/local/share/
|
||||
COPY /scripts/* /usr/local/sbin/
|
||||
|
||||
COPY /ep.sh /usr/local/sbin/
|
||||
COPY /postgres-shim.sh /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" {} +
|
||||
|
||||
## ---
|
||||
|
||||
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
|
||||
|
||||
COPY --from=postgresql-upstream /etc/postgresql-common/createcluster.conf /etc/postgresql-common/
|
||||
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}/"
|
||||
COPY --from=postgresql-upstream /usr/share/postgresql/postgresql.conf.sample /usr/share/postgresql/
|
||||
|
||||
ENV PATH=${PATH}:/usr/lib/postgresql/${PG_MAJOR}/bin
|
||||
|
||||
COPY --from=postgresql-upstream /docker-entrypoint-initdb.d/ /docker-entrypoint-initdb.d/
|
||||
COPY --from=postgresql-upstream /usr/local/bin/*.sh /usr/local/bin/
|
||||
## 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" \
|
||||
; \
|
||||
apt-clean.sh
|
||||
|
||||
## ---
|
||||
|
||||
FROM postgresql-extras AS citus
|
||||
SHELL [ "/bin/sh", "-ec" ]
|
||||
|
||||
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" \
|
||||
; apt-clean.sh
|
||||
|
||||
VOLUME [ "${PGHOME}" ]
|
||||
|
||||
## ---
|
||||
|
||||
FROM citus
|
||||
SHELL [ "/bin/sh", "-ec" ]
|
||||
|
||||
COPY /Dockerfile /usr/local/share/
|
||||
|
||||
## RFC: Python cache
|
||||
## TODO: reduce load by selecting only __pycache__ directories in either way
|
||||
COPY --from=pycache /usr/local/lib/ /usr/local/lib/
|
||||
|
||||
COPY /ep.sh /usr/local/sbin/
|
||||
COPY /postgres-shim.sh /usr/local/sbin/
|
||||
## quirk
|
||||
RUN ln -sv postgres-shim.sh /usr/local/sbin/postgres
|
||||
|
||||
RUN site_packages=$(python3 -c 'import site;print(site.getsitepackages()[0])') ; \
|
||||
rm -rf \
|
||||
"${site_packages}/etcd/tests" \
|
||||
"${site_packages}/psutil/tests" \
|
||||
; \
|
||||
find "${site_packages}/" -maxdepth 1 -type f -name '*.py' -exec python3 -m compileall -q -j 2 {} + ; \
|
||||
find "${site_packages}/" -mindepth 1 -maxdepth 1 -type d -printf '%P\0' \
|
||||
| sed -zE '/\.dist-info$/d;/^(_distutils_hack|pip|pkg_resources|setuptools|wheel)$/d' \
|
||||
| env -C "${site_packages}" xargs -0r python3 -m compileall -q -j 2
|
||||
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
|
||||
|
||||
ENTRYPOINT [ "ep.sh" ]
|
||||
CMD [ "postgres" ]
|
||||
|
Reference in New Issue
Block a user