Skip to content

build(deploy): build every cloud service through one turbo graph - #2425

Merged
fforootd merged 9 commits into
mainfrom
claude/amazing-aryabhata-c98c0c
Oct 28, 2026
Merged

fforootd merged 9 commits into
mainfrom
claude/amazing-aryabhata-c98c0c

Conversation

@fforootd

@fforootd fforootd commented Oct 28, 2026 •

Copy link
Copy Markdown
Member

Summary

Why: this is about turbo's build logic, which the hosted cloud's Vercel builds use and which may replace moon one day.

Puts the hosted cloud's Vercel builds on turbo's task graph, so CI and the deployments run the same tasks against the team's remote cache. Moon stays the required gate and gets no cloud project.

  • apps/cloud is a package, @zitadel/cloud (private), with five tasks in apps/cloud/turbo.json:
    • build: the launcher, apps/cloud/dist/nextgen-launcher, compiled by the new build-launcher.sh (build.sh's go build with the same ldflags and -tags noconsole). Never cached: the launcher runs with the deployment's secrets and becomes its function. Branch builds (previews, CI over OIDC) can write the team's remote cache, so an entry planted under production's key would run in production; Codex's security review caught this. Go's own build cache, which Vercel keeps per branch, keeps the compile short. Its inputs (the Go files and what they embed, as moon's serverInputs lists them, plus the server's version) still decide when it is affected.
    • migrate: never cached, depends on build, and runs launcher migrate. It passes the whole environment through (passThroughEnv: ["*"]). The launcher checks every variable the function needs at build time, and strict mode would hide any variable nobody listed, such as feat: let a scheduler start the audit event purge instead of the server's timer #2397's CRON_SECRET.
    • deploy: never cached, depends on migrate. deploy.sh copies the binary to $VERCEL_OUTPUT_FILE, a temp path outside the repository where Vercel's Go builder takes the function from. A failed migration stops the run before the copy.
    • schemas: apps/cloud/dist/cloud-schemas, rendered by scripts/render-builtin-schemas.mjs, whose default output moved there.
    • dev: pnpm run cloud's script, which replaces the root //#cloud. It passes the whole environment through, as pnpm run cloud does: vercel dev hands it to every service, and the server alone reads NEXTGEN_* and OTEL_*.
  • The server service's build command is pnpm install … && node_modules/.bin/turbo run deploy --filter=@zitadel/cloud. Vercel's Go builder never runs an installCommand: its source has none, and the "Running install" step lives in the JS builders. So the install has to precede turbo in the command; turbo itself comes with it. pnpm skips the install in milliseconds once an earlier service installed. The Go build-cache prune moved into the build task: after a turbo hit Go has refreshed nothing, and the prune would empty its cache.
  • docs and website build with turbo run build --filter=@zitadel/docs / --filter=@zitadel/website. Their builds now list DOCS_SPEED_INSIGHTS_SAMPLE_RATE / WEBSITE_SPEED_INSIGHTS_SAMPLE_RATE: both are read at build time, and strict mode would have hidden them, sending Speed Insights for every page load. The docs' build and dev scripts are plain next build and next dev, as moon's commands; their generate dependency bundles first. turborepo.md now states the rule: a script does its own task's work only, and a step that is a task of its own goes through the graph, never a && b.
  • schemas runs turbo run schemas --filter=@zitadel/cloud with the shared install. It stays rooted at apps/cloud. A service takes no framework: null, and Vercel detects frameworks from dependencies, which this package.json has none of. So it still builds as a static service.
  • Docs follow: apps/cloud/README.md, the cloud runbook, docs/design/build/turborepo.md (it said the docs and website bypass turbo, and that build.sh builds a login UI), the migration plan, .moon/AGENTS.md, and the apps' AGENTS.md files.

Two traps this avoids

  • Turbo hashes the ignored files that a listed glob matches. On Vercel the Go toolchain and module cache sit inside the checkout, in .vercel/cache/golang. The launcher's $TURBO_ROOT$/**/*.go would hash the Go standard library and every module in the cache, and the key would follow the cache's contents. The task excludes .vercel/**, node_modules and agents' worktrees (.claude/, …), the same list as build: stop docs and test edits from re-running the task graph, and let turbo select what ci-turbo runs #2420.
  • The docs' and website's own builds never hit the cache on Vercel. Skew Protection is on (skewProtectionMaxAge 43200). A Next.js build bakes the deployment's ID into every asset URL (?dpl=), and Vercel's URLs into its metadata, which turbo passes through unhashed. Turbo already hashes NEXT_DEPLOYMENT_ID into every task of a Next.js package. The builds also list VERCEL_DEPLOYMENT_ID, so the key holds the deployment even if Skew Protection goes off. The docs' generate and typecheck read no NEXT_* variable, so they drop them all (!NEXT_*) and still hit. Dropping only NEXT_DEPLOYMENT_ID wasn't enough: the docs service's builds also hash Vercel's NEXT_PUBLIC_VERCEL_* variables (URL, commit), and the second preview missed both tasks with unchanged inputs.

So on Vercel the docs and website gain one graph and a strict environment, not speed. Each deployment uploads a docs build (about 31 MB compressed, measured locally) and a website build (about 2.5 MB) that no other deployment can use. The docs service also runs the docs typecheck now: build depends on it, as in moon. That costs time only when the docs change, since a cached typecheck is restored. Real reuse would take turning Skew Protection off, which is a product decision.

Validation

  • turbo run build schemas --filter=@zitadel/cloud twice: schemas is a cache hit on the rerun, and build runs both times (uncached by design, see above). go version -m on the binary shows -tags=noconsole, CGO_ENABLED=0, -trimpath.
  • Dry runs: Go and SQL files under .vercel/cache/golang don't change the launcher's hash, and no input comes from node_modules. VERCEL_TARGET_ENV changes every key, which is why CI's entries are never hits on Vercel (the migration plan said they were; corrected).
  • The server's build command from vercel.json, run locally with an install-only stub pnpm:
    • With VERCEL_OUTPUT_FILE set: build (cache hit), then migrate (applied, scratch SQLite), then deploy (copied the binary).
    • With both CLOUD_* database URLs pointed at one host on purpose: migrate failed on the pooler check, which names both variables, so they reached it through turbo. deploy never ran, and nothing was copied.
  • turbo run deploy --filter=@zitadel/cloud locally without Vercel: migrates, then deploy says there is nothing to hand over.
  • Dry runs with two simulated deployments' NEXT_DEPLOYMENT_ID, VERCEL_DEPLOYMENT_ID and NEXT_PUBLIC_VERCEL_*: the docs' generate and typecheck keep one key, and the build gets one per deployment.
  • The docs and website built through turbo as two simulated deployments (different NEXT_DEPLOYMENT_ID / VERCEL_DEPLOYMENT_ID). The first: 12 misses, 31 s. The second: 10 hits, including the docs' generate and typecheck; only the two Next.js builds re-ran (10 s), and the website's HTML carries the second deployment's dpl=.
  • go test ./apps/cloud/launcher/ -count=1; vitest run scripts/render-builtin-schemas.test.mjs
  • moon run workspace:check-moon-graph; Biome on the changed scripts; node scripts/check-pr-title.mjs
  • turbo boundaries: 40 issues on this branch, the same as on main (the vitest.shared.mjs imports build: run turbo boundaries in CI and move the shared Vitest config into a package #2423 fixes), none in @zitadel/cloud. With build: run turbo boundaries in CI and move the shared Vitest config into a package #2423 merged in: no issues, 39 packages.
  • Vercel preview and deployment-checks: see the checks on this PR.

Release notes / changeset

Empty changeset (.changeset/cloud-turbo-package.md): apps/server/turbo.json and apps/server/moon.yml lie under @zitadel/server's publishable root, but they only rename the file the launcher's tests read. Nothing ships.

Notes

🤖 Generated with Claude Code

apps/cloud becomes the private workspace package @zitadel/cloud with
three turbo tasks: `build` (the launcher, apps/cloud/dist/nextgen-launcher,
via build-launcher.sh with build.sh's ldflags and -tags noconsole),
`schemas` (apps/cloud/dist/cloud-schemas) and `dev` (pnpm run cloud's
script, replacing the root //#cloud). Moon gets no cloud project.

- build.sh builds the launcher with `turbo run build --filter=@zitadel/cloud`,
  copies it to $VERCEL_OUTPUT_FILE and migrates; the migration is never
  cached. The launcher's key holds VERCEL_GIT_COMMIT_REF, the branch it
  stamps in to pick a preview's database, and leaves out .vercel/** and
  node_modules: turbo hashes the ignored files a glob matches, and on
  Vercel the Go toolchain and module cache lie in .vercel/cache/golang.
  The Go cache prune moved into the build task, so a cache hit does not
  empty Go's cache.
- The docs and website services run `turbo run build --filter=...`. Their
  builds now see the Speed Insights sample rates (strict mode hid them),
  and are keyed by VERCEL_DEPLOYMENT_ID: Skew Protection bakes the
  deployment's ID into a Next.js build, so they never hit on Vercel. The
  docs' generate and typecheck drop the inferred NEXT_DEPLOYMENT_ID and
  still hit. The docs' build script is plain `next build`, as moon's.
- The schemas service runs `turbo run schemas --filter=@zitadel/cloud`
  with the shared install and stays rooted at apps/cloud, whose
  package.json has no dependencies, so Vercel still detects no framework.
- Runbook, README, turbo design docs and AGENTS.md files follow.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vercel

vercel Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
cloud Ready Ready Preview Oct 28, 2026 4:52am UTC

Request Review

@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

🦋 Changeset detected

Latest commit: 3cbd88e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Revert wording the package does not need, so the change stays clear of
the open PRs that edit the same files: the README's build.sh row (beside
the row #2397 changes), two runbook phrasings, the root turbo.json header
and the turborepo.md bullet on ignored files in input globs, which the
rework of #2420 covers. The cloud task's own comment keeps why it
excludes .vercel/ and the other ignored trees.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
apps/server/turbo.json and moon.yml lie under @zitadel/server's
publishable root, so the changeset check wants a changeset; they only
rename the file the launcher's tests read (build-launcher.sh), and
nothing ships.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fforootd
fforootd marked this pull request as ready for review October 28, 2026 02:53
Copilot AI balanced review requested due to automatic review settings October 28, 2026 02:53
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
🔒 Security Review ✅ Completed 2026-10-28T03:00:15.426281Z 2990487 Draft marked ready

Security findings

Advisory findings (1)

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛡️ Codex Security Review · Automatically triggered

Here are some automated security review suggestions for this pull request.

Reviewed commit: 299048754d

ℹ️ About Codex security reviews in GitHub

This is an experimental Codex feature. Security reviews are triggered when:

  • You comment "@codex security review"
  • A regular code review gets triggered (for example, "@codex review" or when a PR is opened), and you’re opted in so security review runs alongside code review

Once complete, Codex will leave suggestions, or a comment if no findings are found.

Comment thread apps/cloud/build.sh Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

This Vercel build/deploy change hinges on turbo remote-cache behavior, prune, and deployment keying that can only be validated through actual preview and deployment-check runs rather than static inspection.

No open issues 🎉

1 file not reviewed
  • pnpm-lock.yaml: Generated file
What changed in this PR

This PR moves the hosted cloud's Vercel builds onto a single turbo task graph so CI and deployments share the same tasks and the team's remote cache. apps/cloud becomes the private @zitadel/cloud package (no moon project) with build (launcher), schemas, and dev tasks. The server service's build.sh now delegates compilation to turbo (build-launcher.sh) and only copies the binary and runs migrations; docs/website/schemas services build through turbo filters. Extensive docs are updated to match, plus an empty changeset for the apps/server build-config touch that ships nothing.

Changes:

  • Introduce @zitadel/cloud package + apps/cloud/turbo.json; split Go compilation into build-launcher.sh, leaving build.sh to run turbo + migrate.
  • Point vercel.json services (docs, website, schemas) at turbo filters; move schemas output under apps/cloud/dist/cloud-schemas; add VERCEL_DEPLOYMENT_ID/Speed-Insights env to Next.js build tasks and drop NEXT_DEPLOYMENT_ID from docs generate/typecheck.
  • Update runbook/design/AGENTS docs and the launcher test to reference build-launcher.sh.
File Description
vercel.json Docs/website/schemas services now build via turbo filters; schemas install enabled, output dir rerooted to apps/cloud.
turbo.json Removes root //#cloud dev task (replaced by @zitadel/cloud#dev).
apps/​cloud/​turbo.json New build/schemas/dev tasks with Go-input globs, Vercel ignore excludes, and deployment-keying env.
apps/​cloud/​package.json New private @zitadel/cloud package (AGPL-3.0-only) with build/schemas/dev scripts.
apps/​cloud/​build.sh Delegates compile to turbo, installs when needed, copies binary to $VERCEL_OUTPUT_FILE, then migrates.
apps/​cloud/​build-launcher.sh New launcher compile (ldflags, -tags noconsole) + Go cache prune guarded by VERCEL.
apps/​cloud/​launcher/​main_test.go Test reads build-launcher.sh.
apps/​cloud/​launcher/​database.go, internal/​staticui/​console/​embed_noconsole.go Comment references updated to build-launcher.sh.
apps/​docs/​package.json build script reduced to next build (bundling via turbo generate).
apps/​docs/​turbo.json, apps/​website/​turbo.json Add deployment-ID/Speed-Insights env; docs drops NEXT_DEPLOYMENT_ID from generate/typecheck.
apps/​server/​turbo.json, apps/​server/​moon.yml Rename test input build.sh → build-launcher.sh.
scripts/​render-builtin-schemas.mjs DEFAULT_OUT_DIR moved to apps/cloud/dist/cloud-schemas; comments updated.
scripts/​run-cloud.mjs Comment updates only.
pnpm-lock.yaml Registers empty apps/cloud workspace importer.
.changeset/​cloud-turbo-package.md Empty changeset (publishable path touched, nothing ships).
docs/​runbooks/​cloud.md, docs/​design/​build/​turborepo.md, docs/​design/​build/​turborepo-migration.md, apps/​AGENTS.md, apps/​docs/​AGENTS.md, apps/​website/​AGENTS.md, .moon/​AGENTS.md, apps/​cloud/​README.md Documentation updated to reflect the unified turbo build graph.

Review effort: Balanced

…o task

The server service's build command now installs (the Go preset runs no
installCommand) and runs `turbo run deploy --filter=@zitadel/cloud`.
@zitadel/cloud's new `deploy` task depends on `build` (the launcher, from
the cache when nothing it compiles changed) and runs deploy.sh, the former
build.sh without its install and turbo call: copy the binary to
$VERCEL_OUTPUT_FILE, then migrate. It is never cached, and it passes the
whole environment through (`passThroughEnv: ["*"]`): the launcher checks
every variable the function needs at build time, so a variable strict mode
hid (CRON_SECRET, which #2397 adds, or any later one) would fail every
deployment.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…asks

Split the uncached `deploy` task in two, ordered with dependsOn: `migrate`
(after `build`; the launcher's migration, with the whole environment
passed through) and `deploy` (after `migrate`; deploy.sh now only copies
the binary to $VERCEL_OUTPUT_FILE, and only once the migration applied).
The server's build command still installs first: Vercel's Go builder runs
no installCommand, and turbo comes with the install.

The docs' generate and typecheck drop every NEXT_* variable from their
keys, not only NEXT_DEPLOYMENT_ID: the docs service's builds also hash
Vercel's NEXT_PUBLIC_VERCEL_* variables, and the second preview missed
both tasks with their inputs unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The launcher runs with the deployment's secrets (`migrate`) and becomes
its function, and branch builds (previews, CI over OIDC) can write the
team's remote cache, whose keys leave out PATH: an entry planted under
production's key would have run in production. @zitadel/cloud#build is
now uncached; Go's own build cache, which Vercel keeps per branch, keeps
the compile short. Its inputs still decide when it is affected, and
GOFLAGS, GOOS and GOARCH (which Vercel's Go builder sets for the
function's architecture) pass through.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread apps/docs/package.json Resolved
Comment thread vercel.json Resolved
…cripts

The docs' `dev` script bundled the API reference and the CLI reference
before `next dev`, the `generate` task's work, which both graphs already
run first (moon's docs:dev runs `next dev` itself). It is plain
`next dev` now, as the `build` script became `next build`. turborepo.md
states the rule: a script does its own task's work only, and a step that
is a task of its own is a dependsOn edge and a moon dep, never `a && b`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread apps/cloud/turbo.json Resolved
fforootd and others added 2 commits October 27, 2026 21:30
Vercel's Go builder runs no installCommand and runs the build command
through build-utils' execCommand with the container's PATH and Go's, while
the JS builders (@vercel/next, @vercel/static-build) put every
node_modules/.bin up to the repo root on PATH first. So the server's
build command installs itself and calls node_modules/.bin/turbo; vercel.json
takes no comments, so the runbook's layout row says it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@zitadel/cloud#dev listed CLOUD_DEV_*, NEXTGEN_* and GOFLAGS (the old
//#cloud's list), so under turbo the local cloud's server never saw the
OpenTelemetry SDK's OTEL_* variables, or anything else a service reads.
`vercel dev` hands the environment to every service, as `pnpm run cloud`
does, and the task is uncached, so it passes everything through.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@fforootd
fforootd added this pull request to the merge queue Oct 28, 2026
Merged via the queue into main with commit fa05250 Oct 28, 2026
18 checks passed
@fforootd
fforootd deleted the claude/amazing-aryabhata-c98c0c branch October 28, 2026 04:58
@github-project-automation github-project-automation Bot moved this from Inbox to Done in Engineering Kanban Oct 28, 2026
fforootd added a commit that referenced this pull request Oct 28, 2026
Resolves the conflict in docs/runbooks/cloud.md's service table: main
now builds every cloud service through one turbo graph (#2425), and this
branch adds /api/* to what the server serves. The server row takes
main's build and this branch's paths. The generated code matches a
fresh server:generate.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch was successfully deployed

1 active deployment
Preview — 3cbd88e7 Deployed Oct 28, 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

Archived in project

Development

Successfully merging this pull request may close these issues.

3 participants