Repository navigation
feat(showcase): multi-stage Docker refactor across template, 17 starters, 17 packages - #4147
Merged
Merged
Conversation
…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.
…ith unprivileged user and scoped NODE_ENV
…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).
…th unprivileged user and scoped NODE_ENV
…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.
…eged user and Temurin 21
…privileged user and scoped NODE_ENV
…langroid Dockerfiles
…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).
…after prod-mode deps
…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.
Contributor
|
The latest updates on your projects. Learn more about Vercel for GitHub.
2 Skipped Deployments
|
Contributor
📣 Social Copy GeneratorGenerate social media copies (Twitter/X, LinkedIn, Blog Post) for this PR using Claude.
|
3 tasks
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
typescript,python,java,dotnet) as true multi-stage: builder has dev tools, runner is minimal. Nopip/npm/pnpm/tsx/*-cli devin runtime stages.claude-sdk-typescript,mastra,langgraph-typescriptdirectly 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).USER app, etc.).claude-sdk-typescriptpackage (absorbed from closed PR fix(showcase): prod-mode migration for mastra + claude-sdk-typescript starters #4133).platforms: linux/amd64in the showcase deploy workflow (docker/build-push-actionstep) to match what Railway + GHCR require.README.mddocumenting multi-stage conventions, size target, platform mandate, and thedockerfile_hygieneprobe.generate-starters.tsstrips thelanggraph-typescriptstarter's deadserver.mjs+ itsstartscript (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:
--platform linux/amd64pinning end-to-end.pnpm install --frozen-lockfilein the TS starter template (starters are no-lockfile by design).validate-pinsratchet re-baselined to match the regenerated spec strings.Test plan
docker build --platform linux/amd64green for every starter (17) and package (17) locallypnpm -C showcase/scriptsvitest: 1085/1085 passtsc --noEmit -p showcase/scripts/tsconfig.jsoncleanoxfmt --check+oxlintclean on touched TS files