Files
supabase/apps/studio/components/interfaces/Compute/DeployComputeInstanceDialog.tsx
Ali WaseemandClaude Opus 5.5 e5aecf2931 fix(studio): make compute deploy snippets match the CLI (#53467)
## Problem

Following the Compute "copy as AI prompt" snippet word for word fails
against the current CLI (3.2.0):

1. `size = "2gb-1vcpu"` → `UnknownComputeSizeError`. config.toml takes
`2gb` / `4gb`; the CLI maps those to the API's `2gb-1vcpu` itself
(`apiSizeFor` in `apps/cli/src/shared/compute/compute-runtimes.ts`).
2. Nothing says to enable `[experimental] compute = true` /
`SUPABASE_EXPERIMENTAL_COMPUTE=1`, so the CLI fails with `Unknown
subcommand "compute"`. SupaSquad testers have hit the same error.
3. For the Dockerfile runtime the prompt read "a Dockerfile entrypoint
(Dockerfile)" and never mentioned the port.
5. Every prompt asked for an HTTP "Hello, world!" server, including
private instances. Private exposure has no inbound network access: a
private instance is a background worker (for example, a loop polling a
pgmq queue) and doesn't listen on any port. Deploying an HTTP server as
private is what produced the `listen tcp :8080: bind: address already in
use` error I hit. The call snippets also sent an `Authorization` header,
but public instances don't verify API keys.
4. The instance CLI commands suggest `supabase compute pull` (doesn't
exist) and `supabase compute logs --follow` (deprecated; there's no
`--follow` on the replacement).

I hit these deploying a Dockerfile hello-world from the snippet.

## Solution

- Write the CLI size (`2gb`) into the config.toml block. The API size
still drives the `# 2 GB · 1 vCPU` comment, and the deploy dialog is
unchanged.
- The prompt says to set `compute = true` under `[experimental]`, and to
link the project before `push`. The CLI snippet exports
`SUPABASE_EXPERIMENTAL_COMPUTE=1`, and the config.toml snippet has a
comment about it.
- The prompt branches on access. Public: serve plain HTTP on `$PORT`
(defaults to 8080) and add your own auth if needed. Private: run a
background worker and don't start an HTTP server. Dockerfile prompts say
"a Dockerfile" instead of the garbled entrypoint.
- Overview tab: "Listening port" shows `$PORT → 8080` for public and
"None (background worker)" for private, and "How to call" only renders
for public instances. The JS and Python call snippets drop the
`Authorization` header.
- The deploy dialog's access description explains both modes instead of
mentioning a publishable key.
- Drop `pull` and switch logs to `supabase logs --remote --service
compute --resource <name>` in both the overview and logs tabs.

Tests cover each of these in `computeInstanceSnippets.test.ts`.

Not in this PR: Studio's `RUNTIMES.node.entrypoint` is `node index.js`,
while the CLI scaffolds `index.mjs` exporting `{ fetch }` (same for deno
`main.ts`). The node/deno prompt may need a similar pass.

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-17 16:42:11 +00:00

242 lines
7.9 KiB
TypeScript

import { zodResolver } from '@hookform/resolvers/zod'
import { useForm, useWatch } from 'react-hook-form'
import {
Button,
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogSection,
DialogSectionSeparator,
DialogTitle,
Form,
FormControl,
FormField,
Input,
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from 'ui'
import { Admonition } from 'ui-patterns/Admonition'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import * as z from 'zod'
import {
COMPUTE_INSTANCE_DEPLOYABLE_RUNTIMES,
COMPUTE_INSTANCE_SIZES,
COMPUTE_REGION,
} from './Compute.constants'
import type { ComputeInstanceAccess } from './Compute.types'
import { formatSize, generateComputeInstanceName } from './Compute.utils'
import { ComputeInstanceSnippetTabs } from './ComputeInstanceSnippetTabs'
import { RuntimeBadge } from './RuntimeBadge'
const FORM_ID = 'deploy-instance-form'
const DeployComputeInstanceFormSchema = z.object({
name: z
.string()
.trim()
.min(1, 'Name is required')
.regex(/^[a-z0-9-]+$/, 'Lowercase letters, numbers, and hyphens only'),
runtime: z.enum(COMPUTE_INSTANCE_DEPLOYABLE_RUNTIMES),
size: z.enum(COMPUTE_INSTANCE_SIZES),
access: z.enum(['private', 'public']),
instances: z
.union([z.literal(''), z.coerce.number().int().gte(1).lte(10)])
.refine((value) => value !== '', 'Instances is required'),
})
type DeployComputeInstanceFormValues = z.infer<typeof DeployComputeInstanceFormSchema>
const DEFAULT_VALUES: DeployComputeInstanceFormValues = {
name: '',
runtime: 'deno',
size: COMPUTE_INSTANCE_SIZES[0],
access: 'private',
instances: 1,
}
const ACCESS_OPTIONS: { value: ComputeInstanceAccess; label: string }[] = [
{ value: 'private', label: 'Private' },
{ value: 'public', label: 'Public' },
]
interface DeployComputeInstanceDialogProps {
open: boolean
onOpenChange: (open: boolean) => void
}
export const DeployComputeInstanceDialog = ({
open,
onOpenChange,
}: DeployComputeInstanceDialogProps) => {
const form = useForm<DeployComputeInstanceFormValues>({
mode: 'onBlur',
resolver: zodResolver(DeployComputeInstanceFormSchema),
defaultValues: { ...DEFAULT_VALUES, name: generateComputeInstanceName() },
})
const [name, runtime, size, access, instances] = useWatch({
control: form.control,
name: ['name', 'runtime', 'size', 'access', 'instances'],
})
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent size="large">
<DialogHeader>
<DialogTitle>Deploy</DialogTitle>
</DialogHeader>
<DialogSectionSeparator />
<Admonition
type="note"
title="This dashboard is read-only during the Private Alpha"
description={`Configure an instance below, then deploy it locally. Compute instances only deploy to ${COMPUTE_REGION} during alpha.`}
className="border-x-0 border-y-0 rounded-none"
/>
<DialogSectionSeparator />
<DialogSection>
<Form {...form}>
<form id={FORM_ID} className="flex flex-col gap-y-4">
<FormField
control={form.control}
name="name"
render={({ field }) => (
<FormItemLayout label="Name">
<FormControl>
<Input {...field} placeholder="my-instance" />
</FormControl>
</FormItemLayout>
)}
/>
<FormField
control={form.control}
name="runtime"
render={({ field }) => (
<FormItemLayout label="Runtime">
<Select value={field.value} onValueChange={field.onChange}>
<FormControl>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
</FormControl>
<SelectContent>
{COMPUTE_INSTANCE_DEPLOYABLE_RUNTIMES.map((value) => (
<SelectItem key={value} value={value}>
<RuntimeBadge runtime={value} />
</SelectItem>
))}
</SelectContent>
</Select>
</FormItemLayout>
)}
/>
<FormField
control={form.control}
name="size"
render={({ field }) => (
<FormItemLayout
label="Size"
description="Fixed at deploy time and cannot be changed later"
>
<Select value={field.value} onValueChange={field.onChange}>
<FormControl>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
</FormControl>
<SelectContent>
{COMPUTE_INSTANCE_SIZES.map((value) => (
<SelectItem key={value} value={value}>
{formatSize(value)}
</SelectItem>
))}
</SelectContent>
</Select>
</FormItemLayout>
)}
/>
<FormField
control={form.control}
name="access"
render={({ field }) => (
<FormItemLayout
label="Access"
description="Public instances serve HTTP without an API key check. Private instances run as background workers with no inbound access."
>
<Select value={field.value} onValueChange={field.onChange}>
<FormControl>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
</FormControl>
<SelectContent>
{ACCESS_OPTIONS.map((option) => (
<SelectItem key={option.value} value={option.value}>
{option.label}
</SelectItem>
))}
</SelectContent>
</Select>
</FormItemLayout>
)}
/>
<FormField
control={form.control}
name="instances"
render={({ field }) => (
<FormItemLayout label="Instances" description="1 to 10">
<FormControl>
<Input
{...field}
type="number"
min={1}
max={10}
onChange={(e) =>
field.onChange(
Number.isNaN(e.target.valueAsNumber) ? '' : e.target.valueAsNumber
)
}
/>
</FormControl>
</FormItemLayout>
)}
/>
</form>
</Form>
</DialogSection>
<DialogSectionSeparator />
<DialogSection>
<ComputeInstanceSnippetTabs
input={{
name: name ?? '',
runtime: runtime ?? DEFAULT_VALUES.runtime,
size: size ?? DEFAULT_VALUES.size,
access: access ?? DEFAULT_VALUES.access,
instances: typeof instances === 'number' ? instances : DEFAULT_VALUES.instances,
}}
tabs={['ai', 'cli', 'config']}
/>
</DialogSection>
<DialogFooter>
<Button onClick={() => onOpenChange(false)}>Cancel</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}