Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions docs/product/command-principles.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,26 @@ No current branch command uses `use`; branch targeting follows explicit flags or

Build and release an app into a target branch.

`deploy` has two paths, and the repository decides which one runs:

- **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.
- **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.

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`.

A single-app deploy works like this:

- **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.
- **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.
- **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.
- **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.
- **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.
- **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.
- **Environment variables.** The platform gives a new version the project's variables for the Branch's scope. `deploy` sends none of its own.
- **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.

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.

### `init`

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.
Expand Down
30 changes: 29 additions & 1 deletion docs/reference/error-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Namespaces:
| `BUCKET` | Bucket and bucket-key management (`prisma bucket`) |
| `CLI` | Engine-level invocation: arguments, config loading, prompts, consent, credentials, child processes |
| `CONFIG` | The `composer` section of `prisma.config.ts` and its `config` and `secrets` adapters (`prisma dev`, `prisma deploy`) |
| `DEPLOY` | Deploying, listing and destroying a Composer app (`prisma deploy`, `prisma deploy list`, and the `deploy` and `destroy` operations of `@prisma/composer/control`) |
| `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_` |
| `DEV` | Running an app on this machine with Composer (`prisma dev`, `prisma dev url`, `prisma dev stop`, `prisma emulator list`) |
| `FEEDBACK` | Sending product feedback (`prisma feedback`) |
| `GIT` | Git repository connections (`prisma git`) |
Expand Down Expand Up @@ -320,6 +320,34 @@ These codes come from Composer, the command family behind `prisma deploy`, `pris

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.

### DEPLOY.APP_BUILD_FAILED

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`.

### DEPLOY.APP_EXITED

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`).

### DEPLOY.APP_INSTALL_FAILED

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`.

### DEPLOY.APP_NO_START

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.

### DEPLOY.APP_PORT_MISMATCH

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`).

### DEPLOY.APP_SILENT

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`).

### DEPLOY.APP_USAGE_ERROR

`--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.

### DEPLOY.BUILD_REQUIRED

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.
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ This package exposes `prisma-cli` so it can coexist with the existing
| `postgres` | Create, inspect, back up, restore, and delete Prisma Postgres databases and their connections. |
| `bucket` | Create, list, and delete object-store buckets and their access keys. |
| `service` | Inspect services: versions, logs, domains, promote, roll back, delete. |
| `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. |
| `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. |
| `emulator` | List the local emulators `prisma dev` runs services, databases and buckets on. |
| `contract`, `db`, `migration`, `orm init`, `lsp` | The Prisma ORM workflow. |

Expand Down
86 changes: 86 additions & 0 deletions packages/cli/e2e/deploy.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* `deploy` in a repository with no Composer config: a single-app deploy.
* The app is one file with a `start` script and no dependencies, so the
* run needs no package manager and builds nothing.
*/
import { writeFile } from "node:fs/promises";
import path from "node:path";
import { expect, it } from "vitest";

import { useScratchProject } from "./scratch";
import { describeCommand, session } from "./suite";

const scratch = useScratchProject("deploy");

const SERVER =
'require("node:http").createServer((_, response) => response.end("single-app e2e")).listen(process.env.PORT);\n';

interface DeployResult {
readonly app: string;
readonly project: { readonly id: string };
readonly branch: { readonly production: boolean };
readonly service: { readonly id: string; readonly name: string };
readonly settings: {
readonly start: { readonly value: string; readonly from: string } | null;
};
readonly versionId: string;
readonly url: string;
readonly start: { readonly state: string; readonly port?: number };
readonly promoted: boolean;
}

/** A new deployment's URL can take a moment to route. */
async function fetchText(url: string): Promise<string> {
let last = "";
for (let attempt = 0; attempt < 15; attempt += 1) {
// biome-ignore lint/performance/noAwaitInLoops: each attempt waits for the one before it.
const response = await fetch(url).catch(() => undefined);
if (response?.ok) {
return response.text();
}
last = response === undefined ? "no response" : `HTTP ${response.status}`;
await new Promise((resolve) => setTimeout(resolve, 2000));
}
throw new Error(`${url} did not answer: ${last}`);
}

