From e045cb5a453522273f87fafbde62450ff31c623a Mon Sep 17 00:00:00 2001 From: Jason Woltje Date: Sun, 1 Feb 2026 01:22:51 -0600 Subject: [PATCH] perf(docker): Add BuildKit cache mounts for faster builds Added cache mounts for: - pnpm store: Caches downloaded packages between builds - TurboRepo: Caches build outputs between builds This significantly speeds up subsequent builds: - First build: Full download and compile - Subsequent builds: Only changed packages are re-downloaded/rebuilt Requires Docker BuildKit (default in Docker 23+). Co-Authored-By: Claude Opus 4.5 --- apps/api/Dockerfile | 12 +++++++++--- apps/web/Dockerfile | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/apps/api/Dockerfile b/apps/api/Dockerfile index 00c84ce..43535d2 100644 --- a/apps/api/Dockerfile +++ b/apps/api/Dockerfile @@ -1,3 +1,6 @@ +# syntax=docker/dockerfile:1 +# Enable BuildKit features for cache mounts + # Base image for all stages FROM node:20-alpine AS base @@ -22,8 +25,9 @@ COPY packages/ui/package.json ./packages/ui/ COPY packages/config/package.json ./packages/config/ COPY apps/api/package.json ./apps/api/ -# Install dependencies -RUN pnpm install --frozen-lockfile +# Install dependencies with pnpm store cache +RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \ + pnpm install --frozen-lockfile # ====================== # Builder stage @@ -41,7 +45,9 @@ COPY apps/api ./apps/api # Build the API app and its dependencies using TurboRepo # This ensures @mosaic/shared is built first, then prisma:generate, then the API -RUN pnpm turbo build --filter=@mosaic/api +# Cache TurboRepo build outputs for faster subsequent builds +RUN --mount=type=cache,id=turbo-cache,target=/app/.turbo \ + pnpm turbo build --filter=@mosaic/api # ====================== # Production stage diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile index 8134b73..8da6c1f 100644 --- a/apps/web/Dockerfile +++ b/apps/web/Dockerfile @@ -1,3 +1,6 @@ +# syntax=docker/dockerfile:1 +# Enable BuildKit features for cache mounts + # Base image for all stages FROM node:20-alpine AS base @@ -22,8 +25,9 @@ COPY packages/ui/package.json ./packages/ui/ COPY packages/config/package.json ./packages/config/ COPY apps/web/package.json ./apps/web/ -# Install dependencies -RUN pnpm install --frozen-lockfile +# Install dependencies with pnpm store cache +RUN --mount=type=cache,id=pnpm-store,target=/root/.local/share/pnpm/store \ + pnpm install --frozen-lockfile # ====================== # Builder stage @@ -45,7 +49,9 @@ ENV NEXT_PUBLIC_API_URL=${NEXT_PUBLIC_API_URL} # Build the web app and its dependencies using TurboRepo # This ensures @mosaic/shared and @mosaic/ui are built first -RUN pnpm turbo build --filter=@mosaic/web +# Cache TurboRepo build outputs for faster subsequent builds +RUN --mount=type=cache,id=turbo-cache,target=/app/.turbo \ + pnpm turbo build --filter=@mosaic/web # Ensure public directory exists (may be empty) RUN mkdir -p ./apps/web/public