201 lines
6.0 KiB
Docker
201 lines
6.0 KiB
Docker
ARG PYTHONTAG=3.11.9-slim-bookworm
|
|
FROM localhost/local-python:${PYTHONTAG} as base
|
|
FROM docker.io/library/postgres:16.3-bookworm as postgresql-upstream
|
|
|
|
## ---
|
|
|
|
FROM base as postgresql
|
|
SHELL [ "/bin/sh", "-ec" ]
|
|
|
|
COPY /scripts/* /usr/local/sbin/
|
|
|
|
RUN apt-install.sh \
|
|
ca-certificates \
|
|
curl \
|
|
dumb-init \
|
|
file \
|
|
gnupg \
|
|
iproute2 \
|
|
iputils-ping \
|
|
jq \
|
|
less \
|
|
libnss-wrapper \
|
|
lsof \
|
|
ncurses-base \
|
|
netbase \
|
|
procps \
|
|
psmisc \
|
|
tzdata \
|
|
vim \
|
|
xxd \
|
|
xz-utils \
|
|
zstd \
|
|
; apt-clean.sh
|
|
|
|
ENV PG_MAJOR=16
|
|
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" ]
|
|
|
|
## set up locales!
|
|
RUN _lang=en_US.UTF8 ; \
|
|
{ \
|
|
echo "locales locales/default_environment_locale select ${LANG}" ; \
|
|
echo "locales locales/locales_to_be_generated multiselect ${LANG} UTF-8" ; \
|
|
} | debconf-set-selections ; \
|
|
f=/etc/dpkg/dpkg.cfg.d/docker ; \
|
|
if [ -f "$f" ] ; then \
|
|
sed -Ei '/\/usr\/share\/locale/d' "$f" ; \
|
|
fi ; \
|
|
echo "LANG=${_lang}" > /etc/default/locale ; \
|
|
apt-install.sh locales ; apt-clean.sh ; \
|
|
grep -Fixq "${_lang} UTF-8" /etc/locale.gen || { \
|
|
echo "${_lang} UTF-8" >> /etc/locale.gen ; \
|
|
locale-gen ; \
|
|
} ; \
|
|
locale -a | grep -Fixq "${_lang}"
|
|
ENV LANG=en_US.UTF8
|
|
|
|
ADD https://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc /etc/apt/keyrings/pgdg.gpg.bin
|
|
COPY /apt/sources.pgdg /etc/apt/sources.list.d/pgdg.sources
|
|
RUN env -C /etc/apt/keyrings gpg-export.sh pgdg.gpg.bin pgdg.gpg.asc
|
|
|
|
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 \
|
|
"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" ]
|
|
|
|
ADD https://packagecloud.io/citusdata/community/gpgkey /etc/apt/keyrings/citus.gpg.bin
|
|
COPY /apt/sources.citus /etc/apt/sources.list.d/citus.sources
|
|
RUN env -C /etc/apt/keyrings gpg-export.sh citus.gpg.bin citus.gpg.asc
|
|
RUN apt-install.sh \
|
|
"postgresql-${PG_MAJOR}-citus-12.1" \
|
|
"postgresql-${PG_MAJOR}-topn" \
|
|
; apt-clean.sh
|
|
|
|
VOLUME [ "${PGHOME}" ]
|
|
|
|
## ---
|
|
|
|
FROM postgresql as patroni-build
|
|
SHELL [ "/bin/sh", "-ec" ]
|
|
|
|
# pyyaml
|
|
ENV PYYAML_FORCE_CYTHON=1
|
|
# psutil
|
|
ENV CIBUILDWHEEL=1
|
|
|
|
RUN apt-install.sh \
|
|
build-essential \
|
|
libffi-dev \
|
|
libpq-dev \
|
|
libyaml-dev \
|
|
; \
|
|
apt-clean.sh
|
|
|
|
RUN pip-env.sh pip install --no-binary :all: 'psycopg[c,pool]' ; \
|
|
pip-env.sh pip install 'cython' ; \
|
|
pip-env.sh pip install --no-binary 'cffi,psutil,pyyaml' 'patroni[etcd3,kubernetes,raft]' ; \
|
|
pip-env.sh pip uninstall -y 'cython' ; \
|
|
site_packages=$(python3 -c 'import site;print(site.getsitepackages()[0])') ; \
|
|
pip-clean.sh "${site_packages}" ; \
|
|
find "${site_packages}/" -type f -name '*.so*' -exec ls -l {} + ; \
|
|
echo ; \
|
|
find "${site_packages}/" -type f -name '*.so*' -printf '%P\0' \
|
|
| sed -zE '/rust/d' \
|
|
| env -C "${site_packages}" xargs -0r strip --strip-debug ; \
|
|
echo ; \
|
|
find "${site_packages}/" -type f -name '*.so*' -exec ls -l {} +
|
|
|
|
## ---
|
|
|
|
FROM citus as patroni
|
|
SHELL [ "/bin/sh", "-ec" ]
|
|
|
|
COPY /Dockerfile.interim /usr/local/share/
|
|
|
|
COPY --from=patroni-build /usr/local/bin/ /usr/local/bin/
|
|
COPY --from=patroni-build /usr/local/lib/python3.11/site-packages/ /usr/local/lib/python3.11/site-packages/
|
|
|
|
RUN apt-install.sh \
|
|
libyaml-0-2 \
|
|
; apt-clean.sh
|
|
|
|
WORKDIR "${PGHOME}"
|
|
|
|
## "Fast Shutdown mode" in PostgreSQL
|
|
## NB: override to SIGTERM in order to switch to "Smart Shutdown mode"
|
|
STOPSIGNAL SIGINT
|
|
|
|
ENTRYPOINT [ "docker-entrypoint.sh" ]
|
|
CMD [ "postgres" ]
|
|
|
|
ENV DUMB_INIT_SETSID=0 \
|
|
MALLOC_ARENA_MAX=4 \
|
|
GOMAXPROCS=4
|