describeCommand("deploy", () => {
it("deploys an app that has no Composer config, from its own start script", async () => {
const cli = await session();
const app = await cli.workdir();
await writeFile(
path.join(app, "package.json"),
JSON.stringify({
name: "@e2e/web",
private: true,
scripts: { start: "node server.js" },
}),
);
await writeFile(path.join(app, "server.js"), SERVER);

const run = await cli.run(["deploy", "--project", scratch.project().id], {
cwd: app,
timeoutMs: 170_000,
});
const result = run.envelope.result as DeployResult;

expect(result.app).toBe("web");
expect(result.project.id).toBe(scratch.project().id);
expect(result.branch.production).toBe(true);
expect(result.settings.start).toEqual({
value: "node server.js",
from: "package.json",
});
expect(result.start).toEqual({ state: "listening", port: 8080 });
expect(result.promoted).toBe(true);
expect(await fetchText(result.url)).toBe("single-app e2e");

const shown = await scratch.run(["service", "show", result.service.id]);
const service = shown.envelope.result as {
readonly service: { readonly name: string };
readonly liveDeployment?: { readonly id: string } | null;
};
expect(service.service.name).toBe("web");
expect(JSON.stringify(shown.envelope.result)).toContain(result.versionId);
});
});
31 changes: 28 additions & 3 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ import { bucketKeyCreateCommand } from "./commands/bucket/key-create";
import { bucketKeyDeleteCommand } from "./commands/bucket/key-delete";
import { bucketKeyListCommand } from "./commands/bucket/key-list";
import { bucketListCommand } from "./commands/bucket/list";
import { createDeployCommand } from "./commands/deploy/command";
import {
appConfigSection,
deployConfigSection,
} from "./commands/deploy/config";
import { feedbackCommand } from "./commands/feedback";
import { gitConnectCommand } from "./commands/git/connect";
import { gitDisconnectCommand } from "./commands/git/disconnect";
Expand Down Expand Up @@ -72,6 +77,9 @@ import { getCliVersion } from "./lib/version";
import { v7CommandFamily } from "./v7-redirects";

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

/**
* `deploy` is the shell's own command: Composer's deploy when the
* repository has a Composer config, a single-app deploy otherwise. It is
* a family of its own because it reads the `composer` section through a
* validator that accepts a missing section.
*/
export const deployCommand = createDeployCommand(
composerCommandFamily.commands.deploy,
);
export const deployCommandFamily: CommandFamily = defineCommandFamily({
configSection: deployConfigSection,
docsBaseUrl: DOCS_ERRORS_BASE_URL,
commands: { deploy: deployCommand },
});

/**
* The ORM commands, contributed by orm-toolchain's own package, mounted
* as shipped: the family keys are the mount paths, so the shell adds
Expand Down Expand Up @@ -426,9 +449,10 @@ export const mountedCommands: Readonly<Record<string, AnyCommand>> = {
"service domain delete": serviceDomainDeleteCommand,
"service domain retry": serviceDomainRetryCommand,
"service domain wait": serviceDomainWaitCommand,
// Composer's product verbs: deploy and dev at the root, their
// children beneath them, and the local emulators under their own group.
deploy: composerCommandFamily.commands.deploy,
// `deploy` chooses between Composer's deploy and a single-app deploy.
// Composer's other verbs mount as shipped: deploy list, dev and its
// children, and the local emulators under their own group.
deploy: deployCommand,
"deploy list": composerCommandFamily.commands["deploy list"],
dev: composerCommandFamily.commands.dev,
"dev url": composerCommandFamily.commands["dev url"],
Expand Down Expand Up @@ -478,6 +502,7 @@ export function buildCli(): Cli {
commandFamilies: [
platformCommandFamily,
composerCommandFamily,
deployCommandFamily,
ormCommandFamily,
skillsCommandFamily,
v7CommandFamily,
Expand Down
Loading
Loading