mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
## 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>
139 lines
4.7 KiB
TypeScript
139 lines
4.7 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
import { useParams } from 'common'
|
|
import { RefreshCwIcon, SearchIcon } from 'lucide-react'
|
|
import { useState } from 'react'
|
|
import { Button, InputGroup, InputGroupAddon, InputGroupInput } from 'ui'
|
|
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { ComputeInstanceCommandLine } from '../ComputeInstanceCommandLine'
|
|
import { computeLogsCommand } from '../computeInstanceSnippets'
|
|
import { ComputeLogsColumnRender } from '@/components/interfaces/Settings/Logs/LogColumnRenderers/ComputeLogsColumnRender'
|
|
import { EXPLORER_DATEPICKER_HELPERS } from '@/components/interfaces/Settings/Logs/Logs.constants'
|
|
import {
|
|
LogsDatePicker,
|
|
type DatePickerValue,
|
|
} from '@/components/interfaces/Settings/Logs/Logs.DatePickers'
|
|
import type { LogData } from '@/components/interfaces/Settings/Logs/Logs.types'
|
|
import { LogTable } from '@/components/interfaces/Settings/Logs/LogTable'
|
|
import { AlertError } from '@/components/ui/AlertError'
|
|
import {
|
|
COMPUTE_INSTANCE_LOG_STREAM_LABEL,
|
|
computeInstanceLogsQueryOptions,
|
|
type ComputeInstanceLogStream,
|
|
} from '@/data/compute/compute-instance-logs-query'
|
|
import { useDebouncedValue } from '@/hooks/misc/useDebouncedValue'
|
|
|
|
interface ComputeInstanceLogsTabProps {
|
|
instanceName: string
|
|
stream: ComputeInstanceLogStream
|
|
}
|
|
|
|
const defaultDateRange = (): DatePickerValue => {
|
|
const helper = EXPLORER_DATEPICKER_HELPERS.find((helper) => helper.text === 'Last 24 hours')!
|
|
|
|
return {
|
|
from: helper.calcFrom(),
|
|
to: helper.calcTo(),
|
|
isHelper: true,
|
|
text: helper.text,
|
|
}
|
|
}
|
|
|
|
export const ComputeInstanceLogsTab = ({ instanceName, stream }: ComputeInstanceLogsTabProps) => {
|
|
const { ref: projectRef } = useParams()
|
|
const [selectedLog, setSelectedLog] = useState<LogData | null>(null)
|
|
const [dateRange, setDateRange] = useState<DatePickerValue>(defaultDateRange)
|
|
const [message, setMessage] = useState('')
|
|
const debouncedMessage = useDebouncedValue(message, 300)
|
|
|
|
const {
|
|
data: logs,
|
|
error,
|
|
isPending,
|
|
isError,
|
|
isFetching,
|
|
refetch,
|
|
} = useQuery(
|
|
computeInstanceLogsQueryOptions({
|
|
projectRef,
|
|
name: instanceName,
|
|
stream,
|
|
iso_timestamp_start: dateRange.from,
|
|
iso_timestamp_end: dateRange.to,
|
|
message: debouncedMessage,
|
|
})
|
|
)
|
|
|
|
const label = COMPUTE_INSTANCE_LOG_STREAM_LABEL[stream].toLowerCase()
|
|
|
|
return (
|
|
<div className="flex flex-1 flex-col min-h-0">
|
|
<div className="flex flex-wrap items-center justify-between gap-2 border-b border-default px-4 py-2">
|
|
<div className="flex flex-wrap items-center gap-2">
|
|
<LogsDatePicker
|
|
hideWarnings
|
|
value={dateRange}
|
|
onSubmit={setDateRange}
|
|
helpers={EXPLORER_DATEPICKER_HELPERS}
|
|
align="start"
|
|
/>
|
|
<InputGroup className="w-60">
|
|
<InputGroupInput
|
|
size="tiny"
|
|
placeholder="Filter by event message"
|
|
value={message}
|
|
onChange={(event) => setMessage(event.target.value)}
|
|
/>
|
|
<InputGroupAddon>
|
|
<SearchIcon />
|
|
</InputGroupAddon>
|
|
</InputGroup>
|
|
</div>
|
|
<Button icon={<RefreshCwIcon />} loading={isFetching} onClick={() => refetch()}>
|
|
Refresh
|
|
</Button>
|
|
</div>
|
|
|
|
{isError && (
|
|
<div className="p-4">
|
|
<AlertError error={error} subject="Failed to retrieve instance logs" />
|
|
</div>
|
|
)}
|
|
|
|
{!isError && isPending && (
|
|
<div className="p-4">
|
|
<GenericSkeletonLoader />
|
|
</div>
|
|
)}
|
|
|
|
{!isError && !isPending && (
|
|
<div className="relative flex flex-1 flex-col grow overflow-auto">
|
|
<LogTable
|
|
projectRef={projectRef ?? ''}
|
|
columnRenderers={ComputeLogsColumnRender}
|
|
data={logs ?? []}
|
|
isLoading={isPending}
|
|
showHeader={false}
|
|
showHistogramToggle={false}
|
|
selectedLog={selectedLog ?? undefined}
|
|
onSelectedLogChange={(log) => setSelectedLog(log)}
|
|
EmptyState={
|
|
<div className="mx-auto max-w-md space-y-3 py-16 text-center">
|
|
<p className="text-sm text-foreground">No {label} in the selected time range</p>
|
|
<p className="text-sm text-foreground-lighter">
|
|
View them from the Supabase CLI while you wait for traffic.
|
|
</p>
|
|
<div className="pt-1 text-left">
|
|
<ComputeInstanceCommandLine
|
|
command={computeLogsCommand(instanceName, stream === 'output' ? 'app' : stream)}
|
|
/>
|
|
</div>
|
|
</div>
|
|
}
|
|
/>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|