Skip to content

Commit

Permalink
build(Docker): improve image size, by deleting node-compile-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
pano9000 committed Mar 7, 2025
1 parent 907b8c5 commit 70e227f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
12 changes: 8 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down
7 changes: 5 additions & 2 deletions Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -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
Expand Down

0 comments on commit 70e227f

Please sign in to comment.