Skip to content

Commit 30f032b

Browse files
authored
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
1 parent a9bf4c2 commit 30f032b

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

Dockerfile

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ RUN apk add --no-cache \
3131
yarn \
3232
zlib-dev
3333

34-
COPY .git /pgadmin4/.git
3534
# Create the /pgadmin4 directory and copy the source into it. Explicitly
3635
# remove the node_modules directory as we'll recreate a clean version, as well
3736
# as various other files we don't want
@@ -40,23 +39,23 @@ COPY web /pgadmin4/web
4039
WORKDIR /pgadmin4/web
4140

4241
# Build the JS vendor code in the app-builder, and then remove the vendor source.
43-
RUN export CPPFLAGS="-DPNG_ARM_NEON_OPT=0" && \
42+
RUN --mount=type=bind,source=.git,target=/pgadmin4/.git \
43+
--mount=type=tmpfs,target=node_modules \
44+
--mount=type=tmpfs,target=pgadmin/static/js/generated/.cache \
45+
export CPPFLAGS="-DPNG_ARM_NEON_OPT=0" && \
4446
npm install -g corepack && \
4547
corepack enable && \
4648
yarn set version berry && \
4749
yarn set version 4 && \
4850
yarn install && \
4951
yarn run bundle && \
50-
rm -rf node_modules \
51-
yarn.lock \
52+
rm -rf yarn.lock \
5253
package.json \
5354
.[^.]* \
5455
babel.cfg \
5556
webpack.* \
5657
jest.config.js \
57-
babel.* \
58-
./pgadmin/static/js/generated/.cache \
59-
/pgadmin4/.git
58+
babel.*
6059

6160
#########################################################################
6261
# Next, create the base environment for Python
@@ -65,7 +64,6 @@ RUN export CPPFLAGS="-DPNG_ARM_NEON_OPT=0" && \
6564
FROM python:3-alpine AS env-builder
6665

6766
# Install dependencies
68-
COPY requirements.txt /
6967
RUN apk add --no-cache \
7068
make && \
7169
apk add --no-cache --virtual build-deps \
@@ -78,8 +76,9 @@ RUN apk add --no-cache \
7876
cargo \
7977
zlib-dev \
8078
libjpeg-turbo-dev \
81-
libpng-dev && \
82-
python3 -m venv --system-site-packages --without-pip /venv && \
79+
libpng-dev
80+
COPY requirements.txt /
81+
RUN python3 -m venv --system-site-packages --without-pip /venv && \
8382
/venv/bin/python3 -m pip install --no-cache-dir -r requirements.txt && \
8483
apk del --no-cache build-deps
8584

0 commit comments

Comments
 (0)