Dockerfile47 lines · 1557 chars # Builder stage: install dependencies, build the monorepo, and prepare runtime artifacts
FROM node:20-bullseye AS builder
ENV DEBIAN_FRONTEND=noninteractive
WORKDIR /app
# Install system dependencies required for native modules and building
RUN apt-get update \
&& apt-get install -y --no-install-recommends git ca-certificates build-essential python3 \
&& rm -rf /var/lib/apt/lists/*
# Ensure pnpm is available (preinstall enforces pnpm)
RUN corepack enable \
&& corepack prepare pnpm@9.2.0 --activate
# Copy project files and install dependencies (workspace-aware)
COPY . .
# Install dependencies with frozen lockfile for reproducible builds
RUN pnpm install --frozen-lockfile
# Build the monorepo (turbo-based build across packages)
RUN pnpm -w run build
# Collect built artifacts for the runtime image
RUN mkdir -p /app/dist/react /app/dist/svelte
RUN sh -lc 'if [ -d packages/react/dist ]; then cp -r packages/react/dist/. /app/dist/react/; fi' \
&& sh -lc 'if [ -d packages/svelte/dist ]; then cp -r packages/svelte/dist/. /app/dist/svelte/; fi'
# Runtime stage: keep the image small by only shipping runtime artifacts
FROM node:20-bullseye AS runtime
WORKDIR /app
# Install minimal runtime dependencies
RUN apt-get update \
&& apt-get install -y --no-install-recommends python3 \
&& rm -rf /var/lib/apt/lists/*
# Copy built artifacts from builder
COPY --from=builder /app/dist /app/dist
COPY server.js /app/server.js
EXPOSE 8080
# Serve the static files using a simple Node one-line server file
CMD ["node", "/app/server.js"]