From 38690053a8cb2c1e4c77d9dae2ef78b5360eccba Mon Sep 17 00:00:00 2001 From: Panagiotis Papadopoulos Date: Wed, 5 Mar 2025 08:54:42 +0100 Subject: [PATCH] build(Docker): improve image size, by deleting unnecessary node_modules fodler from dist folder added a TODO as well, to get rid of this strange step here at some point --- Dockerfile | 4 ++++ Dockerfile.alpine | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Dockerfile b/Dockerfile index 54db47144..52a087202 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,6 +10,7 @@ COPY . . RUN npm ci && \ npm run build:prepare-dist && \ npm cache clean --force && \ + rm -rf dist/node_modules && \ mv dist/* \ start-docker.sh \ package-lock.json \ @@ -17,6 +18,9 @@ RUN npm ci && \ rm -rf /usr/src/app/build #TODO: move package-lock copying into copy-dist +#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), +# as we install necessary dependencies in runtime buildstage anyways # Runtime stage FROM node:22.14.0-bullseye-slim diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 43eac8ca7..3d2198bf0 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -10,6 +10,7 @@ COPY . . RUN npm ci && \ npm run build:prepare-dist && \ npm cache clean --force && \ + rm -rf dist/node_modules && \ mv dist/* \ start-docker.sh \ package-lock.json \ @@ -17,6 +18,9 @@ RUN npm ci && \ rm -rf /usr/src/app/build #TODO: move package-lock copying into copy-dist +#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), +# as we install necessary dependencies in runtime buildstage anyways # Runtime stage FROM node:22.14.0-alpine