Skip to content
Merged
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
17 changes: 10 additions & 7 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -203,19 +203,22 @@ If `--project` is provided, purges that project's cache instead of the linked pr
### `void deploy`

```
void deploy [--project <name>] [--dir <path>] [--spa] [--skip-build]
void deploy [--project <name>] [--dir <path>] [--spa] [--skip-build] [--debug]
```

Auto-detects your project type and chooses the right pipeline. See [Supported App Types](../guide/app-types.md) and [Deployment](../guide/deployment.md) for details.

For Drizzle projects, deploy performs a read-only schema drift check. If a new migration would be generated, deploy stops and tells you to run `void db generate`, review the migration, commit it yourself, and rerun `void deploy`.

| Flag | Purpose |
| ------------------ | ------------------------------------------------- |
| `--project <name>` | Target a specific project by slug |
| `--dir <path>` | Deploy a pre-built static directory (skips build) |
| `--spa` | Use SPA mode instead of SSG for static deploys |
| `--skip-build` | Skip the build step (use existing build output) |
| Flag | Purpose |
| ------------------ | ---------------------------------------------------------------------------- |
| `--project <name>` | Target a specific project by slug |
| `--dir <path>` | Deploy a pre-built static directory (skips build) |
| `--spa` | Use SPA mode instead of SSG for static deploys |
| `--skip-build` | Skip the build step (use existing build output) |
| `--debug` | Mirror the structured deploy log to stderr (also written to `~/.void/logs/`) |

Every deploy writes a structured JSONL trace to `~/.void/logs/deploy-<timestamp>.jsonl` regardless of `--debug`. On failure the path is printed at the end of the error message so you can attach it when reporting platform issues. `VOID_DEPLOY_DEBUG=1` is accepted as an alternate trigger for stderr mirroring.

Project resolution precedence:

Expand Down
5 changes: 4 additions & 1 deletion packages/void/src/cli/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export interface DeployArgs {
dir?: string;
spa?: boolean;
skipBuild?: boolean;
debug?: boolean;
}

