From fdf1f2c50573836fb20984221830f62b7a35e414 Mon Sep 17 00:00:00 2001 From: Jack Herrington Date: Tue, 10 Nov 2026 12:25:08 -0800 Subject: [PATCH 1/3] prm: production Dockerfile; trace PGlite assets into .output Adds app/prm/Dockerfile (build from repo root, filtered pnpm install of the PRM's workspace closure, runtime = .output only, non-root, /data volume, HEALTHCHECK on /api/cms/v1/health). No secrets at build time. Nitro was bundling @electric-sql/pglite, dropping pglite.data and the pg_trgm extension bundle, so the default embedded store never opened in a production build (health 503: connection acquisition timed out). Trace it as a dependency instead, same pattern as app/base does for QuickJS. Co-Authored-By: Claude Opus 5.5 --- app/prm/Dockerfile | 31 +++++++++++++++++++++++++++++++ app/prm/vite.config.ts | 7 +++++-- 2 files changed, 36 insertions(+), 2 deletions(-) create mode 100644 app/prm/Dockerfile diff --git a/app/prm/Dockerfile b/app/prm/Dockerfile new file mode 100644 index 00000000..166f956f --- /dev/null +++ b/app/prm/Dockerfile @@ -0,0 +1,31 @@ +# PRM production image. Build from the REPO ROOT (workspace deps live there): +# docker build -f app/prm/Dockerfile -t prm . +# No secrets at build time: all keys (PRM_AUTH_SECRET, PRM_MCP_KEY, ...) are +# injected as runtime env by the deploy layer and never baked into a layer. + +FROM node:24-bookworm-slim AS build +ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0 +WORKDIR /workspace +# corepack reads the pinned pnpm version from the root package.json. +COPY package.json ./ +RUN corepack enable && corepack install +COPY . . +# Install and build only the PRM and its workspace dependency closure. +RUN pnpm install --frozen-lockfile --filter 'prm...' \ + && pnpm --filter prm build + +FROM node:24-bookworm-slim AS runtime +ARG PRM_BUILD_SHA=unknown +ENV NODE_ENV=production \ + PRM_DATA_DIR=/data \ + PRM_BUILD_SHA=$PRM_BUILD_SHA \ + PORT=3000 HOST=0.0.0.0 NITRO_HOST=0.0.0.0 +WORKDIR /app +RUN mkdir /data && chown node:node /data +COPY --from=build --chown=node:node /workspace/app/prm/.output ./.output +USER node +# cms.db, uploads/, backups/, prm.json and secrets.env all live here. +VOLUME /data +EXPOSE 3000 +HEALTHCHECK --interval=15s --timeout=5s --start-period=30s CMD node -e "fetch('http://127.0.0.1:3000/api/cms/v1/health').then(r=>{if(!r.ok)process.exit(1)}).catch(()=>process.exit(1))" +CMD ["node", ".output/server/index.mjs"] diff --git a/app/prm/vite.config.ts b/app/prm/vite.config.ts index ef271e54..d9e6d144 100644 --- a/app/prm/vite.config.ts +++ b/app/prm/vite.config.ts @@ -35,7 +35,10 @@ export default defineConfig({ }), }, }), - nitro(), + // Keep PGlite (the default embedded store) intact so Nitro traces its + // adjacent WASM / data / extension assets into .output. Bundling it + // drops pglite.data and pg_trgm.tar.gz and the store never opens. + nitro({ traceDeps: ['@electric-sql/pglite*'] }), viteReact(), ], // Externalize @tanstack/react-store so its CJS use-sync-external-store shim @@ -43,7 +46,7 @@ export default defineConfig({ // into the app chunk (which pulls in a second React and crashes production // SSR with "Invalid hook call"). Nitro's lib bundler shares the single // bundled React like every other dep. - ssr: { external: ['@tanstack/react-store'] }, + ssr: { external: ['@electric-sql/pglite', '@tanstack/react-store'] }, optimizeDeps: { include: [ 'react', From 86fea2265675f1d83467c3890f8d98d0b6ecadd9 Mon Sep 17 00:00:00 2001 From: Jack Herrington Date: Tue, 10 Nov 2026 14:44:53 -0800 Subject: [PATCH 2/3] prm: keep @tanstack/cms-core/server out of the client bundle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit events.ts is reachable from the client (router.tsx -> cms.config.ts) and statically imported systemContext from @tanstack/cms-core/server, which pulled the server runtime (new AsyncLocalStorage from node:async_hooks) into the browser chunk. In a production build hydration crashed with 'L.AsyncLocalStorage is not a constructor', leaving /setup stuck on 'Loading setup…'. Import it lazily inside the handlers, alongside the existing dynamic import of @tanstack/cms-api (same pattern as app/base). Co-Authored-By: Claude Opus 5.5 --- app/prm/src/events.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/prm/src/events.ts b/app/prm/src/events.ts index 703928ed..04d9ec54 100644 --- a/app/prm/src/events.ts +++ b/app/prm/src/events.ts @@ -10,7 +10,6 @@ * days ago. */ import { defineEventHandler } from '@tanstack/cms-core' -import { systemContext } from '@tanstack/cms-core/server' const HUMAN_ACTORS = new Set(['human', 'admin', 'editor', 'author']) @@ -46,7 +45,11 @@ export const personCreatedEnrichHandler = defineEventHandler({ : {} const name = String(payload.name ?? personId) const headline = String(payload.headline ?? '') + // Server-only modules are imported lazily: this file is reachable from the + // client bundle (router.tsx -> cms.config.ts), and a static import of + // @tanstack/cms-core/server pulls node:async_hooks into the browser. const { runAgent } = await import('@tanstack/cms-api') + const { systemContext } = await import('@tanstack/cms-core/server') await runAgent( 'enrich', [ @@ -75,7 +78,11 @@ export const monthlyStaleRefreshHandler = defineEventHandler({ }) if (stale.length === 0) return if (!process.env.ANTHROPIC_API_KEY && !process.env.CRM_AUTO_ENRICH) return + // Server-only modules are imported lazily: this file is reachable from the + // client bundle (router.tsx -> cms.config.ts), and a static import of + // @tanstack/cms-core/server pulls node:async_hooks into the browser. const { runAgent } = await import('@tanstack/cms-api') + const { systemContext } = await import('@tanstack/cms-core/server') for (const doc of stale.slice(0, 5)) { const id = String(doc.id ?? '') await runAgent( From 4cc1d8fe4acda976bf18eda0b90a83638ddba42a Mon Sep 17 00:00:00 2001 From: Jack Herrington Date: Wed, 11 Nov 2026 07:25:11 -0800 Subject: [PATCH 3/3] fix(prm): keep settings page header inside PageMain container The Settings route rendered PageHeader outside PageMain, so the header escaped the centred max-width column and sat flush against the viewport edge. Co-Authored-By: Claude Opus 5.5 --- app/prm/src/routes/prm-settings.tsx | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/prm/src/routes/prm-settings.tsx b/app/prm/src/routes/prm-settings.tsx index 49b844f7..e5f6a45d 100644 --- a/app/prm/src/routes/prm-settings.tsx +++ b/app/prm/src/routes/prm-settings.tsx @@ -129,12 +129,12 @@ function PrmSettingsPage() { return ( - +