Repository navigation
feat(cli): provision the site on the control-plane during migration (D7) - #551
Merged
Merged
Conversation
JonasJesus42
force-pushed
the
feat/migrate-provision-control-plane
branch
from
September 29, 2026 17:38
d0a651c to
9804336
Compare
A migrated site came out undeployable: the pipeline had to be wired by hand, one Cloudflare dashboard click per worker (D6.3), and nothing gave the site the KV namespace fast-deploy needs. D7 (this commit, superseding D6.3) moves deploy to our own pipeline, and the migration now calls its front door. `provisionSite` posts SITE_CREATE to the control-plane's MCP endpoint and writes the KV namespace id it returns into the scaffolded wrangler.jsonc. SITE_CREATE is idempotent and create-if-absent at every step: admin `sites` row, org ownership, the site's OWN `deco-kv-<site>` namespace, the production environment, and the Deco CR that makes it deploy. The site's own namespace is the point, not a detail: `index:live` is one key per namespace, so two sites sharing one clobber each other's live pointer. And our builder seeds `decofile:<sha>` before activating the new version, which is the guarantee that makes stubbing `blocks.gen` out of the server bundle safe — a site on CF Workers Builds can never take that memory win. Inert without `DECO_CONTROL_PLANE_TOKEN` + `DECO_ORG`: prints the equivalent call and continues, like `provisionAnalytics`. A migration must not fail because an operator ran it without a token, and the id is not load-bearing anyway — the builder re-forces it from `CF_KV_NAMESPACE_ID` on every build. `setKvNamespaceIdInJsonc` edits the config as text rather than parse-and-restringify, because the scaffolded wrangler.jsonc carries the comments explaining why each binding exists. Also hardens `provisionAnalytics`, which interpolated `package.json`'s name straight into SQL sent to the Supabase Management API. That API takes no bind parameters, so the honest fix is to refuse anything that is not a plain site slug. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
A stalled control-plane blocked the migration forever; on timeout the existing catch prints the manual SITE_CREATE fallback. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
JonasJesus42
force-pushed
the
feat/migrate-provision-control-plane
branch
from
September 29, 2026 19:05
9804336 to
7b91055
Compare
JonasJesus42
added a commit
that referenced
this pull request
Sep 29, 2026
Quatro coisas em circulação estavam erradas ou desatualizadas. **1. As chaves de KV.** `CLAUDE.md` dizia `decofile:current` + `index:revision`. Nenhuma das duas existe. As chaves são **por deployment id**: `decofile:<id>`, `index:revision:<id>`, `index:live`, `index:deployments` (`packages/blocks/src/cms/blockSource.ts:113-145`). E isso não é cosmético — um ponteiro único mutável entregaria conteúdo novo para código velho ainda no ar durante um rolling deploy. **2. `wrangler.toml`.** O `docs/fast-deploy.md` documentava a config em toml. O tooling lê e escreve `wrangler.jsonc`; nada emite toml (o parser toml existe só para repos legados). **3. "O snapshot bundlado é o fallback de KV".** No modo bundle-stub não é — `ensureBlocksHydrated` falha alto em vez de servir um site vazio que o edge cacharia. Esse modo, os números de memória por trás dele (três cópias do decofile por isolate, ~27 MB para um decofile de 9.2 MB contra teto de 128 MB sem botão de GC) e o porquê de ser gated na pipeline declarar que semeia agora têm seção própria. **4. `loadRedirects` module-level.** Listado como limitação não-fast-deployável; o `workerEntry.ts:2082-2097` já rechaveia o mapa de redirects por revisão. Só vale para código de site que iça o próprio `loadRedirects(loadBlocks())`. De quebra: os pré-requisitos de site agora apontam para a automação que passou a cobri-los (`SITE_CREATE` + o scaffold de migração, D7), e o requisito de chamar `setupTanstackFastDeploy()` — que não estava documentado em lugar nenhum e é a diferença entre um publish funcionar e escrever nada em silêncio. Fecha a pilha: #548 → #549 (+ infra#333) → #550 → #551 → este. 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- This is an auto-generated description by cubic. --> --- ## Summary by cubic Corrects the fast-deploy docs in `CLAUDE.md` and `docs/fast-deploy.md` to match the actual tooling contract. - KV keys are per deployment id (`decofile:<id>`, `index:revision:<id>`, `index:live`, `index:deployments`), never a single mutable pointer that would feed new content to old code mid-rollout. - The config is `wrangler.jsonc`; nothing emits toml, though it is still parsed for legacy repos. - Bundle-stub mode removes the bundled snapshot fallback — `ensureBlocksHydrated` fails loudly rather than serving an empty site, and the mode is gated on the pipeline declaring it seeds the KV key before activation. - The module-level `loadRedirects` limitation no longer applies to the framework's own redirects; it only affects site code that hoists its own `loadRedirects(loadBlocks())`. - Site prerequisites now point at the automation that provisions them, and the previously undocumented `setupTanstackFastDeploy()` call is recorded as required. Merge after #550 and #551 — the prerequisites section references D7, `SITE_CREATE`, and the scaffolded `setupTanstackFastDeploy()` call. <sup>Written for commit 7bfb8b1. Summary will update on new commits.</sup> <a href="https://cubic.dev/pr/decocms/blocks/pull/552?utm_source=github" target="_blank" rel="noopener noreferrer" data-no-image-dialog="true"><picture><source media="(prefers-color-scheme: dark)" srcset="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://www.cubic.dev/buttons/review-in-cubic-light.svg"><img alt="Review in cubic" src="https://www.cubic.dev/buttons/review-in-cubic-dark.svg"></picture></a> <!-- End of auto-generated description by cubic. --> --- **Merge after #550 and #551** — the prerequisites section references D7, `SITE_CREATE` and the scaffolded `setupTanstackFastDeploy()` call, which only exist once those land. Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.
Problema
Um site migrado saía não-deployável. A pipeline era wiring manual, um clique no dashboard da Cloudflare por worker (D6.3), e nada dava ao site o namespace de KV que o fast-deploy precisa.
D7 — deploy passa para o control-plane
Registro D7 (neste PR, em
MIGRATION_TOOLING_PLAN.md+ a regra always-loaded) — é o "follow-up D-record once shipped" que o D6.3 prometeu. O Cloudflare Workers Builds sai; entradecocms/control-plane(SITE_CREATE→ repo, adminsites, org ownership, KV/R2/D1 próprios do site, env de produção, Deco CR) + operator +cfworkers-builder.Três coisas que o CF Builds estruturalmente não dava:
index:liveé uma chave por namespace — dois sites dividindo um se atropelam.ensureSiteKvNamespacecriadeco-kv-<site>e o builder re-força o id doDECO_KVa partir deCF_KV_NAMESPACE_IDa cada build, então repo de tenant não consegue bindar KV de outro site.decofile:<sha>antes dowrangler deploye viraindex:livedepois — código novo nunca lê conteúdo velho. Essa ordem é exatamente o que torna seguro stubar oblocks.gendo bundle servidor (feat(tanstack): stub blocks.gen by default when the pipeline seeds KV #549), o corte de memória. Site no CF Builds nunca consegue esse ganho.routes/account_idcontrolados pelo tenant.Inalterado do D6.3: storefront continua sem
deploy.yml/preview.yml/sync-secrets.ymlscaffoldados — a pipeline é do control-plane, não do repo do site.Mudanças
provisionSitenomigrate.ts, logo após o bootstrap:tools/call SITE_CREATEno/mcp, grava okvNamespaceIdretornado nowrangler.jsonc. Inerte semDECO_CONTROL_PLANE_TOKEN+DECO_ORG— imprime a chamada equivalente e segue, mesmo padrão doprovisionAnalytics. Migração não pode falhar porque alguém rodou sem token, e o id nem é load-bearing (o builder re-força a cada build).setKvNamespaceIdInJsoncemlib/wrangler-config.ts, ao lado do leitor. Edita como texto em vez de parse-and-restringify, porque owrangler.jsoncscaffoldado carrega os comentários explicando por que cada binding existe.provisionAnalyticsinterpolavapackage.json.namedireto numa string SQL enviada à Supabase Management API. Essa API não aceita bind parameters, então a correção honesta é recusar o que não for um slug de site.--helpdocumenta as env vars novas.Testes
5 casos para
setKvNamespaceIdInJsonc: escreve o id preservando comentários, não encosta em outro binding, aceitabinding/idem qualquer ordem e entrada semid, e devolve a fonte intacta quando o binding não existe (não é erro — o builder re-força mesmo assim).Pilha: #548 → #549 (+ infra#333) → #550 → este.
🤖 Generated with Claude Code
Summary by cubic
Migrated sites previously required manual Cloudflare wiring and lacked the KV namespace needed for fast deploys. Migration now calls the control plane's
SITE_CREATEtool to provision deployment resources and writes the site's KV namespace ID towrangler.jsonc; storefront repos still receive no deploy workflow scaffolding.DECO_CONTROL_PLANE_TOKENandDECO_ORG; without them, migration prints an equivalentcurlcommand and continues.DECO_CONTROL_PLANE_URLoverrides the control-plane base URL, and when the source repo already existsSITE_CREATEreferences it instead of generating one.SITE_CREATEcall times out after 30 seconds so a stalled control-plane can't block the migration.Written for commit 7b91055. Summary will update on new commits.
Refs #486. Supersedes #431: the builder strips tenant-supplied
account_id/routes, so the scaffold shouldn't pin one.