export function parseDeployArgs(args: Array<string>): DeployArgs {
Expand All @@ -17,6 +18,7 @@ export function parseDeployArgs(args: Array<string>): DeployArgs {
dir: { type: 'string' },
spa: { type: 'boolean' },
'skip-build': { type: 'boolean' },
debug: { type: 'boolean' },
},
allowPositionals: true,
strict: true,
Expand Down Expand Up @@ -58,6 +60,7 @@ export function parseDeployArgs(args: Array<string>): DeployArgs {
const dir = typeof parsed.values.dir === 'string' ? parsed.values.dir : undefined;
const spa = parsed.values.spa === true ? true : undefined;
const skipBuild = parsed.values['skip-build'] === true ? true : undefined;
const debug = parsed.values.debug === true ? true : undefined;

return { projectSlug, dir, spa, skipBuild };
return { projectSlug, dir, spa, skipBuild, debug };
}
1 change: 1 addition & 0 deletions packages/void/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ if (helpPath) {
dir: deployArgs.dir,
spa: deployArgs.spa,
skipBuild: deployArgs.skipBuild,
debug: deployArgs.debug,
}).catch((err) => {
log.error(err.message ?? err);
process.exit(1);
Expand Down
100 changes: 80 additions & 20 deletions packages/void/src/cli/client.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { cfAccessHeaders } from '../shared/cf-access.ts';
import { getApiUrl } from './auth.ts';
import { ensureCloudflaredToken } from './cf-access.ts';
import type { CliLogger } from './log-file.ts';
import type { DeployEvent } from './types.ts';

export type PlatformErrorPayload = {
Expand Down Expand Up @@ -122,12 +123,17 @@ export interface DomainStatusResponse extends DomainResponse {
export class PlatformClient {
private baseUrl: string;
private authHeaders: Record<string, string>;
private cliLog?: CliLogger;

constructor(token: string, options?: string | { apiUrl?: string; root?: string }) {
constructor(
token: string,
options?: string | { apiUrl?: string; root?: string; cliLog?: CliLogger },
) {
if (typeof options === 'string') {
this.baseUrl = options;
} else {
this.baseUrl = options?.apiUrl ?? getApiUrl(options?.root);
this.cliLog = options?.cliLog;
}
ensureCloudflaredToken(this.baseUrl);
this.authHeaders = {
Expand Down Expand Up @@ -282,12 +288,34 @@ export class PlatformClient {
}

async *deploy(projectId: string, formData: FormData): AsyncGenerator<DeployEvent> {
const res = await fetch(`${this.baseUrl}/projects/${projectId}/deploy`, {
method: 'POST',
headers: {
...this.authHeaders,
},
body: formData,
const cliLog = this.cliLog;
const url = `${this.baseUrl}/projects/${projectId}/deploy`;
cliLog?.info('deploy_post', { url });

let res: Response;
try {
res = await fetch(url, {
method: 'POST',
headers: {
...this.authHeaders,
},
body: formData,
});
} catch (err) {
cliLog?.error('deploy_fetch_rejected', err, { url });
throw err;
}

// `cf-ray` and `cf-cache-status` are the correlation keys that platform
// engineers need to look up server-side tail logs. Capture them whenever
// the response makes it back.
const cfRay = res.headers.get('cf-ray');
const cfCacheStatus = res.headers.get('cf-cache-status');
cliLog?.info('deploy_response', {
status: res.status,
cfRay,
cfCacheStatus,
contentType: res.headers.get('content-type'),
});

if (!res.ok) {
Expand All @@ -297,22 +325,54 @@ export class PlatformClient {
const reader = res.body!.getReader();
const decoder = new TextDecoder();
let buffer = '';
let bytesRead = 0;
let firstByteAt: number | null = null;
const startedAt = Date.now();
let eventCount = 0;
let lastEventName = '<none>';

while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
buffer += decoder.decode(value, { stream: true });

let newlineIdx;
while ((newlineIdx = buffer.indexOf('\n')) !== -1) {
const line = buffer.slice(0, newlineIdx);
buffer = buffer.slice(newlineIdx + 1);
if (line.trim()) {
yield JSON.parse(line) as DeployEvent;
try {
while (true) {
const { done, value } = await reader.read();
if (done) {
cliLog?.info('deploy_stream_eof', {
bytesRead,
eventCount,
lastEvent: lastEventName,
});
break;
}
if (firstByteAt === null) {
firstByteAt = Date.now() - startedAt;
cliLog?.info('deploy_stream_ttfb', { ttfbMs: firstByteAt });
}
bytesRead += value.byteLength;
buffer += decoder.decode(value, { stream: true });

let newlineIdx;
while ((newlineIdx = buffer.indexOf('\n')) !== -1) {
const line = buffer.slice(0, newlineIdx);
buffer = buffer.slice(newlineIdx + 1);
if (line.trim()) {
const event = JSON.parse(line) as DeployEvent;
eventCount++;
lastEventName = (event as { event?: string }).event ?? '<no-event-field>';
cliLog?.info('deploy_event', {
eventCount,
event: lastEventName,
raw: line.slice(0, 200),
});
yield event;
}
}
}
} catch (err) {
cliLog?.error('deploy_stream_error', err, {
bytesRead,
eventCount,
lastEvent: lastEventName,
});
throw err;
}
}

Expand Down
47 changes: 39 additions & 8 deletions packages/void/src/cli/deploy-errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,27 @@ function appendDeploymentLine(message: string, deploymentId: string | null): str
return deploymentId ? `${message}\nDeployment: ${deploymentId}` : message;
}

function appendLogLine(message: string, logPath: string | null | undefined): string {
return logPath ? `${message}\nDetailed log: ${logPath}` : message;
}

function appendTrailingLines(
message: string,
deploymentId: string | null,
logPath: string | null | undefined,
): string {
return appendLogLine(appendDeploymentLine(message, deploymentId), logPath);
}

/**
* Format a server-emitted `event: 'error'` payload with an optional deployment id.
*/
export function formatDeployFailureMessage(message: string, deploymentId: string | null): string {
return appendDeploymentLine(message, deploymentId);
export function formatDeployFailureMessage(
message: string,
deploymentId: string | null,
logPath?: string | null,
): string {
return appendTrailingLines(message, deploymentId, logPath);
}

/**
Expand All @@ -28,8 +44,11 @@ export function formatDeployFailureMessage(message: string, deploymentId: string
* deploy" message — the server closed the NDJSON stream without emitting
* `done` or `error`, so there is no underlying error to carry.
*/
export function formatConnectionLostMessage(deploymentId: string | null): string {
return appendDeploymentLine('deploy: Connection lost during deploy.', deploymentId);
export function formatConnectionLostMessage(
deploymentId: string | null,
logPath?: string | null,
): string {
return appendTrailingLines('deploy: Connection lost during deploy.', deploymentId, logPath);
}

/**
Expand All @@ -45,7 +64,11 @@ export function formatConnectionLostMessage(deploymentId: string | null): string
* during deploy: <original>` prefix so the caller can still tell network,
* parse, and transport errors apart.
*/
export function formatStreamDeployError(err: unknown, deploymentId: string | null): Error {
export function formatStreamDeployError(
err: unknown,
deploymentId: string | null,
logPath?: string | null,
): Error {
if (err instanceof PlatformApiError) {
const parsed = parsePlatformErrorBody(err.body);
const parsedError = parsed?.error ?? parsed?.message ?? null;
Expand All @@ -54,19 +77,27 @@ export function formatStreamDeployError(err: unknown, deploymentId: string | nul

if (err.status === 409 && parsedError) {
return new Error(
appendDeploymentLine(`deploy: Deploy failed: ${parsedError}`, effectiveDeploymentId),
appendTrailingLines(
`deploy: Deploy failed: ${parsedError}`,
effectiveDeploymentId,
logPath,
),
);
}

const detail = parsedError ?? trimSnippet(err.body);
const base = detail
? `deploy: Deploy failed (HTTP ${err.status}): ${detail}`
: `deploy: Deploy failed (HTTP ${err.status}).`;
return new Error(appendDeploymentLine(base, effectiveDeploymentId));
return new Error(appendTrailingLines(base, effectiveDeploymentId, logPath));
}

const original = err instanceof Error ? err.message : String(err);
return new Error(
appendDeploymentLine(`deploy: Connection lost during deploy: '${original}'.`, deploymentId),
appendTrailingLines(
`deploy: Connection lost during deploy: '${original}'.`,
deploymentId,
logPath,
),
);
}
Loading