Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 20 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,43 +1,38 @@
FROM us-docker.pkg.dev/sentryio/dhi/node:24-debian13-dev AS builder
FROM node:24.14.0 AS builder

WORKDIR /build

COPY package.json yarn.lock ./
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing WORKDIR causes massive image bloat via symlink

Medium Severity

The builder stage has no WORKDIR, so the default / is used. The tsc build outputs to ./lib, which resolves to /lib — a symlink to /usr/lib on Debian bookworm (usrmerge). Docker's COPY --from=builder lib lib follows symlinks, so it copies the entire /usr/lib directory (system libraries + build output) into the runtime image. The removed DHI version had WORKDIR /build to avoid this. Adding a WORKDIR to the builder stage would prevent copying hundreds of megabytes of unnecessary system libraries.

Additional Locations (1)

Fix in Cursor Fix in Web

COPY package.json yarn.lock .
RUN yarn install --frozen-lockfile

COPY tsconfig.json .
COPY src src
RUN yarn build

# Drop devDependencies from node_modules for the runtime image
RUN yarn install --frozen-lockfile --production
FROM node:24.14.0-slim

# canvas 3.x bundles its graphics libs (libcairo, libpango, etc.) but its
# bundled librsvg/glib still need a few basic system libs absent from the
# minimal runtime image. Collect them here to copy in without pulling the
# entire -dev system into the runtime.
RUN mkdir -p /canvas-sys-libs && \
find /lib /usr/lib -maxdepth 3 \( \
-name "libz.so.1*" -o \
-name "libexpat.so.1*" -o \
-name "libuuid.so.1*" -o \
-name "liblzma.so.5*" \
\) -exec cp -P --parents {} /canvas-sys-libs/ \;
ENV NODE_ENV=production

RUN npm install -g npm@latest \
&& npm cache clean --force

FROM us-docker.pkg.dev/sentryio/dhi/node:24-debian13

ENV NODE_ENV=production
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
libcairo2-dev \
libpango1.0-dev \
libjpeg-dev \
libgif-dev \
librsvg2-dev \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /usr/src/app

COPY package.json ./
COPY package.json yarn.lock ./
RUN yarn install --frozen-lockfile \
&& yarn cache clean

COPY fonts fonts
COPY --from=builder /build/node_modules node_modules
COPY --from=builder /build/lib lib
COPY --from=builder /canvas-sys-libs/ /
COPY --from=builder lib lib

RUN ["node", "lib/index.js", "--help"]
RUN node lib/index.js --help

EXPOSE 9090/tcp
CMD ["node", "./lib/index.js", "server", "9090"]