FROM node:22.12.0-bullseye-slim
# Install essential build tools and dependencies for Node native modules and fonts
RUN apt-get update \
&& apt-get install -y --no-install-recommends \
git \
python3 \
build-essential \
ca-certificates \
libcairo2-dev \
libpango1.0-dev \
libjpeg-dev \
libgif-dev \
librsvg2-dev \
&& rm -rf /var/lib/apt/lists/*
# Install a compatible version of pnpm via npm to manage monorepo dependencies
RUN npm i -g pnpm@10.30.3
WORKDIR /mermaid
# Copy manifest and lockfile first to leverage layer caching
COPY package.json pnpm-lock.yaml* ./
# Remove patchedDependencies configuration from root package.json to avoid missing patch files during install
COPY scripts/fix-pnpm-patches.mjs ./scripts/fix-pnpm-patches.mjs
RUN node --version \
&& node ./scripts/fix-pnpm-patches.mjs
# Install dependencies
RUN pnpm install --frozen-lockfile
# Copy the rest of the source code
COPY . .
# Build project from source
RUN pnpm build
# Expose ports used by Mermaid server
EXPOSE 9000 3333
# Run the development server by default (suitable for container usage in this setup)
CMD ["pnpm", "dev"]