Skip to content

feat(showcase): multi-stage Docker refactor across template, 17 starters, 17 packages - #4147

Merged
jpr5 merged 37 commits into
mainfrom
feat/showcase-multistage-docker
Apr 22, 2026
Merged

jpr5 merged 37 commits into
mainfrom
feat/showcase-multistage-docker

Conversation

@jpr5

@jpr5 jpr5 commented Apr 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Rewrite starter Dockerfile templates (typescript, python, java, dotnet) as true multi-stage: builder has dev tools, runner is minimal. No pip/npm/pnpm/tsx/*-cli dev in runtime stages.
  • Encode prod-mode behaviors for claude-sdk-typescript, mastra, langgraph-typescript directly in the TS template + generator conditionals (folds in the pattern from fix(showcase/langgraph-typescript): replace langgraph-cli dev with direct @langchain/langgraph-api server #4132 for langgraph-ts; adds parallel migration for claude-sdk-ts + mastra).
  • Regenerate all 17 starter Dockerfiles.
  • Rewrite all 17 package Dockerfiles to match the template shape (multi-stage, venv builder for Python, 3-stage Python runtime, USER app, etc.).
  • Cold-start instrumentation on claude-sdk-typescript package (absorbed from closed PR fix(showcase): prod-mode migration for mastra + claude-sdk-typescript starters #4133).
  • Pin platforms: linux/amd64 in the showcase deploy workflow (docker/build-push-action step) to match what Railway + GHCR require.
  • Template README.md documenting multi-stage conventions, size target, platform mandate, and the dockerfile_hygiene probe.
  • generate-starters.ts strips the langgraph-typescript starter's dead server.mjs + its start script (both reference deps only needed in the package's prod-mode path).

Why

Railway cold starts exceed the 180s watchdog grace when the runtime stage boots via langgraph-cli dev / npx mastra dev / npx tsx — the dev-mode work (TS compile, Rollup bundle, native libsql init) blocks the health probe. #4132 proved the fix is to move this to image build time for langgraph-ts. This PR generalizes that shape to all TS starters that need it and reshapes every Dockerfile in the tree so runners no longer carry dev toolchains.

Secondary outcomes:

  • Smaller runtime images (pip/npm toolchain moved to builder only).
  • Consistent --platform linux/amd64 pinning end-to-end.
  • No pnpm install --frozen-lockfile in the TS starter template (starters are no-lockfile by design).
  • validate-pins ratchet re-baselined to match the regenerated spec strings.

Test plan

  • docker build --platform linux/amd64 green for every starter (17) and package (17) locally
  • pnpm -C showcase/scripts vitest: 1085/1085 pass
  • tsc --noEmit -p showcase/scripts/tsconfig.json clean
  • oxfmt --check + oxlint clean on touched TS files
  • validate-pins: count 110, hash matches updated baseline
  • CI Showcase Validate green on PR HEAD
  • Post-merge: showcase deploy for mastra + claude-sdk-typescript goes green (currently flapping)

jpr5 added 30 commits April 21, 2026 17:20
…rod-mode tokens

Restructure the shared starter Dockerfile templates so the runtime stage
ships only a minimal base plus built artifacts — no dev toolchains (pip,
pnpm, tsx, *-cli dev) run in the runner stage.

Dockerfile.typescript:
- Add AGENT_BUILD_STEPS / AGENT_BUILD_COPY template tokens so per-slug
  prod-mode compiles (claude-sdk-typescript tsc, mastra `mastra build`)
  can be emitted by the generator. Mirrors PR #4132's langgraph-typescript
  fix for the rest of the TS starter slots — cold start becomes a straight
  `node` call instead of `npx tsx` / `npx mastra dev` on Railway.

Dockerfile.python:
- Split pip install into a dedicated agent-builder stage that carries
  full `python:3.12` (with compilers + dev headers needed for wheels
  that don't ship pre-built for -slim), and produces a self-contained
  /opt/venv. The runner then COPYs /opt/venv as a single opaque tree —
  no pip, no build tools in the final image.

Dockerfile.java and Dockerfile.dotnet already implement the true
multi-stage shape (temurin-21 JDK / dotnet-9 SDK builder + JRE / aspnet
runtime); no structural changes needed.

Regenerating the 17 starter Dockerfiles happens in the next commit
block — this commit is template-authoring only.
…ls per framework

Add per-slug Dockerfile emitters that pair with the new
AGENT_BUILD_STEPS / AGENT_BUILD_COPY tokens in Dockerfile.typescript:

- getAgentBuildSteps(fw): runs in the builder stage, after `npm run build`.
  Emits `npx tsc` for claude-sdk-typescript (compiles agent/index.ts →
  /app/dist/agent/index.js with flags that match the sibling package
  Dockerfile), and `npx mastra build --dir src/mastra` for mastra
  (bundles the server into .mastra/output/index.mjs). Returns "" for
  every other slug so their Dockerfile cache stays unchanged.

- getAgentBuildCopy(fw): runs in the runner stage, after the agent-code
  COPY. Moves /app/dist (claude-sdk-ts) or /app/.mastra (mastra) from
  the frontend stage into the runner.

- getEntrypointBlock() prod-mode updates: mastra now boots via
  `node /app/.mastra/output/index.mjs` (not `npx mastra dev`) and
  claude-sdk-typescript via `node /app/dist/agent/index.js` (not
  `npx tsx agent/index.ts`). Cold start is a straight `node`
  invocation on Railway — mirrors PR #4132's fix for langgraph-ts.

- Wire AGENT_BUILD_STEPS / AGENT_BUILD_COPY into the `vars` map in
  generateStarterImpl so the template substitution picks up the new
  tokens, and export the two helpers so the test suite can guard them.

Also refresh the generator header comment to describe the multi-stage
shape (builder toolchain vs. minimal runtime) and the prod-mode emitter
wiring.

Tests:
- Replace the legacy `mastra dev` / `npx tsx` entrypoint expectations
  with prod-mode assertions (`node /app/.mastra/output/index.mjs`,
  `node /app/dist/agent/index.js`), plus not-to-contain guards so a
  future refactor can't accidentally re-enable the tsx/dev path.
- Add a dedicated describe block for getAgentBuildSteps /
  getAgentBuildCopy covering the two opted-in slots, the ""
  fallthrough for langgraph-typescript (which has its own server.mjs
  migration path), and the "" fallthrough for every Python slug
  (Python prod-mode is shared-template, not per-slug).

Full `vitest run` in showcase/scripts is green (1085 tests).
Starter Dockerfile regeneration is deferred to a follow-up commit
block once Task 1's template wiring lands.
Split Python install into a dedicated agent-builder stage (python:3.12.13)
that produces /opt/venv, which the slim runner COPYs in. The runner no
longer runs pip install, so no compiler toolchain or build-essential bloats
the final image.

Preserves behavior: entrypoint.sh, port 10000, ENV NODE_ENV=production,
shared_python/ -> /app/shared/python/ + PYTHONPATH.
Split Python install into a dedicated agent-builder stage (python:3.12.13)
that produces /opt/venv, which the slim runner COPYs in. The runner no
longer runs pip install, so no compiler toolchain or build-essential bloats
the final image.

Preserves behavior: entrypoint.sh, port 10000, ENV NODE_ENV=production,
shared_python/ -> /app/shared/python/ + PYTHONPATH.
…venv builder

Split Python install into a dedicated agent-builder stage (python:3.12.13)
that produces /opt/venv, which the slim runner COPYs in. The runner no
longer runs pip install, so no compiler toolchain or build-essential bloats
the final image.

Preserves behavior: entrypoint.sh, port 10000, ENV NODE_ENV=production,
shared_python/ -> /app/shared/python/ + PYTHONPATH.
…builder

Split Python install into a dedicated agent-builder stage (python:3.12.13)
that produces /opt/venv, which the slim runner COPYs in. The runner no
longer runs pip install, so no compiler toolchain or build-essential bloats
the final image.

Preserves behavior: entrypoint.sh, port 10000, src/aimock_toggle.py,
shared_python/ -> /app/shared/python/ + PYTHONPATH. No image-level
NODE_ENV (entrypoint.sh scopes it to Next.js only).
…ilder

Split the runner image into three stages:
- frontend (node:22-slim) builds Next.js artifacts
- agent-builder (python:3.12.13) builds /opt/venv from requirements.txt
- runner (python:3.12.13-slim) installs Node.js + copies artifacts, with no
  pip and no build-essential

Mirrors the pattern already used by showcase/starters/llamaindex/Dockerfile.
…nv builder

Split the runner image into three stages:
- frontend (node:22-slim) builds Next.js artifacts
- agent-builder (python:3.12.13) builds /opt/venv from requirements.txt
- runner (python:3.12.13-slim) installs Node.js + copies artifacts, with no
  pip and no build-essential

Mirrors the pattern already used by showcase/starters/ms-agent-python/Dockerfile.
…uilder

Split the runner image into three stages:
- frontend (node:22-slim) builds Next.js artifacts
- agent-builder (python:3.12.13) builds /opt/venv from requirements.txt
- runner (python:3.12.13-slim) installs Node.js + copies artifacts, with no
  pip and no build-essential

Mirrors the pattern already used by showcase/starters/pydantic-ai/Dockerfile.
Split the runner image into three stages:
- frontend (node:22-slim) builds Next.js artifacts
- agent-builder (python:3.12.13) builds /opt/venv from requirements.txt
- runner (python:3.12.13-slim) installs Node.js + copies artifacts, with no
  pip and no build-essential

Mirrors the pattern already used by showcase/starters/strands/Dockerfile.
…entation

Package-level service claims to listen on :8000 but Railway health probes
fail. Narrow the cold-start window by timestamping each phase from
entrypoint exec to first /health-serving moment:

- entrypoint.sh: print `[entrypoint] pre-node <ISO>` immediately before
  `node /app/agent_server.js`, pairing with the agent_server.ts prints
  below to chain timestamps across the exec boundary.
- agent_server.ts: print `[agent_server] module loaded <ISO>` before any
  side-effect imports (so import-time hangs surface distinctly from
  init-time hangs), `[agent_server] pre-Anthropic <ISO>` right before
  `new Anthropic(...)`, and include an ISO timestamp in the existing
  app.listen() callback so we can read the delta directly.

No behavior change — only logs added. Next deploy cycle should reveal
which phase consumes the budget and whether the failure mode is
listen-but-unreachable vs. listen-never-reached.
Add showcase/starters/template/README.md covering the multi-stage build
convention (builder + runtime split), the >=40% image-size reduction
target, the linux/amd64 platform requirement for local builds, and the
dockerfile_hygiene probe rules (>=2 FROM stages, no dev-dep installs in
the runtime stage).

Expand the header comment on showcase/scripts/generate-starters.ts to
document the >=40% size target, the getAgentBuildSteps/getAgentBuildCopy
handoff in more detail, and the linux/amd64 platform pin in the deploy
workflow.
Add platforms: linux/amd64 to the depot/build-push-action invocation in
showcase_deploy.yml. Railway and GHCR serve x86 hosts, so an arm64-only
image crashes on pull. Matches the platform requirement enforced for
local docker build invocations (documented in
showcase/starters/template/README.md).
…anup kill, preserve --rootDir ., strip dead langgraph-ts server.mjs, guard AGENT_DIR expansion

- entrypoint.template.sh: cleanup trap + final kill now tolerate no-match
  (|| true) so trap doesn't abort shell when one of the three PIDs has
  already exited. Package-level entrypoint.sh already had this shape.
- generate-starters.ts: claude-sdk-typescript tsc now uses --rootDir .
  so emitted artifact is /app/dist/agent/index.js (matches entrypoint
  expectation + runner-stage COPY). tsc was inferring agent/ as rootDir
  and stripping the prefix.
- generate-starters.ts: drop server.mjs from langgraph-typescript starter
  output. The starter uses 'npx @langchain/langgraph-cli dev' and never
  invokes server.mjs; the file imports @langchain/langgraph-api/server
  which is not in the starter's extraDependencies (resolution relied on
  transitive hoist via @langchain/langgraph-cli). The file stays in the
  PACKAGE where prod mode does use it.
- generate-starters.ts: assert agentDir non-empty / non-absolute before
  Dockerfile substitution so the 'rm -f {{AGENT_DIR}}/package*.json' line
  can never degrade into 'rm -f /package*.json' across /app.
@vercel

vercel Bot commented Apr 22, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Apr 22, 2026 3:13am
research-canvas Ready Ready Preview, Comment Apr 22, 2026 3:13am
travel Ready Ready Preview, Comment Apr 22, 2026 3:13am
2 Skipped Deployments
Project Deployment Actions Updated (UTC)
chat-with-your-data Skipped Skipped Apr 22, 2026 3:13am
form-filling Skipped Skipped Apr 22, 2026 3:13am

Request Review

@github-actions

Copy link
Copy Markdown
Contributor

📣 Social Copy Generator

Generate social media copies (Twitter/X, LinkedIn, Blog Post) for this PR using Claude.

  • Generate social media copies

@vercel
vercel Bot temporarily deployed to Preview – form-filling April 22, 2026 03:10 Inactive
@vercel
vercel Bot temporarily deployed to Preview – chat-with-your-data April 22, 2026 03:10 Inactive
@jpr5
jpr5 merged commit ba578c5 into main Apr 22, 2026
13 checks passed
@jpr5
jpr5 deleted the feat/showcase-multistage-docker branch April 22, 2026 03:15
jpr5 added a commit that referenced this pull request Apr 22, 2026
…re silently exiting rc=127 (#4174)

## Summary
- Add `curl` to the runtime `apt-get install` line in:
  - `showcase/starters/template/dockerfiles/Dockerfile.typescript`
-
`showcase/packages/{claude-sdk-typescript,langgraph-typescript,mastra}/Dockerfile`
  - 3 starter Dockerfiles (regenerated from template)

## Why
Multi-stage Docker refactor (#4147) moved TS showcase services to
`node:22-slim` runtime. That base image doesn't include `curl`. The
watchdog's liveness probe invokes `curl -sS --max-time 5
http://127.0.0.1:8124/ok` — which exits `rc=127 "command not found"`
every cycle. After 180s grace + 3×30s strikes the watchdog kills the
agent. Railway auto-restarts. Loop forever.

Verified via `railway ssh`:
```
sh: 1: curl: not found
rc=127
```
while `ss -tlnp` on the same container confirmed both :8123
(langgraph-api) and :8124 (liveness.mjs) LISTEN. The agent was always
healthy — the probe was broken.

## Test plan
- [ ] Local amd64 docker build for starter+package variants succeeds
- [ ] `docker run ... sh -c "which curl"` prints `/usr/bin/curl`
- [ ] After Railway redeploy of langgraph-typescript, steady-state: no
kill-loop, `/api/health` green
pull Bot pushed a commit to KornaAI/CopilotKit that referenced this pull request Apr 22, 2026
… silently exiting rc=127

The multi-stage Docker refactor (CopilotKit#4147) moved TypeScript showcase services
to `node:22-slim` runtime. That base image does NOT include `curl`.

entrypoint.sh's watchdog runs `curl -sS --max-time 5 http://127.0.0.1:8124/ok`
every 5s to probe the liveness endpoint. Without curl the probe exits
rc=127 "command not found" every cycle. After 180s grace + 3x30s strikes
the watchdog kills the agent process. Railway auto-restarts. Kill-loop
forever.

Verified via `railway ssh --service showcase-langgraph-typescript`:

    sh: 1: curl: not found
    rc=127

while `ss -tlnp` on the same container confirmed BOTH 0.0.0.0:8123
(langgraph-api) and 0.0.0.0:8124 (liveness.mjs) LISTEN. The agent
servers were healthy the whole time — the probe tool was missing.

Fix: add `apt-get install -y --no-install-recommends curl` to the
runtime stage of:

  - showcase/starters/template/dockerfiles/Dockerfile.typescript (source)
  - showcase/packages/claude-sdk-typescript/Dockerfile
  - showcase/packages/langgraph-typescript/Dockerfile
  - showcase/packages/mastra/Dockerfile

3 starter Dockerfiles regenerated from the template via
`pnpm -C showcase/scripts generate-starters`.

Python/Java/.NET services already install curl (they need it for
NodeSource or similar) and are unaffected.

Smoke: local `docker build --platform linux/amd64` for both
starter + package variants succeeded; `docker run ... sh -c "which curl"`
prints /usr/bin/curl in both.
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
…ers, 17 packages (CopilotKit#4147)

## Summary
- Rewrite starter Dockerfile templates (`typescript`, `python`, `java`,
`dotnet`) as true multi-stage: builder has dev tools, runner is minimal.
No `pip`/`npm`/`pnpm`/`tsx`/`*-cli dev` in runtime stages.
- Encode prod-mode behaviors for `claude-sdk-typescript`, `mastra`,
`langgraph-typescript` directly in the TS template + generator
conditionals (folds in the pattern from CopilotKit#4132 for langgraph-ts; adds
parallel migration for claude-sdk-ts + mastra).
- Regenerate all 17 starter Dockerfiles.
- Rewrite all 17 package Dockerfiles to match the template shape
(multi-stage, venv builder for Python, 3-stage Python runtime, `USER
app`, etc.).
- Cold-start instrumentation on `claude-sdk-typescript` package
(absorbed from closed PR CopilotKit#4133).
- Pin `platforms: linux/amd64` in the showcase deploy workflow
(`docker/build-push-action` step) to match what Railway + GHCR require.
- Template `README.md` documenting multi-stage conventions, size target,
platform mandate, and the `dockerfile_hygiene` probe.
- `generate-starters.ts` strips the `langgraph-typescript` starter's
dead `server.mjs` + its `start` script (both reference deps only needed
in the package's prod-mode path).

## Why
Railway cold starts exceed the 180s watchdog grace when the runtime
stage boots via `langgraph-cli dev` / `npx mastra dev` / `npx tsx` — the
dev-mode work (TS compile, Rollup bundle, native libsql init) blocks the
health probe. CopilotKit#4132 proved the fix is to move this to image build time
for langgraph-ts. This PR generalizes that shape to all TS starters that
need it and reshapes every Dockerfile in the tree so runners no longer
carry dev toolchains.

Secondary outcomes:
- Smaller runtime images (pip/npm toolchain moved to builder only).
- Consistent `--platform linux/amd64` pinning end-to-end.
- No `pnpm install --frozen-lockfile` in the TS starter template
(starters are no-lockfile by design).
- `validate-pins` ratchet re-baselined to match the regenerated spec
strings.

## Test plan
- [ ] `docker build --platform linux/amd64` green for every starter (17)
and package (17) locally
- [ ] `pnpm -C showcase/scripts` vitest: 1085/1085 pass
- [ ] `tsc --noEmit -p showcase/scripts/tsconfig.json` clean
- [ ] `oxfmt --check` + `oxlint` clean on touched TS files
- [ ] validate-pins: count 110, hash matches updated baseline
- [ ] CI Showcase Validate green on PR HEAD
- [ ] Post-merge: showcase deploy for mastra + claude-sdk-typescript
goes green (currently flapping)
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
… silently exiting rc=127

The multi-stage Docker refactor (CopilotKit#4147) moved TypeScript showcase services
to `node:22-slim` runtime. That base image does NOT include `curl`.

entrypoint.sh's watchdog runs `curl -sS --max-time 5 http://127.0.0.1:8124/ok`
every 5s to probe the liveness endpoint. Without curl the probe exits
rc=127 "command not found" every cycle. After 180s grace + 3x30s strikes
the watchdog kills the agent process. Railway auto-restarts. Kill-loop
forever.

Verified via `railway ssh --service showcase-langgraph-typescript`:

    sh: 1: curl: not found
    rc=127

while `ss -tlnp` on the same container confirmed BOTH 0.0.0.0:8123
(langgraph-api) and 0.0.0.0:8124 (liveness.mjs) LISTEN. The agent
servers were healthy the whole time — the probe tool was missing.

Fix: add `apt-get install -y --no-install-recommends curl` to the
runtime stage of:

  - showcase/starters/template/dockerfiles/Dockerfile.typescript (source)
  - showcase/packages/claude-sdk-typescript/Dockerfile
  - showcase/packages/langgraph-typescript/Dockerfile
  - showcase/packages/mastra/Dockerfile

3 starter Dockerfiles regenerated from the template via
`pnpm -C showcase/scripts generate-starters`.

Python/Java/.NET services already install curl (they need it for
NodeSource or similar) and are unaffected.

Smoke: local `docker build --platform linux/amd64` for both
starter + package variants succeeded; `docker run ... sh -c "which curl"`
prints /usr/bin/curl in both.
zeekay pushed a commit to Dream-AI-4444/CopilotKit that referenced this pull request Sep 11, 2026
…re silently exiting rc=127 (CopilotKit#4174)

## Summary
- Add `curl` to the runtime `apt-get install` line in:
  - `showcase/starters/template/dockerfiles/Dockerfile.typescript`
-
`showcase/packages/{claude-sdk-typescript,langgraph-typescript,mastra}/Dockerfile`
  - 3 starter Dockerfiles (regenerated from template)

## Why
Multi-stage Docker refactor (CopilotKit#4147) moved TS showcase services to
`node:22-slim` runtime. That base image doesn't include `curl`. The
watchdog's liveness probe invokes `curl -sS --max-time 5
http://127.0.0.1:8124/ok` — which exits `rc=127 "command not found"`
every cycle. After 180s grace + 3×30s strikes the watchdog kills the
agent. Railway auto-restarts. Loop forever.

Verified via `railway ssh`:
```
sh: 1: curl: not found
rc=127
```
while `ss -tlnp` on the same container confirmed both :8123
(langgraph-api) and :8124 (liveness.mjs) LISTEN. The agent was always
healthy — the probe was broken.

## Test plan
- [ ] Local amd64 docker build for starter+package variants succeeds
- [ ] `docker run ... sh -c "which curl"` prints `/usr/bin/curl`
- [ ] After Railway redeploy of langgraph-typescript, steady-state: no
kill-loop, `/api/health` green

This branch was successfully deployed

3 active and 2 inactive deployments
Preview – research-canvas — c71641db Deployed Apr 22, 2026 by vercel[bot]
Preview – travel — c71641db Deployed Apr 22, 2026 by vercel[bot]
Preview – docs — c71641db Deployed Apr 22, 2026 by vercel[bot]
Preview – form-filling — c71641db Deployed Apr 22, 2026 by vercel[bot]
Preview – chat-with-your-data — c71641db Deployed Apr 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant