From fd0af6b2dddce3f951f5a27da8e9568baaaeb59c Mon Sep 17 00:00:00 2001 From: Jaffar Ashoor Date: Sun, 23 Mar 2025 02:59:40 +0300 Subject: [PATCH 1/2] Reduce final docker image size this adds a third stage to the build, copying the required files only from the previos stages, this reduces the final image size from 600MB+ down to ~320MB --- Dockerfile | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4e110a61..3eea9cd5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,12 +1,12 @@ ### STAGE 0: Build client ### -FROM node:20-alpine AS build +FROM node:20-alpine AS build-client WORKDIR /client COPY /client /client RUN npm ci && npm cache clean --force RUN npm run generate ### STAGE 1: Build server ### -FROM node:20-alpine +FROM node:20-alpine AS build-server ENV NODE_ENV=production @@ -21,9 +21,9 @@ RUN apk update && \ tini \ unzip -COPY --from=build /client/dist /client/dist -COPY index.js package* / -COPY server server +WORKDIR /server +COPY index.js package* /server +COPY /server /server/server ARG TARGETPLATFORM @@ -42,7 +42,20 @@ RUN case "$TARGETPLATFORM" in \ RUN npm ci --only=production -RUN apk del make python3 g++ +### STAGE 2: Create minimal runtime image ### +FROM node:20-alpine + +# Install only runtime dependencies +RUN apk add --no-cache \ + tzdata \ + ffmpeg \ + tini + +WORKDIR /app + +# Copy compiled frontend and server from build stages +COPY --from=build-client /client/dist /app/client/dist +COPY --from=build-server /server /app EXPOSE 80 From 40e7e36ef6bd87d51293fffe0513ea5e3dc4a3c9 Mon Sep 17 00:00:00 2001 From: advplyr Date: Mon, 12 May 2025 15:15:18 -0500 Subject: [PATCH 2/2] Dockerfile unnecessary stage 1 apks --- Dockerfile | 8 ++------ tailwind.config.js | 0 2 files changed, 2 insertions(+), 6 deletions(-) create mode 100644 tailwind.config.js diff --git a/Dockerfile b/Dockerfile index 3eea9cd5..1ba107fd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,15 +10,11 @@ FROM node:20-alpine AS build-server ENV NODE_ENV=production -RUN apk update && \ - apk add --no-cache --update \ +RUN apk add --no-cache --update \ curl \ - tzdata \ - ffmpeg \ make \ python3 \ g++ \ - tini \ unzip WORKDIR /server @@ -46,7 +42,7 @@ RUN npm ci --only=production FROM node:20-alpine # Install only runtime dependencies -RUN apk add --no-cache \ +RUN apk add --no-cache --update \ tzdata \ ffmpeg \ tini diff --git a/tailwind.config.js b/tailwind.config.js new file mode 100644 index 00000000..e69de29b