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/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( 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 ( - +
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',