somratpro Claude Opus 4.7 commited on
Commit
7fec572
·
1 Parent(s): 8de0b02

fix: limit Next.js webpack workers to prevent OOMKilled on HF builder

Browse files

Next.js 14 spawns N-1 webpack worker threads by default; each holds a full
module graph in memory. On the HF Space builder, parallel threads push RSS
past the builder limit (exit 137 OOMKilled) even with sourcemaps disabled.

Fix: patch experimental.cpus=1 + workerThreads=false into next.config.js so
webpack compiles single-threaded. Also add NEXT_PRIVATE_SKIP_SIZE_MINIMIZATION
env var and lower frontend heap from 3072→2048 MB (single-thread doesn't need
as much V8 heap headroom).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>

Files changed (1) hide show
  1. Dockerfile +14 -11
Dockerfile CHANGED
@@ -37,20 +37,22 @@ RUN npm install -g pnpm@10.6.1
37
  # Pinned to v2.11.3 — last release before Temporal became a hard requirement.
38
  RUN git clone --depth=1 --branch v2.11.3 https://github.com/gitroomhq/postiz-app.git .
39
 
40
- # Patch Next.js config to fix two things:
41
- # 1. basePath/assetPrefix=/app → mount Postiz UI at /app (HuggingPost
42
- # dashboard owns /).
43
- # 2. Disable sourcemap generation Postiz upstream sets both
44
- # `productionBrowserSourceMaps: true` AND Sentry's webpack plugin
45
- # `sourcemaps: { disable: false }`. Together they push peak build
46
- # memory past HF Space builder limits (exit 137 OOMKilled).
47
- # We flip both to false; visible cost is no client-side stack-trace
48
- # symbolization, which we don't need on a self-host.
49
  RUN sed -i "s|const nextConfig = {|const nextConfig = {\n basePath: '/app',\n assetPrefix: '/app',|" apps/frontend/next.config.js \
50
  && sed -i "s|productionBrowserSourceMaps: true|productionBrowserSourceMaps: false|" apps/frontend/next.config.js \
51
  && sed -i "s|disable: false,|disable: true,|" apps/frontend/next.config.js \
 
52
  && grep -q "basePath: '/app'" apps/frontend/next.config.js \
53
  && grep -q "productionBrowserSourceMaps: false" apps/frontend/next.config.js \
 
54
  || (echo "PATCH FAILED — next.config.js shape changed upstream"; exit 1)
55
 
56
  # Sentry env stubs — even with the wrapper bypassed, transitive imports may
@@ -60,7 +62,8 @@ ENV SENTRY_DSN="" \
60
  SENTRY_ORG="" \
61
  SENTRY_PROJECT="" \
62
  NEXT_PUBLIC_SENTRY_DSN="" \
63
- NEXT_TELEMETRY_DISABLED=1
 
64
 
65
  # Install all deps (sharp is optional but Next.js image optimization needs it).
66
  RUN pnpm install --frozen-lockfile=false
@@ -70,7 +73,7 @@ RUN pnpm install --frozen-lockfile=false
70
  RUN NODE_OPTIONS="--max-old-space-size=3072" pnpm run build:backend
71
  RUN NODE_OPTIONS="--max-old-space-size=3072" pnpm run build:workers
72
  RUN NODE_OPTIONS="--max-old-space-size=3072" pnpm run build:cron
73
- RUN NODE_OPTIONS="--max-old-space-size=3072" pnpm run build:frontend
74
 
75
  # Drop dev junk to shrink the runtime image.
76
  RUN find . -name ".git" -type d -prune -exec rm -rf {} + 2>/dev/null || true \
 
37
  # Pinned to v2.11.3 — last release before Temporal became a hard requirement.
38
  RUN git clone --depth=1 --branch v2.11.3 https://github.com/gitroomhq/postiz-app.git .
39
 
40
+ # Patch Next.js config for four memory/path fixes:
41
+ # 1. basePath/assetPrefix=/app → mount Postiz UI at /app.
42
+ # 2. Disable browser sourcemaps (productionBrowserSourceMaps: true upstream
43
+ # causes peak RSS spike during bundle emit).
44
+ # 3. Disable Sentry webpack sourcemap plugin (disable: false upstream).
45
+ # 4. experimental.cpus=1 + workerThreads=false — Next.js 14 spawns
46
+ # N-1 webpack worker threads by default; each holds a full module graph
47
+ # copy in memory. Single-thread compilation trades speed for RAM.
48
+ # This is the primary fix for exit 137 / OOMKilled on HF builder.
49
  RUN sed -i "s|const nextConfig = {|const nextConfig = {\n basePath: '/app',\n assetPrefix: '/app',|" apps/frontend/next.config.js \
50
  && sed -i "s|productionBrowserSourceMaps: true|productionBrowserSourceMaps: false|" apps/frontend/next.config.js \
51
  && sed -i "s|disable: false,|disable: true,|" apps/frontend/next.config.js \
52
+ && sed -i "s|experimental: {|experimental: {\n cpus: 1,\n workerThreads: false,|" apps/frontend/next.config.js \
53
  && grep -q "basePath: '/app'" apps/frontend/next.config.js \
54
  && grep -q "productionBrowserSourceMaps: false" apps/frontend/next.config.js \
55
+ && grep -q "cpus: 1" apps/frontend/next.config.js \
56
  || (echo "PATCH FAILED — next.config.js shape changed upstream"; exit 1)
57
 
58
  # Sentry env stubs — even with the wrapper bypassed, transitive imports may
 
62
  SENTRY_ORG="" \
63
  SENTRY_PROJECT="" \
64
  NEXT_PUBLIC_SENTRY_DSN="" \
65
+ NEXT_TELEMETRY_DISABLED=1 \
66
+ NEXT_PRIVATE_SKIP_SIZE_MINIMIZATION=true
67
 
68
  # Install all deps (sharp is optional but Next.js image optimization needs it).
69
  RUN pnpm install --frozen-lockfile=false
 
73
  RUN NODE_OPTIONS="--max-old-space-size=3072" pnpm run build:backend
74
  RUN NODE_OPTIONS="--max-old-space-size=3072" pnpm run build:workers
75
  RUN NODE_OPTIONS="--max-old-space-size=3072" pnpm run build:cron
76
+ RUN NODE_OPTIONS="--max-old-space-size=2048" pnpm run build:frontend
77
 
78
  # Drop dev junk to shrink the runtime image.
79
  RUN find . -name ".git" -type d -prune -exec rm -rf {} + 2>/dev/null || true \