share pycache

This commit is contained in:
Konstantin Demin 2025-02-21 11:28:45 +03:00
parent 20182ec83f
commit d8c7de04a5
Signed by: krd
GPG Key ID: 4D56F87A8BA65FD0
2 changed files with 50 additions and 48 deletions

View File

@ -5,50 +5,6 @@ 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" {} +
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 AS postgresql
SHELL [ "/bin/sh", "-ec" ]
@ -153,9 +109,6 @@ SHELL [ "/bin/sh", "-ec" ]
COPY /Dockerfile /usr/local/share/
## RFC: Python cache
COPY --from=pycache /pycache/ /usr/local/
COPY /ep.sh /usr/local/sbin/
COPY /postgres-shim.sh /usr/local/sbin/
## quirk

View File

@ -68,7 +68,7 @@ RUN find "${PYTHON_SITE_PACKAGES}/" -mindepth 1 -maxdepth 1 -printf '%P\0' \
## ---
FROM base AS deps
FROM base AS deps-intermediate
SHELL [ "/bin/sh", "-ec" ]
COPY /Dockerfile.deps /usr/local/share/
@ -108,3 +108,52 @@ ENV LANG=en_US.UTF8
RUN find /usr/local/sbin/ ! -type d -ls -delete ; \
jdupes -1LSpr /usr/
## ---
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 '/^(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" {} +
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/