Optimisations in the Dockerfile

* mount .git from host instead of copying & removing
* use tmpfs for build cache in Dockerfile
* avoid rerunning apk when requirements.txt changes
pull/9488/head
Guiorgy 2026-01-01 12:30:49 +04:00 committed by GitHub
parent a9bf4c23bc
commit 30f032b7d8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 9 additions and 10 deletions

View File

@ -31,7 +31,6 @@ RUN apk add --no-cache \
yarn \ yarn \
zlib-dev zlib-dev
COPY .git /pgadmin4/.git
# Create the /pgadmin4 directory and copy the source into it. Explicitly # Create the /pgadmin4 directory and copy the source into it. Explicitly
# remove the node_modules directory as we'll recreate a clean version, as well # remove the node_modules directory as we'll recreate a clean version, as well
# as various other files we don't want # as various other files we don't want
@ -40,23 +39,23 @@ COPY web /pgadmin4/web
WORKDIR /pgadmin4/web WORKDIR /pgadmin4/web
# Build the JS vendor code in the app-builder, and then remove the vendor source. # Build the JS vendor code in the app-builder, and then remove the vendor source.
RUN export CPPFLAGS="-DPNG_ARM_NEON_OPT=0" && \ RUN --mount=type=bind,source=.git,target=/pgadmin4/.git \
--mount=type=tmpfs,target=node_modules \
--mount=type=tmpfs,target=pgadmin/static/js/generated/.cache \
export CPPFLAGS="-DPNG_ARM_NEON_OPT=0" && \
npm install -g corepack && \ npm install -g corepack && \
corepack enable && \ corepack enable && \
yarn set version berry && \ yarn set version berry && \
yarn set version 4 && \ yarn set version 4 && \
yarn install && \ yarn install && \
yarn run bundle && \ yarn run bundle && \
rm -rf node_modules \ rm -rf yarn.lock \
yarn.lock \
package.json \ package.json \
.[^.]* \ .[^.]* \
babel.cfg \ babel.cfg \
webpack.* \ webpack.* \
jest.config.js \ jest.config.js \
babel.* \ babel.*
./pgadmin/static/js/generated/.cache \
/pgadmin4/.git
######################################################################### #########################################################################
# Next, create the base environment for Python # Next, create the base environment for Python
@ -65,7 +64,6 @@ RUN export CPPFLAGS="-DPNG_ARM_NEON_OPT=0" && \
FROM python:3-alpine AS env-builder FROM python:3-alpine AS env-builder
# Install dependencies # Install dependencies
COPY requirements.txt /
RUN apk add --no-cache \ RUN apk add --no-cache \
make && \ make && \
apk add --no-cache --virtual build-deps \ apk add --no-cache --virtual build-deps \
@ -78,8 +76,9 @@ RUN apk add --no-cache \
cargo \ cargo \
zlib-dev \ zlib-dev \
libjpeg-turbo-dev \ libjpeg-turbo-dev \
libpng-dev && \ libpng-dev
python3 -m venv --system-site-packages --without-pip /venv && \ COPY requirements.txt /
RUN python3 -m venv --system-site-packages --without-pip /venv && \
/venv/bin/python3 -m pip install --no-cache-dir -r requirements.txt && \ /venv/bin/python3 -m pip install --no-cache-dir -r requirements.txt && \
apk del --no-cache build-deps apk del --no-cache build-deps