refactor layout
python extensions are built using strictly versioned libpq-dev
This commit is contained in:
138
Dockerfile
138
Dockerfile
@@ -1,11 +1,11 @@
|
||||
ARG UPSTREAM_IMAGE_VERSION
|
||||
ARG DEPS_IMAGE
|
||||
ARG BASE_IMAGE
|
||||
FROM docker.io/library/postgres:${UPSTREAM_IMAGE_VERSION}-trixie AS postgresql-upstream
|
||||
FROM ${DEPS_IMAGE} AS deps
|
||||
FROM ${BASE_IMAGE} AS base
|
||||
|
||||
## ---
|
||||
|
||||
FROM deps AS postgresql
|
||||
FROM base AS postgresql
|
||||
SHELL [ "/bin/sh", "-ec" ]
|
||||
|
||||
COPY /scripts/* /usr/local/sbin/
|
||||
@@ -22,7 +22,9 @@ RUN echo "postgres:x:${PG_UID}:${PG_GID}:postgres:${PGHOME}:/bin/bash" >> /etc/p
|
||||
RUN install -d -o postgres -g postgres -m 3755 /run/postgresql
|
||||
VOLUME [ "/run/postgresql" ]
|
||||
|
||||
COPY /apt/sources.pgdg /etc/apt/sources.list.d/pgdg.sources
|
||||
COPY /apt/sources.pgdg-ver.in /tmp/pgdg-ver.sources
|
||||
COPY /apt/preferences.pgdg /etc/apt/preferences.d/pgdg
|
||||
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}" ; \
|
||||
@@ -48,7 +50,135 @@ RUN ln -sv /usr/local/sbin/dumb-run-as.sh /usr/local/bin/gosu
|
||||
|
||||
## ---
|
||||
|
||||
FROM postgresql AS postgresql-extras
|
||||
FROM postgresql AS pybuild
|
||||
SHELL [ "/bin/sh", "-ec" ]
|
||||
|
||||
COPY /scripts/* /usr/local/sbin/
|
||||
|
||||
COPY /requirements.txt /tmp/
|
||||
|
||||
ENV DEV_PACKAGES='libffi-dev libpq-dev libyaml-dev'
|
||||
# psutil
|
||||
ENV CIBUILDWHEEL=1
|
||||
# pyyaml
|
||||
ENV PYYAML_FORCE_CYTHON=1
|
||||
|
||||
RUN w=$(mktemp -d) ; : "${w:?}" ; \
|
||||
{ apt-mark showauto ; apt-mark showmanual ; } | sort -uV > "$w/t0" ; \
|
||||
printf '%s\n' ${DEV_PACKAGES} | sort -uV > "$w/t1" ; \
|
||||
apt-install.sh ${DEV_PACKAGES} ; \
|
||||
{ apt-mark showauto ; apt-mark showmanual ; } | sort -uV > "$w/t2" ; \
|
||||
set +e ; \
|
||||
grep -Fxv -f "$w/t0" "$w/t2" > "$w/t3" ; \
|
||||
grep -Fxv -f "$w/t1" "$w/t3" > "$w/t4" ; \
|
||||
grep -Ev -e '-(dev|doc)$' "$w/t4" > "${PYTHON_SITE_PACKAGES}/apt-deps.txt" ; \
|
||||
set -e ; \
|
||||
rm -rf "$w/" ; unset w ; \
|
||||
apt-install.sh build-essential ; \
|
||||
pip-env.sh pip install 'cython~=3.1.3' ; \
|
||||
pip-env.sh pip install \
|
||||
--no-binary 'cffi,psutil,pyyaml' \
|
||||
-r /tmp/requirements.txt \
|
||||
; \
|
||||
pip-env.sh pip uninstall -y 'cython' ; \
|
||||
python-rm-cache.sh /usr/local ; \
|
||||
rm -rf \
|
||||
/usr/local/bin/patroni_aws \
|
||||
/usr/local/bin/patroni_raft_controller \
|
||||
"${PYTHON_SITE_PACKAGES}/etcd/tests" \
|
||||
"${PYTHON_SITE_PACKAGES}/netaddr/tests" \
|
||||
"${PYTHON_SITE_PACKAGES}/psutil/tests" \
|
||||
; \
|
||||
truncate -s 0 \
|
||||
"${PYTHON_SITE_PACKAGES}/netaddr/eui/iab.idx" \
|
||||
"${PYTHON_SITE_PACKAGES}/netaddr/eui/iab.txt" \
|
||||
"${PYTHON_SITE_PACKAGES}/netaddr/eui/oui.txt" \
|
||||
"${PYTHON_SITE_PACKAGES}/netaddr/eui/oui.idx" \
|
||||
; \
|
||||
find "${PYTHON_SITE_PACKAGES}/" -type f -name '*.so*' -exec ls -l {} + ; \
|
||||
echo ; \
|
||||
find "${PYTHON_SITE_PACKAGES}/" -type f -name '*.so*' -printf '%p\0' \
|
||||
| sed -zE '/rust/d' \
|
||||
| xargs -0r strip --strip-debug --strip-unneeded ; \
|
||||
echo ; \
|
||||
find "${PYTHON_SITE_PACKAGES}/" -type f -name '*.so*' -exec ls -l {} + ; \
|
||||
apt-remove.sh build-essential ; \
|
||||
apt-clean.sh
|
||||
|
||||
## avoid changing already present packages
|
||||
RUN rm -rfv \
|
||||
/usr/local/bin/pip \
|
||||
/usr/local/bin/pip3* \
|
||||
; \
|
||||
find "${PYTHON_SITE_PACKAGES}/" -mindepth 1 -maxdepth 1 -printf '%P\0' \
|
||||
| sed -zEn \
|
||||
-e '/^pip(|-.+\.dist-info)$/p' \
|
||||
| env -C "${PYTHON_SITE_PACKAGES}" xargs -0r rm -rf
|
||||
|
||||
## ---
|
||||
|
||||
FROM pybuild 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 '/^(asyncio|collections|concurrent|ctypes|email|encodings|html|http|importlib|json|logging|multiprocessing|re|urllib|zipfile|zoneinfo)$/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|so|txt)$/d' \
|
||||
-e '/^pip$/d' \
|
||||
| sort -zV \
|
||||
| env -C "${PYTHON_SITE_PACKAGES}" xargs -0r \
|
||||
python3 -m compileall -q -j 2
|
||||
|
||||
## Python cache warmup
|
||||
RUN export PYTHONPROFILEIMPORTTIME=1 ; \
|
||||
patroni --help ; \
|
||||
patronictl --help ; \
|
||||
patroni_barman --help ; \
|
||||
patroni_wale_restore --help ; \
|
||||
cdiff --help ; \
|
||||
netaddr --help ; \
|
||||
ydiff --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" {} +
|
||||
|
||||
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 -
|
||||
|
||||
## ---
|
||||
|
||||
FROM postgresql AS postgresql-patroni
|
||||
|
||||
COPY --from=pybuild /usr/local/bin/ /usr/local/bin/
|
||||
COPY --from=pybuild /${PYTHON_SITE_PACKAGES}/ /${PYTHON_SITE_PACKAGES}/
|
||||
COPY --from=pycache /pycache/ /usr/local/
|
||||
|
||||
## install missing dependencies for Python site-packages
|
||||
RUN f="${PYTHON_SITE_PACKAGES}/apt-deps.txt" ; \
|
||||
[ -s "$f" ] || exit 0 ; \
|
||||
xargs -a "$f" apt-install.sh ; \
|
||||
apt-clean.sh
|
||||
|
||||
## ---
|
||||
|
||||
FROM postgresql-patroni AS postgresql-extras
|
||||
SHELL [ "/bin/sh", "-ec" ]
|
||||
|
||||
RUN apt-install.sh \
|
||||
|
@@ -271,9 +271,6 @@ RUN env -C /root rm -f .bash_history .python_history .wget-hsts
|
||||
FROM base-intermediate AS certs
|
||||
SHELL [ "/bin/sh", "-ec" ]
|
||||
|
||||
COPY /scripts/* /usr/local/sbin/
|
||||
COPY /extra-scripts/* /usr/local/sbin/
|
||||
|
||||
## "2025.08.03"
|
||||
ENV CERTIFI_COMMIT=a97d9ad8f87c382378dddc0b0b33b9770932404e
|
||||
|
||||
@@ -299,9 +296,6 @@ RUN apt-install.sh ca-certificates ; \
|
||||
FROM base-intermediate AS apt-gpg
|
||||
SHELL [ "/bin/sh", "-ec" ]
|
||||
|
||||
COPY /scripts/* /usr/local/sbin/
|
||||
COPY /extra-scripts/* /usr/local/sbin/
|
||||
|
||||
COPY --from=certs /etc/ssl/certs/ca-certificates.* /etc/ssl/certs/
|
||||
|
||||
ADD https://apt.postgresql.org/pub/repos/apt/ACCC4CF8.asc /tmp/pgdg.gpg.bin
|
||||
@@ -324,6 +318,58 @@ RUN apt-env.sh apt-get update ; \
|
||||
|
||||
## ---
|
||||
|
||||
FROM base-intermediate AS tools
|
||||
SHELL [ "/bin/sh", "-ec" ]
|
||||
|
||||
## current HEAD: "main: don't use secure_getenv", December 14, 2024
|
||||
ENV CATATONIT_COMMIT=56579adbb42c0c7ad94fc12d844b38fc5b37b3ce
|
||||
|
||||
# ARG CATATONIT_BASE_URI='https://codeload.github.com/openSUSE/catatonit/tar.gz'
|
||||
# ARG CATATONIT_URI="${CATATONIT_BASE_URI}/${CATATONIT_COMMIT}"
|
||||
|
||||
ARG CATATONIT_BASE_URI='https://github.com/openSUSE/catatonit/archive'
|
||||
ARG CATATONIT_URI="${CATATONIT_BASE_URI}/${CATATONIT_COMMIT}.tar.gz"
|
||||
|
||||
# hadolint ignore=DL3020
|
||||
ADD "${CATATONIT_URI}" /tmp/catatonit.tar.gz
|
||||
|
||||
RUN pkg='build-essential debhelper musl-dev autoconf autoconf-archive' ; \
|
||||
apt-install.sh ${pkg} ; \
|
||||
DEB_HOST_GNU_TYPE=$(dpkg-architecture -q DEB_HOST_GNU_TYPE) ; \
|
||||
export HOSTCC="${DEB_HOST_GNU_TYPE}-gcc" ; \
|
||||
DEB_TARGET_GNU_TYPE=$(dpkg-architecture -q DEB_TARGET_GNU_TYPE) ; \
|
||||
DEB_TARGET_MUSL_TYPE=$(printf '%s' "${DEB_TARGET_GNU_TYPE}" | sed -E 's/-gnu$/-musl/') ; \
|
||||
CFLAGS_LTO="-flto=2 -fuse-linker-plugin -ffat-lto-objects -flto-partition=none" ; \
|
||||
CFLAGS_COMMON="-O2 -g -pipe -fPIE -fstack-protector-strong -fstack-clash-protection -fcf-protection" ; \
|
||||
CPPFLAGS="-Wall -Wextra -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2" ; \
|
||||
## build catatonit
|
||||
d=/tmp/catatonit ; \
|
||||
rm -rf "$d" ; \
|
||||
mkdir -p "$d" ; \
|
||||
( \
|
||||
cd "$d" ; \
|
||||
tar --strip-components=1 -xf /tmp/catatonit.tar.gz ; \
|
||||
commit_abbrev=$(printf '%s' "${CATATONIT_COMMIT}" | cut -c1-8) ; \
|
||||
sed -i "s/+dev/+git.${commit_abbrev}/" configure.ac ; \
|
||||
export CC="${DEB_TARGET_MUSL_TYPE}-gcc" ; \
|
||||
export CFLAGS="${CFLAGS_LTO} ${CFLAGS_COMMON} ${CPPFLAGS}" ; \
|
||||
export LDFLAGS="-static-pie -Wl,-z,relro -Wl,-z,now" ; \
|
||||
autoreconf -fiv ; \
|
||||
./configure ; \
|
||||
make -j1 ; \
|
||||
ls -l catatonit ; \
|
||||
# "${DEB_TARGET_GNU_TYPE}-strip" --strip-debug --strip-unneeded catatonit ; \
|
||||
strip --strip-debug --strip-unneeded catatonit ; \
|
||||
ls -l catatonit ; \
|
||||
cp catatonit /usr/local/bin/ ; \
|
||||
) ; \
|
||||
## cleanup
|
||||
rm -rf "$d" ; \
|
||||
apt-remove.sh ${pkg} ; \
|
||||
apt-clean.sh
|
||||
|
||||
## ---
|
||||
|
||||
FROM base-intermediate AS base
|
||||
SHELL [ "/bin/sh", "-ec" ]
|
||||
|
||||
@@ -331,6 +377,7 @@ COPY /Dockerfile.base /usr/local/share/
|
||||
|
||||
COPY --from=certs /etc/ssl/certs/ca-certificates.* /etc/ssl/certs/
|
||||
COPY --from=apt-gpg /etc/apt/keyrings/ /etc/apt/keyrings/
|
||||
COPY --from=tools /usr/local/bin/catatonit /usr/local/bin/
|
||||
|
||||
RUN python-rm-cache.sh /usr/local
|
||||
|
||||
@@ -359,7 +406,24 @@ RUN certifi_pem="${PYTHON_SITE_PACKAGES}/pip/_vendor/certifi/cacert.pem" ; \
|
||||
rm -f "${certifi_pem}" ; \
|
||||
ln -sv /etc/ssl/certs/ca-certificates.crt "${certifi_pem}"
|
||||
|
||||
RUN apt-clean.sh
|
||||
## 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
|
||||
|
||||
RUN find /usr/local/sbin/ ! -type d -ls -delete ; \
|
||||
find /run/ -mindepth 1 -ls -delete || : ; \
|
||||
|
225
Dockerfile.deps
225
Dockerfile.deps
@@ -1,225 +0,0 @@
|
||||
ARG BASE_IMAGE
|
||||
FROM ${BASE_IMAGE} AS base
|
||||
|
||||
## ---
|
||||
|
||||
FROM base AS tools
|
||||
SHELL [ "/bin/sh", "-ec" ]
|
||||
|
||||
COPY /scripts/* /usr/local/sbin/
|
||||
COPY /extra-scripts/* /usr/local/sbin/
|
||||
|
||||
## current HEAD: "main: don't use secure_getenv", December 14, 2024
|
||||
ENV CATATONIT_COMMIT=56579adbb42c0c7ad94fc12d844b38fc5b37b3ce
|
||||
|
||||
# ARG CATATONIT_BASE_URI='https://codeload.github.com/openSUSE/catatonit/tar.gz'
|
||||
# ARG CATATONIT_URI="${CATATONIT_BASE_URI}/${CATATONIT_COMMIT}"
|
||||
|
||||
ARG CATATONIT_BASE_URI='https://github.com/openSUSE/catatonit/archive'
|
||||
ARG CATATONIT_URI="${CATATONIT_BASE_URI}/${CATATONIT_COMMIT}.tar.gz"
|
||||
|
||||
# hadolint ignore=DL3020
|
||||
ADD "${CATATONIT_URI}" /tmp/catatonit.tar.gz
|
||||
|
||||
RUN pkg='build-essential debhelper musl-dev autoconf autoconf-archive' ; \
|
||||
apt-install.sh ${pkg} ; \
|
||||
DEB_HOST_GNU_TYPE=$(dpkg-architecture -q DEB_HOST_GNU_TYPE) ; \
|
||||
export HOSTCC="${DEB_HOST_GNU_TYPE}-gcc" ; \
|
||||
DEB_TARGET_GNU_TYPE=$(dpkg-architecture -q DEB_TARGET_GNU_TYPE) ; \
|
||||
DEB_TARGET_MUSL_TYPE=$(printf '%s' "${DEB_TARGET_GNU_TYPE}" | sed -E 's/-gnu$/-musl/') ; \
|
||||
CFLAGS_LTO="-flto=2 -fuse-linker-plugin -ffat-lto-objects -flto-partition=none" ; \
|
||||
CFLAGS_COMMON="-O2 -g -pipe -fPIE -fstack-protector-strong -fstack-clash-protection -fcf-protection" ; \
|
||||
CPPFLAGS="-Wall -Wextra -Werror=format-security -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2" ; \
|
||||
## build catatonit
|
||||
d=/tmp/catatonit ; \
|
||||
rm -rf "$d" ; \
|
||||
mkdir -p "$d" ; \
|
||||
( \
|
||||
cd "$d" ; \
|
||||
tar --strip-components=1 -xf /tmp/catatonit.tar.gz ; \
|
||||
commit_abbrev=$(printf '%s' "${CATATONIT_COMMIT}" | cut -c1-8) ; \
|
||||
sed -i "s/+dev/+git.${commit_abbrev}/" configure.ac ; \
|
||||
export CC="${DEB_TARGET_MUSL_TYPE}-gcc" ; \
|
||||
export CFLAGS="${CFLAGS_LTO} ${CFLAGS_COMMON} ${CPPFLAGS}" ; \
|
||||
export LDFLAGS="-static-pie -Wl,-z,relro -Wl,-z,now" ; \
|
||||
autoreconf -fiv ; \
|
||||
./configure ; \
|
||||
make -j1 ; \
|
||||
ls -l catatonit ; \
|
||||
# "${DEB_TARGET_GNU_TYPE}-strip" --strip-debug --strip-unneeded catatonit ; \
|
||||
strip --strip-debug --strip-unneeded catatonit ; \
|
||||
ls -l catatonit ; \
|
||||
cp catatonit /usr/local/bin/ ; \
|
||||
) ; \
|
||||
## cleanup
|
||||
rm -rf "$d" ; \
|
||||
apt-remove.sh ${pkg} ; \
|
||||
apt-clean.sh
|
||||
|
||||
## ---
|
||||
|
||||
FROM base AS patroni
|
||||
SHELL [ "/bin/sh", "-ec" ]
|
||||
|
||||
COPY /scripts/* /usr/local/sbin/
|
||||
|
||||
COPY /apt/sources.pgdg /etc/apt/sources.list.d/pgdg.sources
|
||||
COPY /apt/preferences.pgdg /etc/apt/preferences.d/pgdg
|
||||
|
||||
COPY /requirements.txt /tmp/
|
||||
|
||||
ENV DEV_PACKAGES='libffi-dev libpq-dev libyaml-dev'
|
||||
# psutil
|
||||
ENV CIBUILDWHEEL=1
|
||||
# pyyaml
|
||||
ENV PYYAML_FORCE_CYTHON=1
|
||||
|
||||
RUN w=$(mktemp -d) ; : "${w:?}" ; \
|
||||
{ apt-mark showauto ; apt-mark showmanual ; } | sort -uV > "$w/t0" ; \
|
||||
printf '%s\n' ${DEV_PACKAGES} | sort -uV > "$w/t1" ; \
|
||||
apt-install.sh ${DEV_PACKAGES} ; \
|
||||
{ apt-mark showauto ; apt-mark showmanual ; } | sort -uV > "$w/t2" ; \
|
||||
set +e ; \
|
||||
grep -Fxv -f "$w/t0" "$w/t2" > "$w/t3" ; \
|
||||
grep -Fxv -f "$w/t1" "$w/t3" > "$w/t4" ; \
|
||||
grep -Ev -e '-(dev|doc)$' "$w/t4" > "${PYTHON_SITE_PACKAGES}/apt-deps.txt" ; \
|
||||
set -e ; \
|
||||
rm -rf "$w/" ; unset w ; \
|
||||
apt-install.sh build-essential ; \
|
||||
pip-env.sh pip install 'cython~=3.1.3' ; \
|
||||
pip-env.sh pip install \
|
||||
--no-binary 'cffi,psutil,pyyaml' \
|
||||
-r /tmp/requirements.txt \
|
||||
; \
|
||||
pip-env.sh pip uninstall -y 'cython' ; \
|
||||
python-rm-cache.sh /usr/local ; \
|
||||
rm -rf \
|
||||
/usr/local/bin/patroni_aws \
|
||||
/usr/local/bin/patroni_raft_controller \
|
||||
"${PYTHON_SITE_PACKAGES}/etcd/tests" \
|
||||
"${PYTHON_SITE_PACKAGES}/netaddr/tests" \
|
||||
"${PYTHON_SITE_PACKAGES}/psutil/tests" \
|
||||
; \
|
||||
truncate -s 0 \
|
||||
"${PYTHON_SITE_PACKAGES}/netaddr/eui/iab.idx" \
|
||||
"${PYTHON_SITE_PACKAGES}/netaddr/eui/iab.txt" \
|
||||
"${PYTHON_SITE_PACKAGES}/netaddr/eui/oui.txt" \
|
||||
"${PYTHON_SITE_PACKAGES}/netaddr/eui/oui.idx" \
|
||||
; \
|
||||
find "${PYTHON_SITE_PACKAGES}/" -type f -name '*.so*' -exec ls -l {} + ; \
|
||||
echo ; \
|
||||
find "${PYTHON_SITE_PACKAGES}/" -type f -name '*.so*' -printf '%p\0' \
|
||||
| sed -zE '/rust/d' \
|
||||
| xargs -0r strip --strip-debug --strip-unneeded ; \
|
||||
echo ; \
|
||||
find "${PYTHON_SITE_PACKAGES}/" -type f -name '*.so*' -exec ls -l {} + ; \
|
||||
apt-remove.sh build-essential ; \
|
||||
apt-clean.sh
|
||||
|
||||
## avoid changing already present packages
|
||||
RUN rm -rfv \
|
||||
/usr/local/bin/pip \
|
||||
/usr/local/bin/pip3* \
|
||||
; \
|
||||
find "${PYTHON_SITE_PACKAGES}/" -mindepth 1 -maxdepth 1 -printf '%P\0' \
|
||||
| sed -zEn \
|
||||
-e '/^pip(|-.+\.dist-info)$/p' \
|
||||
| env -C "${PYTHON_SITE_PACKAGES}" xargs -0r rm -rf
|
||||
|
||||
## ---
|
||||
|
||||
FROM base AS deps-intermediate
|
||||
SHELL [ "/bin/sh", "-ec" ]
|
||||
|
||||
COPY /Dockerfile.deps /usr/local/share/
|
||||
|
||||
COPY /scripts/* /usr/local/sbin/
|
||||
|
||||
COPY /apt/sources.pgdg /etc/apt/sources.list.d/pgdg.sources
|
||||
COPY /apt/preferences.pgdg /etc/apt/preferences.d/pgdg
|
||||
|
||||
COPY --from=tools /usr/local/bin/catatonit /usr/local/bin/
|
||||
|
||||
COPY --from=patroni /usr/local/bin/ /usr/local/bin/
|
||||
COPY --from=patroni /${PYTHON_SITE_PACKAGES}/ /${PYTHON_SITE_PACKAGES}/
|
||||
|
||||
## install missing dependencies for Python site-packages
|
||||
RUN f="${PYTHON_SITE_PACKAGES}/apt-deps.txt" ; \
|
||||
[ -s "$f" ] || exit 0 ; \
|
||||
xargs -a "$f" apt-install.sh ; \
|
||||
apt-clean.sh
|
||||
|
||||
## 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
|
||||
|
||||
RUN find /usr/local/sbin/ ! -type d -ls -delete
|
||||
|
||||
## ---
|
||||
|
||||
FROM deps-intermediate 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 '/^(asyncio|collections|concurrent|ctypes|email|encodings|html|http|importlib|json|logging|multiprocessing|re|urllib|zipfile|zoneinfo)$/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|so|txt)$/d' \
|
||||
-e '/^pip$/d' \
|
||||
| sort -zV \
|
||||
| env -C "${PYTHON_SITE_PACKAGES}" xargs -0r \
|
||||
python3 -m compileall -q -j 2
|
||||
|
||||
## Python cache warmup
|
||||
RUN export PYTHONPROFILEIMPORTTIME=1 ; \
|
||||
patroni --help ; \
|
||||
patronictl --help ; \
|
||||
patroni_barman --help ; \
|
||||
patroni_wale_restore --help ; \
|
||||
cdiff --help ; \
|
||||
netaddr --help ; \
|
||||
ydiff --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" {} +
|
||||
|
||||
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 -
|
||||
|
||||
## ---
|
||||
|
||||
FROM deps-intermediate AS deps
|
||||
|
||||
## RFC: Python cache
|
||||
COPY --from=pycache /pycache/ /usr/local/
|
@@ -27,7 +27,7 @@ grab_site_packages() {
|
||||
PYTHON_SITE_PACKAGES=$(grab_site_packages "docker.io/python:${PYTHONTAG}")
|
||||
[ -n "${PYTHON_SITE_PACKAGES:?}" ]
|
||||
|
||||
img="docker.io/rockdrilla/postgresql:base-v6"
|
||||
img="docker.io/rockdrilla/postgresql:base-v7"
|
||||
|
||||
buildah bud \
|
||||
-f ./Dockerfile.base \
|
||||
|
@@ -1,18 +0,0 @@
|
||||
#!/bin/sh
|
||||
set -ef
|
||||
cd "$(dirname "$0")/.."
|
||||
|
||||
set -a
|
||||
BUILDAH_FORMAT="${BUILDAH_FORMAT:-docker}"
|
||||
BUILDAH_ISOLATION="${BUILDAH_ISOLATION:-chroot}"
|
||||
BUILDAH_NETWORK="${BUILDAH_NETWORK:-host}"
|
||||
set +a
|
||||
|
||||
img="docker.io/rockdrilla/postgresql:deps-v6"
|
||||
base="docker.io/rockdrilla/postgresql:base-v6"
|
||||
|
||||
exec buildah bud \
|
||||
-f ./Dockerfile.deps \
|
||||
-t "${img}" \
|
||||
--pull=missing --no-cache \
|
||||
--build-arg "BASE_IMAGE=${base}" \
|
@@ -8,24 +8,25 @@ BUILDAH_ISOLATION="${BUILDAH_ISOLATION:-chroot}"
|
||||
BUILDAH_NETWORK="${BUILDAH_NETWORK:-host}"
|
||||
set +a
|
||||
|
||||
POSTGRESQL_VERSION="${1:-16.7}"
|
||||
POSTGRESQL_VERSION="${1:-17.6}"
|
||||
PG_MAJOR="${POSTGRESQL_VERSION%%.*}"
|
||||
|
||||
img="docker.io/rockdrilla/postgresql:${POSTGRESQL_VERSION}"
|
||||
deps="docker.io/rockdrilla/postgresql:deps-v6"
|
||||
img="docker.io/rockdrilla/postgresql:${POSTGRESQL_VERSION}$2"
|
||||
orig_base="docker.io/rockdrilla/postgresql:base-v7"
|
||||
base="${orig_base}-${POSTGRESQL_VERSION}-env"
|
||||
|
||||
c=$(buildah from --pull=missing "${deps}")
|
||||
c=$(buildah from --pull=missing "${orig_base}")
|
||||
[ -n "${c:?}" ]
|
||||
buildah config --env "POSTGRESQL_VERSION=${POSTGRESQL_VERSION}" "$c"
|
||||
buildah config --env "PG_MAJOR=${PG_MAJOR}" "$c"
|
||||
buildah commit --rm "$c" "${img}-env"
|
||||
buildah commit --rm "$c" "${base}"
|
||||
unset c
|
||||
|
||||
buildah bud \
|
||||
-f ./Dockerfile \
|
||||
-t "${img}" \
|
||||
--pull=missing --no-cache \
|
||||
--build-arg "DEPS_IMAGE=${img}-env" \
|
||||
--build-arg "BASE_IMAGE=${base}" \
|
||||
--build-arg "UPSTREAM_IMAGE_VERSION=${POSTGRESQL_VERSION}" \
|
||||
|
||||
podman image rm "${img}-env"
|
||||
podman image rm "${base}"
|
||||
|
@@ -1,7 +1,7 @@
|
||||
## psycopg[c,pool]
|
||||
|
||||
psycopg-c==3.2.9
|
||||
typing_extensions==4.14.1
|
||||
typing_extensions==4.15.0
|
||||
psycopg-pool==3.2.6
|
||||
psycopg[c,pool]==3.2.9
|
||||
|
||||
|
Reference in New Issue
Block a user