mirror of
https://github.com/CopilotKit/CopilotKit.git
synced 2026-09-14 16:26:20 +08:00
28f33ecc8a
Six fixes addressing CR findings on the Option-B runtime URL-injection migration:
1. SSR_PLACEHOLDER must be parseable URL sentinels — `new URL("")` throws on
SSR causing 500s for any consumer that constructs URLs from runtime-config
fields. Use `.invalid`-TLD sentinels (RFC 2606) for URL fields; analytics
keys stay empty string. Add `suppressHydrationWarning` on consumers that
render the placeholder server-side and the real value post-hydration
(integration-grid, page-actions popover).
2. Hook-order: move `usePathname()`/`useEffect` ABOVE the early-return in
use-google-analytics. Gate the effect bodies on `GA_ID` instead so React
sees a stable hook order across renders.
3. `readUrl`/`readKey` accept either bare or `NEXT_PUBLIC_*`-prefixed env
names via a fallback chain — covers both server-only and inlined-public
variable conventions without forcing a rename across deploy targets.
4. Extract `serializeRuntimeConfig` to `lib/runtime-config-serialize.ts` so
the OWASP-escape behavior (XSS via </script>, U+2028/U+2029 line-terminator
injection) can be unit-tested without importing the layout into vitest.
5. Reclassify `intelligenceSignupUrl`/`posthogHost` from FATAL-CONFIG to
info-level in shell-docs — these are optional integrations, not hard
wiring failures, so absence should not poison the error stream.
6. Comment-rot cleanup: drop "Option B", B12, "the bug we are fixing", fix
"four substrings"→"three substrings" miscounts, and refresh shell-docs
.env.example to describe the runtime-injection contract instead of a
stale next.config throw claim.
V1: shell + shell-docs `next build` succeeds (no Edge-runtime crash on
`unstable_noStore`).
V2: `OPS_BASE_URL=` shell-dashboard `next build` no longer throws —
`next.config.ts` is now a phase-aware function that emits a sentinel
destination at build time and throws only at start (PHASE_PRODUCTION_BUILD
from next/constants).
Tests: shell-docs 72/72, shell 12/12, shell-dashboard runtime-config 16/16
(pre-existing baseline-partner-count failure unchanged).
76 lines
3.5 KiB
Docker
76 lines
3.5 KiB
Docker
FROM node:20-slim AS builder
|
|
ARG COMMIT_SHA=unknown
|
|
ARG BRANCH=unknown
|
|
WORKDIR /app
|
|
|
|
# Copy manifests + lockfiles for deterministic installs.
|
|
# Both packages ship their own package-lock.json; `npm ci` enforces the
|
|
# lock and never mutates it (in contrast to `npm install` which could
|
|
# silently bump transitive deps). shell-dashboard is deliberately NOT
|
|
# part of the root pnpm workspace (flat, standalone Next.js app), so
|
|
# using npm here is the correct tool — not a workaround.
|
|
COPY showcase/scripts/package.json showcase/scripts/package-lock.json ./scripts/
|
|
COPY showcase/shell-dashboard/package.json showcase/shell-dashboard/package-lock.json ./shell-dashboard/
|
|
|
|
RUN cd scripts && npm ci \
|
|
&& cd ../shell-dashboard && npm ci
|
|
|
|
# Copy source
|
|
COPY showcase/shared/ ./shared/
|
|
COPY showcase/integrations/ ./integrations/
|
|
COPY showcase/scripts/ ./scripts/
|
|
# probe-docs.ts checks for MDX files in shell-docs/src/content/docs/ to
|
|
# determine docs reachability status. Only the content directory is needed.
|
|
COPY showcase/shell-docs/src/content/ ./shell-docs/src/content/
|
|
COPY showcase/shell-dashboard/ ./shell-dashboard/
|
|
|
|
# Bake commit info into Next.js build (NEXT_PUBLIC_* are compiled in).
|
|
ENV NEXT_PUBLIC_COMMIT_SHA=${COMMIT_SHA}
|
|
ENV NEXT_PUBLIC_BRANCH=${BRANCH}
|
|
|
|
# Generate registry + docs status, then build Next.js
|
|
RUN cd scripts && node node_modules/tsx/dist/cli.mjs generate-registry.ts \
|
|
&& node node_modules/tsx/dist/cli.mjs probe-docs.ts \
|
|
&& cd ../shell-dashboard && npx next build
|
|
|
|
# Prod-deps-only stage: re-install shell-dashboard deps with --omit=dev so
|
|
# the runtime image doesn't ship vitest/playwright/tailwind-postcss/etc.
|
|
# The builder stage's node_modules includes the full dev tree because
|
|
# `next build` needs types + tailwind + postcss at compile time; copying
|
|
# that tree straight into runtime roughly doubles the image size and ships
|
|
# test tooling to prod. Using `npm ci --omit=dev` off the same lockfile
|
|
# gives us a deterministic, prod-only tree without needing Next's
|
|
# `output: 'standalone'` mode (which requires a next.config.ts change in a
|
|
# package owned by another workstream).
|
|
FROM node:20-slim AS prod-deps
|
|
WORKDIR /app/shell-dashboard
|
|
COPY showcase/shell-dashboard/package.json showcase/shell-dashboard/package-lock.json ./
|
|
# `--ignore-scripts` skips the package.json `postinstall` hook, which
|
|
# runs `cd ../scripts && npm install` — only needed at build time for
|
|
# the generator scripts. Runtime has no need for sibling packages.
|
|
RUN npm ci --omit=dev --ignore-scripts --silent
|
|
|
|
FROM node:20-slim AS runner
|
|
WORKDIR /app
|
|
ENV NODE_ENV=production
|
|
ENV PORT=10000
|
|
# URL env vars (POCKETBASE_URL / SHELL_URL / OPS_BASE_URL) are read at
|
|
# runtime by `src/lib/runtime-config.ts` from the Railway service env —
|
|
# no Dockerfile ARG/ENV plumbing required for them.
|
|
# COMMIT_SHA / BRANCH stay build-baked because they identify the artifact,
|
|
# not the deploy. See showcase/RAILWAY.md and runtime-config.ts.
|
|
|
|
# Copy build artifacts with `node:node` ownership so the runtime process
|
|
# (dropped to USER node below) can read them. The `node` user/group ships
|
|
# in the node:20-slim base image at uid/gid 1000 — no useradd needed.
|
|
COPY --chown=node:node --from=builder /app/shell-dashboard/.next ./.next
|
|
COPY --chown=node:node --from=prod-deps /app/shell-dashboard/node_modules ./node_modules
|
|
COPY --chown=node:node --from=builder /app/shell-dashboard/package.json ./
|
|
|
|
# Drop root privileges — parity with showcase/harness/Dockerfile. Reduces
|
|
# blast radius of any RCE in Next.js or a transitive dep.
|
|
USER node
|
|
|
|
EXPOSE 10000
|
|
CMD ["npx", "next", "start", "-p", "10000"]
|