Skip to content

Commit a2f60ee

Browse files
kristof-siketclaude
andcommitted
feat(deploy): deploy a repository that has no Composer config
`prisma deploy` now has two paths. A repository whose prisma.config.ts declares a `composer` section takes Composer's deploy, unchanged. Composer's own section validator decides whether the section is missing. Every other repository takes a single-app deploy. It deploys the one app in the current folder from the repository's own install, build and start commands. The rules and the deploy come from `@prisma/compute-sdk/app` (prisma/project-compute#202). The CLI adds no framework rules. - The App config is the `app` section of prisma.config.ts: install, build, start, static and port. `prisma/config` types it. - The project is the linked project or `--project`. `--environment` names the Branch. `--name` names the service; the default is the `name` in package.json, else the folder name. - The version is promoted only when the app listens. A failed install or build, a missing start, and an app that exits or opens no port each fail the deploy with a `DEPLOY.APP_*` error. - The end-to-end suite now covers `deploy` through the single-app path. `@prisma/compute-sdk/app` is not published yet, so the pinned version in package.json does not have it. `pnpm typecheck`, the builds and the tests fail on the pinned version until project-compute#202 is released and the pin is raised. They pass against the build of that pull request. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
1 parent 619abb4 commit a2f60ee

18 files changed

Lines changed: 2020 additions & 16 deletions

File tree

‎docs/product/command-principles.md‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,26 @@ No current branch command uses `use`; branch targeting follows explicit flags or
9393

9494
Build and release an app into a target branch.
9595

96+
`deploy` has two paths, and the repository decides which one runs:
97+
98+
- **Composer deploy.** A loaded `prisma.config.ts` declares a `composer` section. Composer's own `deploy` command runs, unchanged. The test is Composer's own: its section validator decides whether the section is missing.
99+
- **Single-app deploy.** No loaded `prisma.config.ts` declares a `composer` section. The CLI deploys the one app in the current folder from the repository's own install, build and start commands. It holds no framework rules.
100+
101+
A repository that shows another sign of a Composer app still takes the Composer path, and fails with Composer's `CONFIG.SECTION_MISSING` error: `--entry` names a file that exists, or a `prisma-composer.config.*` file is present. A single-app deploy ignores an `--entry` that names no file, because prisma/cloud-deploy-action always passes `--entry module.ts`.
102+
103+
A single-app deploy works like this:
104+
105+
- **Build settings.** Install, Build, Start or Static folder, and Port. Each has a Source: `prisma.config.ts`, `package.json`, the lockfile, the build output, an entry file, or a default. The rules live in `@prisma/compute-sdk/app`; the CLI calls `resolveBuildSettings`, `buildApp` and `deployApp` and adds none of its own.
106+
- **App config.** The `app` section of `prisma.config.ts`: `install`, `build`, `start`, `static`, `port`. Every field is optional and replaces the rule for that setting. An unknown field is an error.
107+
- **Project.** The project the directory is linked to, or `--project`. It is resolved the way the `service` commands resolve it. A single-app deploy never creates a project.
108+
- **Branch.** `--environment production` (the default) is the project's default Branch. Any other name is the Branch with that git name, created when it does not exist.
109+
- **Service.** Named by `--name`, else the `name` in `package.json` without its scope, else the folder name. The service on the Branch with that name is reused; otherwise one is created.
110+
- **Start check.** The app is started on Prisma Cloud before it gets traffic. The version is promoted only when the app listens on the routed port. When the app listens on another port and no port was stated, the deploy runs once more with that port. An app that exits, or opens no port within 60 seconds, fails the deploy and leaves the live version unchanged.
111+
- **Environment variables.** The platform gives a new version the project's variables for the Branch's scope. `deploy` sends none of its own.
112+
- **Exit code.** Every failure is a structured error and exits non-zero: a failed install or build, no start command, a failed start, a failed API call.
113+
114+
Human output is a card with the target and the Build settings, one line per finished step, then the URL. On stdout, a single-app deploy writes the same data line as a Composer deploy: the service name, `compute-service`, the service id and the URL, separated by tabs.
115+
96116
### `init`
97117

98118
Prepare the current repository for Prisma development, entirely locally: add the `postinstall` script that keeps the Prisma agent skills in sync (`prisma skills sync || exit 0`), add `prisma` to `devDependencies` at the CLI's exact version when no dependency field declares it, scaffold a `prisma.config.ts` recording which agents get skills, then sync the skills once now.

