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

Fix OOM build (exit 137) by disabling sourcemap generation

Browse files

Postiz upstream enables both Next.js productionBrowserSourceMaps and
Sentry's webpack sourcemap plugin. Together they push peak build memory
past HF Space builder limits (16 GB cap), causing OOMKilled at exit 137.

Patch apps/frontend/next.config.js during build:
- productionBrowserSourceMaps: true β†’ false
- Sentry sourcemaps.disable: false β†’ true

Also lower per-app heap from 4 GB to 3 GB and build the four Postiz apps
sequentially (backend β†’ workers β†’ cron β†’ frontend) instead of in parallel
β€” concurrent Next.js + Nest builds each spawn worker pools and stack peak
RSS.

README updated for /app routing (Postiz UI mounted at /app/*, dashboard
owns /, OAuth callback URLs need the /app prefix).

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

Files changed (2) hide show
  1. Dockerfile +31 -9
  2. README.md +17 -14
Dockerfile CHANGED
@@ -37,18 +37,40 @@ 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 mount the frontend at /app.
41
- # We inject basePath + assetPrefix immediately after `const nextConfig = {`.
42
- # This makes Next.js generate links/asset URLs prefixed with /app, so the
43
- # browser will hit /app/_next/* etc., which our health-server then strips
44
- # back to /_next/* before passing to nginx.
 
 
 
 
45
  RUN sed -i "s|const nextConfig = {|const nextConfig = {\n basePath: '/app',\n assetPrefix: '/app',|" apps/frontend/next.config.js \
 
 
46
  && grep -q "basePath: '/app'" apps/frontend/next.config.js \
47
- || (echo "BASEPATH PATCH FAILED β€” next.config.js shape changed upstream"; exit 1)
48
-
49
- # Install + build. 4 GB heap for the Next.js compile.
 
 
 
 
 
 
 
 
 
 
50
  RUN pnpm install --frozen-lockfile=false
51
- RUN NODE_OPTIONS="--max-old-space-size=4096" pnpm run build
 
 
 
 
 
 
52
 
53
  # Drop dev junk to shrink the runtime image.
54
  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 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
57
+ # probe these. Empty values keep them from doing network calls.
58
+ ENV SENTRY_DSN="" \
59
+ SENTRY_AUTH_TOKEN="" \
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
67
+
68
+ # Build apps one at a time with a 3 GB heap. Sequential matters: parallel
69
+ # Next.js + Nest builds each spawn workers and stack peak RSS.
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 \
README.md CHANGED
@@ -172,9 +172,11 @@ HuggingPost will create or update a Worker named `<your-space-host>-proxy` and r
172
  Each social platform requires you to register your Postiz instance as an OAuth app. The callback URL pattern is:
173
 
174
  ```
175
- https://<your-space-host>/api/integrations/social/<platform>/callback
176
  ```
177
 
 
 
178
  For each platform you want (X, LinkedIn, Facebook, etc.), follow the [Postiz provider docs](https://docs.postiz.com/providers) to obtain client ID + secret, then enter them inside Postiz **Settings β†’ Channels** (NOT as Space secrets β€” Postiz stores them encrypted in its DB).
179
 
180
  > [!TIP]
@@ -201,21 +203,22 @@ HuggingPost/
201
 
202
  | Path | Target | Notes |
203
  | :--- | :--- | :--- |
204
- | `/` | dashboard (local) | HTML status page |
205
- | `/health`, `/status`, `/uptimerobot/setup` | local | JSON / handlers |
206
- | `/api/*` | backend `:3000` | `/api` prefix stripped |
207
- | `/uploads/*` | backend `:3000` | media files |
208
- | `/*` | frontend `:4200` | Next.js pages, `/_next/*`, etc. |
209
 
210
  **Internal processes:**
211
 
212
- | Process | Port | Memory cap |
213
  | :--- | :--- | :--- |
214
- | `health-server.js` | 7860 (public) | β€” |
215
- | Postiz frontend (Next.js) | 4200 | 2 GB |
216
- | Postiz backend (NestJS) | 3000 | 2 GB |
217
- | Postiz workers | β€” | 1 GB |
218
- | Postiz cron | β€” | 512 MB |
 
219
  | `postgres` | 5432 | β€” |
220
  | `redis-server` | 6379 | β€” |
221
  | `postiz-sync.py` (loop) | β€” | β€” |
@@ -239,8 +242,8 @@ The Space slept. Set up UptimeRobot from the dashboard.
239
  **OAuth callback fails for X/Facebook/LinkedIn**
240
  Some platforms reject `*.hf.space` subdomains as redirect URIs. You may need to put a custom domain in front (Cloudflare β†’ HF Space CNAME).
241
 
242
- **Out of memory during build**
243
- The Next.js build needs `--max-old-space-size=4096`. If you forked and changed the Dockerfile, make sure the `NODE_OPTIONS` flag is still on the `pnpm run build` line.
244
 
245
  **`prisma-db-push` fails on first boot**
246
  Usually means Postgres didn't finish starting. Container will exit and HF will auto-restart β€” second boot usually succeeds. If it persists, check Logs for the actual Prisma error.
 
172
  Each social platform requires you to register your Postiz instance as an OAuth app. The callback URL pattern is:
173
 
174
  ```
175
+ https://<your-space-host>/app/api/integrations/social/<platform>/callback
176
  ```
177
 
178
+ (Note the `/app` prefix β€” Postiz UI is mounted there so its API is too.)
179
+
180
  For each platform you want (X, LinkedIn, Facebook, etc.), follow the [Postiz provider docs](https://docs.postiz.com/providers) to obtain client ID + secret, then enter them inside Postiz **Settings β†’ Channels** (NOT as Space secrets β€” Postiz stores them encrypted in its DB).
181
 
182
  > [!TIP]
 
203
 
204
  | Path | Target | Notes |
205
  | :--- | :--- | :--- |
206
+ | `/` | HuggingPost dashboard (local) | Status + UptimeRobot setup |
207
+ | `/health`, `/status`, `/uptimerobot/setup` | local | JSON handlers |
208
+ | `/app` or `/app/*` | Postiz nginx `:5000` | `/app` stripped β€” Next.js built with `basePath="/app"` |
209
+ | `/_next/*`, `/static/*` | 301 β†’ `/app/<path>` | Catches absolute-URL leaks |
210
+ | anything else | 404 | β€” |
211
 
212
  **Internal processes:**
213
 
214
+ | Process | Port | Notes |
215
  | :--- | :--- | :--- |
216
+ | `health-server.js` | 7860 (public) | Dashboard + reverse proxy |
217
+ | nginx | 5000 (internal) | Routes `/api`β†’3000, `/uploads`β†’fs, `/`β†’4200 |
218
+ | Postiz backend (NestJS) | 3000 | Started by PM2 |
219
+ | Postiz frontend (Next.js) | 4200 | Started by PM2, `basePath=/app` baked at build |
220
+ | Postiz workers | β€” | BullMQ consumer |
221
+ | Postiz cron | β€” | Schedule tick |
222
  | `postgres` | 5432 | β€” |
223
  | `redis-server` | 6379 | β€” |
224
  | `postiz-sync.py` (loop) | β€” | β€” |
 
242
  **OAuth callback fails for X/Facebook/LinkedIn**
243
  Some platforms reject `*.hf.space` subdomains as redirect URIs. You may need to put a custom domain in front (Cloudflare β†’ HF Space CNAME).
244
 
245
+ **Out of memory during build (exit 137 / OOMKilled)**
246
+ The Dockerfile patches `apps/frontend/next.config.js` to disable sourcemap generation (`productionBrowserSourceMaps: false` + Sentry `sourcemaps.disable: true`). Without these, peak build memory exceeds HF Space builder limits. If you forked and removed those sed patches, OOM returns. Builds also run apps sequentially (backend β†’ workers β†’ cron β†’ frontend) at 3 GB heap each β€” parallel builds OOM.
247
 
248
  **`prisma-db-push` fails on first boot**
249
  Usually means Postgres didn't finish starting. Container will exit and HF will auto-restart β€” second boot usually succeeds. If it persists, check Logs for the actual Prisma error.