Skip to content

Commit 74946fb

Browse files
authored
improvement(docker): speed up app image build with cache mounts and parallel node-gyp (#4310)
1 parent f62d274 commit 74946fb

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

docker/app.Dockerfile

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,17 @@ COPY packages/workflow-types/package.json ./packages/workflow-types/package.json
4545

4646
# Install dependencies, then rebuild isolated-vm for Node.js
4747
# Use --linker=hoisted for flat node_modules layout (required for Docker multi-stage builds)
48+
# JOBS=4 caps node-gyp parallelism — higher values OOM isolated-vm (laverdet/isolated-vm#428)
4849
RUN --mount=type=cache,id=bun-cache,target=/root/.bun/install/cache \
4950
--mount=type=cache,id=npm-cache,target=/root/.npm \
5051
HUSKY=0 bun install --omit=dev --ignore-scripts --linker=hoisted && \
51-
cd node_modules/isolated-vm && npx node-gyp rebuild --release
52+
cd node_modules/isolated-vm && JOBS=4 npx node-gyp rebuild --release
5253

5354
# ========================================
5455
# Builder Stage: Build the Application
5556
# ========================================
5657
FROM base AS builder
58+
ARG TARGETPLATFORM
5759
WORKDIR /app
5860

5961
# Install turbo globally (cached for fast reinstall)
@@ -88,17 +90,10 @@ COPY apps/sim/postcss.config.mjs ./apps/sim/postcss.config.mjs
8890
COPY apps/sim ./apps/sim
8991
COPY packages ./packages
9092

91-
# Required for standalone nextjs build
92-
WORKDIR /app/apps/sim
93-
RUN --mount=type=cache,id=bun-cache,target=/root/.bun/install/cache \
94-
HUSKY=0 bun install sharp --linker=hoisted
95-
9693
ENV NEXT_TELEMETRY_DISABLED=1 \
9794
VERCEL_TELEMETRY_DISABLED=1 \
9895
DOCKER_BUILD=1
9996

100-
WORKDIR /app
101-
10297
# Provide dummy database URLs during image build so server code that imports @sim/db
10398
# can be evaluated without crashing. Runtime environments should override these.
10499
ARG DATABASE_URL="postgresql://user:pass@localhost:5432/dummy"
@@ -109,7 +104,10 @@ ENV DATABASE_URL=${DATABASE_URL}
109104
ARG NEXT_PUBLIC_APP_URL="http://localhost:3000"
110105
ENV NEXT_PUBLIC_APP_URL=${NEXT_PUBLIC_APP_URL}
111106

112-
RUN bun run build
107+
# Per-platform cache id keeps arm64/amd64 SWC artifacts isolated.
108+
RUN --mount=type=cache,id=next-cache-${TARGETPLATFORM},target=/app/apps/sim/.next/cache \
109+
--mount=type=cache,id=turbo-cache-${TARGETPLATFORM},target=/app/.turbo \
110+
bun run build
113111

114112
# ========================================
115113
# Runner Stage: Run the actual app

0 commit comments

Comments
 (0)