From 70e227f4c3b7facc1744d2a8dec87c1b7867e494 Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 5 Mar 2025 09:09:54 +0100 Subject: [PATCH] build(Docker): improve image size, by deleting node-compile-cache --- Dockerfile | 12 ++++++++---- Dockerfile.alpine | 7 +++++-- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index c21d9f4f6..2436a8124 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,7 +14,9 @@ RUN npm ci && \ mv dist/* \ start-docker.sh \ /usr/src/app/ && \ - rm -rf /usr/src/app/build + rm -rf \ + /usr/src/app/build \ + /tmp/node-compile-cache #TODO: improve node_modules handling in copy-dist/Dockerfile -> remove duplicated work # currently copy-dist will copy certain node_module folders, but in the Dockerfile we delete them again (to keep image size down), @@ -29,14 +31,16 @@ WORKDIR /usr/src/app RUN apt-get update && \ apt-get install -y --no-install-recommends \ gosu && \ - rm -rf /var/lib/apt/lists/* && \ - rm -rf /var/cache/apt/* + rm -rf \ + /var/lib/apt/lists/* \ + /var/cache/apt/* COPY --from=builder /usr/src/app ./ RUN sed -i "/electron/d" package.json && \ npm ci --omit=dev && \ - npm cache clean --force + npm cache clean --force && \ + rm -rf /tmp/node-compile-cache # Configure container EXPOSE 8080 diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 09efe2529..9370bd6da 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -14,7 +14,9 @@ RUN npm ci && \ mv dist/* \ start-docker.sh \ /usr/src/app/ && \ - rm -rf /usr/src/app/build + rm -rf \ + /usr/src/app/build \ + /tmp/node-compile-cache #TODO: improve node_modules handling in copy-dist/Dockerfile -> remove duplicated work # currently copy-dist will copy certain node_module folders, but in the Dockerfile we delete them again (to keep image size down), @@ -32,7 +34,8 @@ COPY --from=builder /usr/src/app ./ RUN sed -i "/electron/d" package.json && \ npm ci --omit=dev && \ - npm cache clean --force + npm cache clean --force && \ + rm -rf /tmp/node-compile-cache # Add application user RUN adduser -s /bin/false node; exit 0