‎docs/reference/error-reference.md‎

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Namespaces:
2020
| `BUCKET` | Bucket and bucket-key management (`prisma bucket`) |
2121
| `CLI` | Engine-level invocation: arguments, config loading, prompts, consent, credentials, child processes |
2222
| `CONFIG` | The `composer` section of `prisma.config.ts` and its `config` and `secrets` adapters (`prisma dev`, `prisma deploy`) |
23-
| `DEPLOY` | Deploying, listing and destroying a Composer app (`prisma deploy`, `prisma deploy list`, and the `deploy` and `destroy` operations of `@prisma/composer/control`) |
23+
| `DEPLOY` | Deploying, listing and destroying a Composer app (`prisma deploy`, `prisma deploy list`, and the `deploy` and `destroy` operations of `@prisma/composer/control`), and a single-app deploy (`prisma deploy` in a repository with no Composer config), whose codes start with `DEPLOY.APP_` |
2424
| `DEV` | Running an app on this machine with Composer (`prisma dev`, `prisma dev url`, `prisma dev stop`, `prisma emulator list`) |
2525
| `FEEDBACK` | Sending product feedback (`prisma feedback`) |
2626
| `GIT` | Git repository connections (`prisma git`) |
@@ -320,6 +320,34 @@ These codes come from Composer, the command family behind `prisma deploy`, `pris
320320

321321
Composer starts the deploy engine from the `alchemy` package installed beside `@prisma/composer`, and either `@prisma/composer` itself could not be resolved from the app, or no runnable engine entry could be resolved beside it. Layouts without a `node_modules` directory, such as Yarn Plug'n'Play, are not supported. The fix is to check that the app depends on `@prisma/composer` and to reinstall dependencies so `@prisma/composer` and its `alchemy` dependency sit in a `node_modules` directory. Meta: none.
322322

323+
### DEPLOY.APP_BUILD_FAILED
324+
325+
A single-app deploy ran the app's build command and it exited with an error. Nothing was uploaded. The end of the command's output is printed before the error (in `--json` mode, as `output` events with `source: "build"`). The fix is to run the build command in the app folder and fix what it reports, or to set `build` in the `app` section of `prisma.config.ts`. Meta: `command`, `seconds`.
326+
327+
### DEPLOY.APP_EXITED
328+
329+
A single-app deploy uploaded a version and started it, and the app exited. The version was not promoted, so the version that serves traffic did not change. The app's own output is printed before the error (in `--json` mode, as `output` events with `source: "app"`), and `meta.start.output` carries it. A common cause is an environment variable the app needs: set it with `prisma project env add`, then deploy again. Meta: `serviceId`, `versionId`, `url` (the version's own URL), `port`, `start` (`state`, `code`, `output`).
330+
331+
### DEPLOY.APP_INSTALL_FAILED
332+
333+
A single-app deploy ran the app's install command and it exited with an error. Nothing was built or uploaded. The end of the command's output is printed before the error (in `--json` mode, as `output` events with `source: "install"`). The fix is to run the install command in the app folder and fix what it reports, or to set `install` in the `app` section of `prisma.config.ts`. Meta: `command`, `seconds`.
334+
335+
### DEPLOY.APP_NO_START
336+
337+
A single-app deploy found no way to start the app, so nothing was uploaded. No rule matched: the `start` script is missing or runs a development server, the build wrote no server file and no static site, and the folder holds no entry file such as `index.ts`. The fix is to add a `start` script to `package.json`, or to set `start` (a command) or `static` (a folder of static files) in the `app` section of `prisma.config.ts`. Meta: none.
338+
339+
### DEPLOY.APP_PORT_MISMATCH
340+
341+
A single-app deploy started the app, and the app listens on another port than the one requests are sent to. The version was not promoted. This happens when `port` in the `app` section names a port the app does not use, or when the app picks a different port on each start. The fix is to set `port` to the port the app listens on, or to make the app listen on the port in the `PORT` environment variable. Meta: `serviceId`, `versionId`, `url`, `port` (the routed port), `start` (`state`, `port`).
342+
343+
### DEPLOY.APP_SILENT
344+
345+
A single-app deploy started the app, and the app neither opened a port nor exited within 60 seconds. The version was not promoted. The app's output so far is printed before the error. The fix is to make the app listen on the port in the `PORT` environment variable. Meta: `serviceId`, `versionId`, `url`, `port`, `start` (`state`, `output`).
346+
347+
### DEPLOY.APP_USAGE_ERROR
348+
349+
`--project` was passed to a deploy of a Prisma Composer app. The flag names the Project of a single-app deploy only; a Composer app is deployed into the project named after the app, so the flag is refused instead of ignored. The fix is to remove `--project`, or to pass `--name` to deploy the app under another name. Meta: none.
350+
323351
### DEPLOY.BUILD_REQUIRED
324352

325353
Assembling a service failed during a destroy. Destroy evaluates the same stack program as deploy, which packages the built artifacts, so an app must be built before it can be torn down. The fix is to run the build, then retry the destroy. The underlying assemble error rides as the cause.

‎packages/cli/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ This package exposes `prisma-cli` so it can coexist with the existing
7777
| `postgres` | Create, inspect, back up, restore, and delete Prisma Postgres databases and their connections. |
7878
| `bucket` | Create, list, and delete object-store buckets and their access keys. |
7979
| `service` | Inspect services: versions, logs, domains, promote, roll back, delete. |
80-
| `dev`, `deploy` | Run a Composer app locally; deploy it to the platform. `dev url` prints a running node's local URL and `dev stop` stops the app. |
80+
| `dev`, `deploy` | Run a Composer app locally; deploy it to the platform. `dev url` prints a running node's local URL and `dev stop` stops the app. In a repository with no Composer config, `deploy` deploys the one app in the folder from its own install, build and start commands. |
8181
| `emulator` | List the local emulators `prisma dev` runs services, databases and buckets on. |
8282
| `contract`, `db`, `migration`, `orm init`, `lsp` | The Prisma ORM workflow. |
8383

‎packages/cli/e2e/deploy.e2e.ts‎

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/**
2+
* `deploy` in a repository with no Composer config: a single-app deploy.
3+
* The app is one file with a `start` script and no dependencies, so the
4+
* run needs no package manager and builds nothing.
5+
*/
6+
import { writeFile } from "node:fs/promises";
7+
import path from "node:path";
8+
import { expect, it } from "vitest";
9+
10+
import { useScratchProject } from "./scratch";
11+
import { describeCommand, session } from "./suite";
12+
13+
const scratch = useScratchProject("deploy");
14+
15+
const SERVER =
16+
'require("node:http").createServer((_, response) => response.end("single-app e2e")).listen(process.env.PORT);\n';
17+
18+
interface DeployResult {
19+
readonly app: string;
20+
readonly project: { readonly id: string };
21+
readonly branch: { readonly production: boolean };
22+
readonly service: { readonly id: string; readonly name: string };
23+
readonly settings: {
24+
readonly start: { readonly value: string; readonly from: string } | null;
25+
};
26+
readonly versionId: string;
27+
readonly url: string;
28+
readonly start: { readonly state: string; readonly port?: number };
29+
readonly promoted: boolean;
30+
}
31+
32+
/** A new deployment's URL can take a moment to route. */
33+
async function fetchText(url: string): Promise<string> {
34+
let last = "";
35+
for (let attempt = 0; attempt < 15; attempt += 1) {
36+
// biome-ignore lint/performance/noAwaitInLoops: each attempt waits for the one before it.
37+
const response = await fetch(url).catch(() => undefined);
38+
if (response?.ok) {
39+
return response.text();
40+
}
41+
last = response === undefined ? "no response" : `HTTP ${response.status}`;
42+
await new Promise((resolve) => setTimeout(resolve, 2000));
43+
}
44+
throw new Error(`${url} did not answer: ${last}`);
45+
}
46+
47+
describeCommand("deploy", () => {
48+
it("deploys an app that has no Composer config, from its own start script", async () => {
49+
const cli = await session();
50+
const app = await cli.workdir();
51+
await writeFile(
52+
path.join(app, "package.json"),
53+
JSON.stringify({
54+
name: "@e2e/web",
55+
private: true,
56+
scripts: { start: "node server.js" },
57+
}),
58+
);
59+
await writeFile(path.join(app, "server.js"), SERVER);
60+
61+
const run = await cli.run(["deploy", "--project", scratch.project().id], {
62+
cwd: app,
63+
timeoutMs: 170_000,
64+
});
65+
const result = run.envelope.result as DeployResult;
66+
67+
expect(result.app).toBe("web");
68+
expect(result.project.id).toBe(scratch.project().id);
69+
expect(result.branch.production).toBe(true);
70+
expect(result.settings.start).toEqual({
71+
value: "node server.js",
72+
from: "package.json",
73+
});
74+
expect(result.start).toEqual({ state: "listening", port: 8080 });
75+
expect(result.promoted).toBe(true);
76+
expect(await fetchText(result.url)).toBe("single-app e2e");
77+
78+
const shown = await scratch.run(["service", "show", result.service.id]);
79+
const service = shown.envelope.result as {
80+
readonly service: { readonly name: string };
81+
readonly liveDeployment?: { readonly id: string } | null;
82+
};
83+
expect(service.service.name).toBe("web");
84+
expect(JSON.stringify(shown.envelope.result)).toContain(result.versionId);
85+
});
86+
});

‎packages/cli/src/cli.ts‎

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ import { bucketKeyCreateCommand } from "./commands/bucket/key-create";
2323
import { bucketKeyDeleteCommand } from "./commands/bucket/key-delete";
2424
import { bucketKeyListCommand } from "./commands/bucket/key-list";
2525
import { bucketListCommand } from "./commands/bucket/list";
26+
import { createDeployCommand } from "./commands/deploy/command";
27+
import {
28+
appConfigSection,
29+
deployConfigSection,
30+
} from "./commands/deploy/config";
2631
import { feedbackCommand } from "./commands/feedback";
2732
import { gitConnectCommand } from "./commands/git/connect";
2833
import { gitDisconnectCommand } from "./commands/git/disconnect";
@@ -72,6 +77,9 @@ import { getCliVersion } from "./lib/version";
7277
import { v7CommandFamily } from "./v7-redirects";
7378

7479
export const platformCommandFamily: CommandFamily = defineCommandFamily({
80+
// The `app` section holds the App config of a single-app deploy. `deploy`
81+
// reads it; it is declared here so prisma.config.ts may carry it.
82+
configSection: appConfigSection,
7583
docsBaseUrl: DOCS_ERRORS_BASE_URL,
7684
commands: {
7785
login: authLoginCommand,
@@ -141,6 +149,21 @@ export const platformCommandFamily: CommandFamily = defineCommandFamily({
141149
*/
142150
export const composerCommandFamily: CommandFamily = createComposerFamily();
143151

152+
/**
153+
* `deploy` is the shell's own command: Composer's deploy when the
154+
* repository has a Composer config, a single-app deploy otherwise. It is
155+
* a family of its own because it reads the `composer` section through a
156+
* validator that accepts a missing section.
157+
*/
158+
export const deployCommand = createDeployCommand(
159+
composerCommandFamily.commands.deploy,
160+
);
161+
export const deployCommandFamily: CommandFamily = defineCommandFamily({
162+
configSection: deployConfigSection,
163+
docsBaseUrl: DOCS_ERRORS_BASE_URL,
164+
commands: { deploy: deployCommand },
165+
});
166+
144167
/**
145168
* The ORM commands, contributed by orm-toolchain's own package, mounted
146169
* as shipped: the family keys are the mount paths, so the shell adds
@@ -426,9 +449,10 @@ export const mountedCommands: Readonly<Record<string, AnyCommand>> = {
426449
"service domain delete": serviceDomainDeleteCommand,
427450
"service domain retry": serviceDomainRetryCommand,
428451
"service domain wait": serviceDomainWaitCommand,
429-
// Composer's product verbs: deploy and dev at the root, their
430-
// children beneath them, and the local emulators under their own group.
431-
deploy: composerCommandFamily.commands.deploy,
452+
// `deploy` chooses between Composer's deploy and a single-app deploy.
453+
// Composer's other verbs mount as shipped: deploy list, dev and its
454+
// children, and the local emulators under their own group.
455+
deploy: deployCommand,
432456
"deploy list": composerCommandFamily.commands["deploy list"],
433457
dev: composerCommandFamily.commands.dev,
434458
"dev url": composerCommandFamily.commands["dev url"],
@@ -478,6 +502,7 @@ export function buildCli(): Cli {
478502
commandFamilies: [
479503
platformCommandFamily,
480504
composerCommandFamily,
505+
deployCommandFamily,
481506
ormCommandFamily,
482507
skillsCommandFamily,
483508
v7CommandFamily,

0 commit comments

Comments
 (0)