Skip to content

Commit 8fd4fc3

Browse files
fix(prisma-cloud): an unchanged deploy no longer replaces a service that depends on another service (#446)
* fix(prisma-cloud): an unchanged deploy no longer makes a new version of a service that reads another service's URL A service's url output came from its deployment, which promotes itself on every deploy, so the url was unknown while planning. A consumer writes that url into an environment row and its deployment's triggers, and an unknown trigger replaces the deployment. Every deploy made a new version of every such consumer, even with nothing changed. The url output is now the App's endpoint domain, which is known from the App's create and does not change, the same value a service's own origin already uses. serviceId still waits for the promotion, because a custom domain reads it and is bound to the live deployment. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * fix(prisma-cloud): a missing endpoint domain names the service, and the docs say a service's url comes from its App One function reads an App's endpoint domain for a service's url, for serviceOrigin and for a service's own origin, and its error names the service. The design docs now draw a reading service's url row from the App, and no longer say the create-time domain is a placeholder. The tests also check that the reading service's row holds the url, that a new artifact for the service being read replaces only that service's deployment, and that reserve publishes the App's domain. The fake Management API used by the apply tests is now exported from @internal/lowering/scratch-stack. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * fix(prisma-cloud): a service's deployment is still created only after the services it reads are promoted Taking a service's url from its App removed the edge that made a reading service's deployment wait for its provider's promotion. A reading service's Deployment now also waits, through its app prop, on every output of the services and resources it reads. A Compute provider's serviceId resolves only after its promotion, so the order is kept on a first deploy and when both services change. The wait is on app, not in triggers, and an unresolved app counts as unchanged, so an unchanged reading service is still not replaced. appAfterEnvironment is renamed appAfter, since it now orders the deployment after its provider outputs as well as its environment rows. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * fix(prisma-cloud): the deploy-order tests fail when the producer is never promoted, and the docs name producers and consumers The ordering tests now assert the exact sequence of the producer's promotion and the consumer's deployment create, so a missing promotion fails them. Code, tests and docs use producer and consumer for the two ends of a dependency edge. The serviceId output says both reasons it comes from the deployment, the edge helper's comment says only what a caller needs, and the self-origin value is endpointDomainOf itself. The edge decision record has a dated amendment: a service's url comes from its App, and a consumer's deployment waits for its producers' promotion through the app prop, never through triggers. The Prisma Cloud docs and core's lowering steps state what is true now. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> * fix(prisma-cloud): a serviceOrigin that cannot resolve names the consumer again The shared missing-domain error named only the producing service. It now also says which consumer's serviceOrigin could not be resolved, as the message did before the check was shared. Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io> --------- Signed-off-by: willbot <w.a.madden+machine@gmail.com> Signed-off-by: Will Madden <madden@prisma.io>
1 parent f5566e0 commit 8fd4fc3

16 files changed

Lines changed: 524 additions & 170 deletions

File tree

‎docs/design/05-prisma-cloud/alchemy-lowering.md‎

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ behind them.
6767
| `Prisma.Project` | Project | name | projectId | **one per Prisma Composer application**; resolved by the CLI before Alchemy runs, so no lowering yields one |
6868
| `Prisma.Database` | Database | project, name?, region, branchId?, logicalId? | databaseId, connection strings | one per Module-provisioned postgres resource; never the project default; a branch-attached database is created with `branchId` and no display name (upstream refuses the combination — see [deploying.md](../../guides/deploying.md)) |
6969
| `Prisma.Connection` | database connection info | database, name | connectionId, directConnectionString | Composer binds the DIRECT string explicitly; upstream's `databaseUrl` is pooled-first |
70-
| `Prisma.App` | App | project, displayName, regionId, branchId?, logicalId? | appId, appEndpointDomain | `branchId` targets the Branch of an environment other than `production`; omitted, upstream attaches the App to the project's default (production) Branch. `appEndpointDomain` is available at provision — that is what a service's own origin is read from |
70+
| `Prisma.App` | App | project, displayName, regionId, branchId?, logicalId? | appId, appEndpointDomain | `branchId` targets the Branch of an environment other than `production`; omitted, upstream attaches the App to the project's default (production) Branch. `appEndpointDomain` is available at provision — that is what a service's own origin and its published `url` are read from |
7171
| `Prisma.EnvironmentVariable` | ConfigVariable | project, class, key, value (Redacted), branchId? | environmentVariableId | production-class with no `branchId` for `production`; preview-class with `branchId` for any other environment. Values are write-only, so upstream re-applies the desired one on every deploy |
72-
| `Prisma.Deployment` | Deployment (ComputeVersion) + Promotion | app, artifactPath, artifactContentType, portMapping, triggers, start, promote | deploymentId, appEndpointDomain | provider reconcile: create → upload tar.gz → start → poll until running → promote; `appEndpointDomain` read **post-promote** (create-time domain is a placeholder — PRO-200). It is replaced, not updated, when its artifact fingerprint or its `triggers` fingerprint moves |
72+
| `Prisma.Deployment` | Deployment (ComputeVersion) + Promotion | app, artifactPath, artifactContentType, portMapping, triggers, start, promote | deploymentId, appEndpointDomain | provider reconcile: create → upload tar.gz → start → poll until running → promote; `appEndpointDomain` read **post-promote**; it is the same domain the App reports from its create. It is replaced, not updated, when its artifact fingerprint or its `triggers` fingerprint moves |
7373
| `Prisma.Bucket` | Bucket | project, name, branchId?, logicalId? | bucketId, name | one per bucket resource; `Prisma.BucketAccessKey` mints its read-write S3 credentials, which become the node's outputs |
7474

7575
`logicalId` is set on every deploy except branchless local dev; [§ Platform identity](#platform-identity-logicalid) says what it carries.
@@ -178,14 +178,7 @@ logic is untouched.
178178
Management API; the table above is that mapping. One resource maps to one PDP
179179
entity except `Deployment`, which spans version-create + upload + start +
180180
promote (and therefore owns the env-snapshot moment).
181-
- **PDP → ours**: `foundryVersionId`, `Promotion`, and Foundry's version record
182-
have no resource of ours; they are internal to the `Deployment` provider's
183-
behavior or unmodeled. **Branch** likewise has no Alchemy resource — it is
184-
resolved and its lifecycle managed by the CLI's container-resolution
185-
client, outside the Alchemy graph entirely (see
186-
[§ Environments and container resolution](#environments-and-container-resolution)).
187-
`serviceEndpointDomain` surfaces as `App.appEndpointDomain` (before the first
188-
deploy) and `Deployment.appEndpointDomain` (post-promote).
181+
- **PDP → ours**: `foundryVersionId`, `Promotion`, and Foundry's version record have no resource of ours; they are internal to the `Deployment` provider's behavior or unmodeled. **Branch** likewise has no Alchemy resource — it is resolved and its lifecycle managed by the CLI's container-resolution client, outside the Alchemy graph entirely (see [§ Environments and container resolution](#environments-and-container-resolution)). `serviceEndpointDomain` surfaces as `App.appEndpointDomain` and `Deployment.appEndpointDomain`; both are the same domain.
189182

190183
## The lowering graphs
191184

@@ -215,8 +208,9 @@ flowchart TB
215208
Ss[App shop.storefront] --> Ds[Deployment shop.storefront.deployment]
216209
EVa -- resource ref --> Da
217210
EVs -- resource ref --> Ds
218-
Da -- appEndpointDomain --> EVu["EnvironmentVariable(COMPOSER_SHOP_STOREFRONT_AUTH_URL)"]
211+
Sa -- appEndpointDomain --> EVu["EnvironmentVariable(COMPOSER_SHOP_STOREFRONT_AUTH_URL)"]
219212
EVu -- resource ref --> Ds
213+
Da -- "serviceId (after promote)" --> Ds
220214
end
221215
```
222216

@@ -227,12 +221,9 @@ How the pieces map:
227221
- **Each service** lowers to an `App → Deployment` chain plus its own
228222
`Database → Connection`, whose url is written as that service's **explicitly
229223
named** variable — the same `serialize` path as any other config value.
230-
- **The connection** lowers to two edges: the producer's endpoint domain flows
231-
into a named `EnvironmentVariable`, and that **whole resource flows into the
232-
consumer's `Deployment`** through its `app` prop.
233-
- Every `EnvironmentVariable` a Deployment boots with is threaded into its
234-
`app` — database URLs and connection URLs alike — so the deployment
235-
depends on its config being written first.
224+
- **The connection** lowers to two edges: the producer's App's endpoint domain flows into a named `EnvironmentVariable`, and that **whole resource flows into the consumer's `Deployment`** through its `app` prop. The domain comes from the App, not the Deployment: the Deployment is promoted on every deploy, so its domain is unknown while planning, and a consumer's deployment, whose triggers hold the value, would be replaced on every deploy. Because the App's domain is known, an unchanged consumer keeps its deployment when its producer is redeployed.
225+
- Every `EnvironmentVariable` a Deployment boots with is threaded into its `app` — database URLs and connection URLs alike — so the deployment depends on its config being written first.
226+
- Every output of a consumer's producers is threaded into its Deployment's `app` too, so its deployment waits for its producers' promotion: a Compute producer's `serviceId` comes from its Deployment and resolves only after the promotion. The wait is on `app`, not in `triggers`, and upstream treats an unresolved `app` as unchanged, so an unchanged consumer is not replaced.
236227
- The Deployment's `portMapping.http` rides the same seam: `serialize` resolves
237228
the service's `port` param from the typed Config and surfaces it in its
238229
outputs, and `deploy` routes the platform to it — so the routed port and the
@@ -247,25 +238,11 @@ deployment-create, so new and replacement deployments boot with the completed
247238
configuration updates.
248239
Without it the two race — the failure documented as PRO-211 in `gotchas.md`.
249240

250-
**Why the edge rides `app`.** Upstream's `Prisma.Deployment` has no
251-
`environment` prop (Composer's deleted one did). Alchemy derives its dependency
252-
graph from the resource references a prop's *value* is built from, so the
253-
descriptor builds `app` as an Output over the app id AND every whole variable
254-
resource, resolving to the app id itself: the graph gains the edges. A persisted
255-
variable ID can resolve before its pending value update finishes; the whole
256-
resource keeps that update as a dependency. The edge cannot ride
257-
`artifactPath` (or any of upstream's other replacement-block props): the diff
258-
reads that block as one unit and gives no opinion the moment any member is
259-
unresolved — and a brand-new variable's reference IS unresolved at plan time —
260-
which would skip the artifact comparison and silently drop a code change.
261-
`compute/deployment-edge.ts` records the full argument and its test drives
262-
upstream's real diff.
241+
**Why the edge rides `app`.** Upstream's `Prisma.Deployment` has no `environment` prop (Composer's deleted one did). Alchemy derives its dependency graph from the resource references a prop's *value* is built from, so the descriptor builds `app` as an Output over the app id, every whole variable resource and every output of the service's producers, resolving to the app id itself: the graph gains the edges. A persisted variable ID can resolve before its pending value update finishes; the whole resource keeps that update as a dependency. The edge cannot ride `artifactPath` (or any of upstream's other replacement-block props): the diff reads that block as one unit and gives no opinion the moment any member is unresolved — and a brand-new variable's reference IS unresolved at plan time — which would skip the artifact comparison and silently drop a code change. [ADR-0048](../90-decisions/ADR-0048-prisma-cloud-resources-come-from-the-upstream-alchemy-provider.md) records the full argument, and `compute/__tests__/deployment-edge.test.ts` drives upstream's real diff.
263242

264243
**Change propagation is wired through `Prisma.Deployment.triggers`.** The platform freezes a deployment's environment at create, so a *value* change (a rotated URL) reaches a running service only through a new deployment. The compute descriptor declares one trigger member per environment row, carrying the same `Redacted` value the row writes; upstream folds the resolved members into a salted fingerprint inside its own encrypted state and plans a replacement exactly when one moved (and conservatively when a member cannot be resolved at plan time because the producing resource is itself changing). Unchanged service → same fingerprint → reuse; changed value or artifact → replace. Because upstream resolves the actual values, a value re-issued under a stable resource identity (a connection rotated in place, a re-minted service key) moves the fingerprint too. No plaintext lands in state — the members are `Redacted` in props and only the salted hash is persisted. A platform variable a row merely POINTS at (operator-owned; Composer never reads its value) contributes a `<name>:updatedAt` member instead, read at preflight and handed to the lowering in the extension's preflight payload, so an out-of-band rotation still ships a new deployment. A service's input document is not an environment row and has no trigger member: it travels in the service's artifact, in the `inputDocument` field of `compute.bootstrap.json` ([ADR-0065](../90-decisions/ADR-0065-a-compute-services-input-document-travels-in-its-artifact.md)), so a changed document changes the artifact's bytes and its content-addressed `artifactPath`, which replaces the deployment. A platform variable the document names is still a `<name>:updatedAt` member.
265244

266-
The framework's core constructs these edges when lowering a connection (the
267-
`serialize` env-var records thread into `deploy` through the service SPI); no pack
268-
author and no app author ever hand-wires them.
245+
The compute descriptor constructs these edges (the `serialize` env-var records thread into `deploy` through the service SPI, and the producers' outputs come from the lowering context); no app author ever hand-wires them.
269246

270247
## Related
271248

‎docs/design/05-prisma-cloud/pdp-data-model.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ This is the timing model Prisma Composer's graph must respect:
8585
| any time | ConfigVariable rows are created/updated/deleted via the environment-variables API — **rows only; no effect on any existing version** | `routes/v1/environment-variables.ts` |
8686
| **version create** | `materializeBranchEnvVars(app.branchId)` resolves the complete map — production branch → production templates; preview branch → preview templates merged with that branch's overrides (override wins) — decrypts it, and hands the **plain map to Foundry with the version**. The env is **frozen into the version** | `routes/v1/versions.ts` → `resolveDeployEnvVars.ts` → `compute-config/materializeBranchEnvVars.ts` |
8787
| version start | boots the version; **no env re-resolution** | `routes/v1/version-handlers.ts` |
88-
| promote | endpoint routed to the version; `serviceEndpointDomain` persisted. The domain returned at *create* time is a placeholder region — only the post-promote read is trustworthy (PRO-200) | `interactors/compute/service.ts` |
88+
| promote | endpoint routed to the version; `serviceEndpointDomain` persisted. The domain returned at *create* names the domain the service will serve on | `interactors/compute/service.ts` |
8989

9090
Consequences Prisma Composer designs around:
9191

‎docs/design/10-domains/core-model.md‎

Lines changed: 20 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ type Outputs = Readonly<Record<string, unknown>>
670670
// `url` is present only when the descriptor declares the address publicly
671671
// reachable — a connection string is never a `url` (no core-level rule is safe:
672672
// `url` on compute is an endpoint, on postgres it would be a DSN). A descriptor
673-
// constructing one holds `deployment.appEndpointDomain` — an Output<T>, not a T,
673+
// constructing one holds the App's `appEndpointDomain` — an Output<T>, not a T,
674674
// because the stack effect runs before Alchemy applies — so construction sites
675675
// traffic in `Input<DeployedEntity>` (LoweredResult.entities above); apply
676676
// resolves them before any reader sees them.
@@ -766,13 +766,7 @@ module-provisioned **resource** lowers exactly once via its extension's
766766
nodes are edges only and never lower. Then for each service:
767767

768768
1. `provision` — the service now has identity (its App).
769-
2. core **builds the typed `Config`** — each input's declared params matched by
770-
name to its producer's `outputs` through the one `dependency` edge:
771-
whatever the module wired in — a resource's outputs (shared by every consumer
772-
wired to it) or a producer service's deploy outputs (the producer, earlier in
773-
topo order, is already fully deployed — its URL is real, not the create-time
774-
placeholder) — plus service-param defaults. Leaf values are provisioning refs,
775-
not strings.
769+
2. core **builds the typed `Config`** — each input's declared params matched by name to its producer's `outputs` through the one `dependency` edge: whatever the module wired in — a resource's outputs (shared by every consumer wired to it) or a producer service's deploy outputs — plus service-param defaults. Leaf values are provisioning refs, not strings. Core lowers a producer before its consumers, so a consumer's hooks receive the producer's outputs; how a target makes the consumer's deployment wait for its producers is the target's ([Prisma Cloud](../05-prisma-cloud/alchemy-lowering.md#the-lowering-graphs)).
776770
3. `serialize(config)` — the pack encodes that typed Config into the service's
777771
runtime environment (Prisma Cloud: one env write per leaf, keyed by the
778772
pack's own naming from the address, value = the ref; the input document
@@ -784,15 +778,7 @@ nodes are edges only and never lower. Then for each service:
784778
5. `deploy(artifact)` — the first version snapshots an environment that is already
785779
complete.
786780

787-
**How the ordering is actually enforced:** our walk only *assembles* Alchemy
788-
resource descriptions — Alchemy executes them in dependency order and runs
789-
unordered resources concurrently; declaration order is never consulted. So core
790-
realizes the sequence as **dependency edges**: most arise naturally from value flow
791-
(the env var consumes the project id and the producer's URL), and the one that
792-
doesn't — deploy-after-serialize — exists because the service descriptor builds
793-
the `Deployment`'s props out of the environment records it boots with, which is
794-
PDP's own dataflow restored (the deployment-create call literally contains the
795-
materialized env map). See the lowering graphs in
781+
**How the ordering is actually enforced:** our walk only *assembles* Alchemy resource descriptions — Alchemy executes them in dependency order and runs unordered resources concurrently; declaration order is never consulted. So core realizes the sequence as **dependency edges**: most arise naturally from value flow (the env var consumes the project id and the producer's URL), and two do not. Deploy-after-serialize exists because the service descriptor builds the `Deployment`'s props out of the environment records it boots with, which is PDP's own dataflow restored (the deployment-create call literally contains the materialized env map). Deploy-after-producers exists because the service descriptor also builds them out of its producers' outputs, so a consumer's deployment is created after its producers go live. See the lowering graphs in
796782
[`../05-prisma-cloud/alchemy-lowering.md`](../05-prisma-cloud/alchemy-lowering.md).
797783
This is what makes the fresh-deploy config race (PRO-211) structurally impossible
798784
on every target — the edge's **ordering** job. Its second job, **propagating**
@@ -1098,7 +1084,7 @@ export const prismaCloud = (opts: PrismaCloudOptions = {}): ExtensionDescriptor
10981084
const svc = yield* Prisma.App(address, {
10991085
project: projectIdOf(application), displayName: address, regionId: o.region ?? "us-east-1", logicalId: address,
11001086
})
1101-
return { serviceId: svc.appId, projectId: projectIdOf(application) } // : ComputeProvisioned
1087+
return { serviceId: svc.appId, projectId: projectIdOf(application), endpointDomain: svc.appEndpointDomain } // : ComputeProvisioned
11021088
}),
11031089
11041090
// Encode the typed Config into the runtime environment — one env var per
@@ -1133,22 +1119,30 @@ export const prismaCloud = (opts: PrismaCloudOptions = {}): ExtensionDescriptor
11331119
Effect.try(() => Prisma.packageComputeArtifact({ id, bundleDir: assembled.dir, appEntry: assembled.entry, address, inputDocument: serialized.input && JSON.parse(serialized.input.value) })),
11341120
11351121
// create → upload → start → promote. The app id is read through
1136-
// serialize's env-var records, so the deployment depends on them — the
1137-
// ordering edge that kills PRO-211. Returns a LoweredResult: `url` IS
1122+
// serialize's env-var records and every output of its producers, so the
1123+
// deployment is created after its rows are written (PRO-211) and after
1124+
// its producers are promoted. Returns a LoweredResult: `url` IS
11381125
// published here — a Compute service's deployed URL is a public endpoint,
1139-
// and this descriptor is the only party that knows it. Both fields are
1140-
// still Output refs until apply.
1141-
deploy: ({ address }, provisioned, artifact, serialized) =>
1126+
// and this descriptor is the only party that knows it. It is the App's
1127+
// domain, not the deployment's: the deployment is promoted on every
1128+
// deploy, so its domain is unknown while planning, and every service
1129+
// reading the URL would get a new deployment. Both fields are still
1130+
// Output refs until apply.
1131+
deploy: ({ id, address, graph, lowered }, provisioned, artifact, serialized) =>
11421132
Effect.gen(function* () {
1133+
const producerOutputs = graph.edges
1134+
.filter((edge) => edge.kind === "dependency" && edge.to === id)
1135+
.flatMap((edge) => Object.values(lowered.get(edge.from) ?? {}))
1136+
.filter(Output.isOutput)
11431137
const deployment = yield* Prisma.Deployment(`${address}.deployment`, {
1144-
app: appAfterEnvironment(provisioned.serviceId, serialized.environment),
1138+
app: appAfter(provisioned.serviceId, serialized.environment, producerOutputs),
11451139
artifactPath: artifact.path,
11461140
artifactContentType: "application/gzip",
11471141
portMapping: { http: serialized.port }, start: true, promote: true,
11481142
})
11491143
return {
1150-
outputs: { url: deployment.appEndpointDomain, projectId: provisioned.projectId },
1151-
entities: [{ kind: "compute-service", id: provisioned.serviceId, url: deployment.appEndpointDomain }],
1144+
outputs: { url: provisioned.endpointDomain, projectId: provisioned.projectId, serviceId: deployment.appId },
1145+
entities: [{ kind: "compute-service", id: provisioned.serviceId, url: provisioned.endpointDomain }],
11521146
}
11531147
}),
11541148
},

0 commit comments

Comments
 (0)