build(docker): slim down the runtime image

- install production dependencies and chromium in a separate stage
- drop source maps, typescript sources and declarations, docs,
  typeorm's browser build, better-sqlite3's c sources and ffmpeg
- base the runtime on debian:bookworm-slim with only the node binary
- document the image layout
- bump version to 1.22.1
This commit is contained in:
ars9 committed 2026-10-01 10:52:47 +03:00
1 parent 23fa302b25
commit 69efc73cf1
5 files changed
+48 -10

No files matched your search

+8
View File
@@ -2,6 +2,14 @@
All notable changes to this project will be documented in this file.
## 1.22.1 - 2026-10-01
Changes since 1.22.0:
### Changed
- The Docker image is about 20% smaller (1.09 GB → 876 MB on disk, 251 MB → 220 MB compressed). Production dependencies and Chromium are installed in a separate stage that drops files nothing loads at runtime (source maps, TypeScript sources and declarations, docs, TypeORM's browser build, better-sqlite3's C sources, Playwright's ffmpeg). The runtime image is `debian:bookworm-slim` with only the `node` binary, so it no longer contains `npm`, `npx`, `yarn` or `corepack`.
## 1.22.0 - 2026-10-01
Changes since 1.21.1:
+35 -7
View File
@@ -28,8 +28,38 @@ COPY server/tsconfig*.json ./server/
COPY server/src ./server/src
RUN npm run -w server build
# ── Runtime dependencies ──────────────────────────────────────────────────────
FROM node:24-slim AS runtime-deps
WORKDIR /app
COPY package*.json ./
COPY server/package.json ./server/
# Production dependencies and Playwright's headless-only Chromium build,
# matching the installed Playwright version. All browser launches are
# headless, so the full desktop Chromium (GTK, Mesa/LLVM, icon themes) isn't
# needed, and neither is ffmpeg (only used for video recording).
#
# Then drop what nothing loads at runtime: source maps, TypeScript sources and
# declarations, docs, TypeORM's browser build and better-sqlite3's C sources
# (the addon is already compiled).
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
RUN npm ci --omit=dev -w server \
&& npx playwright install --only-shell chromium \
&& rm -rf /ms-playwright/ffmpeg-* \
&& find node_modules -type f \( \
-name '*.map' -o -name '*.ts' -o -name '*.mts' -o -name '*.cts' \
-o -iname '*.md' -o -iname '*.markdown' \
\) -delete \
&& rm -rf node_modules/typeorm/browser \
node_modules/better-sqlite3/deps \
node_modules/better-sqlite3/src
# ── Runtime ───────────────────────────────────────────────────────────────────
FROM node:24-slim AS runtime
# Plain Debian with just the node binary: npm, yarn, corepack and the C
# headers that come with the node image aren't needed to run the app.
FROM debian:bookworm-slim AS runtime
# Runtime only: in the build stages it would make npm ci skip devDependencies
ENV NODE_ENV=production
@@ -63,18 +93,16 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
libxrandr2 \
&& rm -rf /var/lib/apt/lists/*
COPY --from=runtime-deps /usr/local/bin/node /usr/local/bin/node
WORKDIR /app
COPY package*.json ./
COPY server/package.json ./server/
# Playwright's headless-only Chromium build, matching the installed Playwright
# version. All browser launches are headless, so the full desktop Chromium
# (GTK, Mesa/LLVM, icon themes) isn't needed.
ENV PLAYWRIGHT_BROWSERS_PATH=/ms-playwright
RUN npm ci --omit=dev -w server \
&& npx playwright install --only-shell chromium \
&& npm cache clean --force
COPY --from=runtime-deps /ms-playwright /ms-playwright
COPY --from=runtime-deps /app/node_modules ./node_modules
COPY --from=server-build /app/server/dist ./dist
COPY --from=client-build /app/client/dist ./client
+2
View File
@@ -204,6 +204,8 @@ The root `Dockerfile` builds a single image with the whole application: it build
The runtime image uses Playwright's headless-only Chromium build (`chromium-headless-shell`) with just the shared libraries it links against, plus DejaVu and Liberation fonts (Liberation is metric-compatible with Arial/Times, so pages lay out as they would with those fonts). All browser launches are headless, so the full desktop Chromium isn't installed. If a new Playwright version needs another library, `ldd` on the `chrome-headless-shell` binary in the image lists what's missing.
To keep the image small, production dependencies and the browser are installed in a separate `runtime-deps` stage, which drops what nothing loads at runtime (source maps, TypeScript sources and declarations, docs, TypeORM's browser build, better-sqlite3's C sources, and Playwright's ffmpeg, which is only used for video recording). The runtime stage is plain `debian:bookworm-slim` with only the `node` binary copied in, so the image has no `npm`, `npx`, `yarn` or `corepack`. If a package starts failing in the image only, check whether it reads one of the deleted file types at runtime.
```bash
docker compose build
```
+2 -2
View File
@@ -1,12 +1,12 @@
{
"name": "liqa",
"version": "1.22.0",
"version": "1.22.1",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "liqa",
"version": "1.22.0",
"version": "1.22.1",
"workspaces": [
"server",
"client"
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "liqa",
"version": "1.22.0",
"version": "1.22.1",
"private": true,
"engines": {
"node": ">=24"