fix(functions): edge-runtime template offline bootstrap (#45570)#5171
Open
ChrisJr404 wants to merge 1 commit intosupabase:developfrom
Open
fix(functions): edge-runtime template offline bootstrap (#45570)#5171ChrisJr404 wants to merge 1 commit intosupabase:developfrom
ChrisJr404 wants to merge 1 commit intosupabase:developfrom
Conversation
The embedded edge-runtime entrypoint imported two std modules from deno.land at the top of the file. Deno's graph builder fetches those URLs every time the worker boots, so `supabase start` cannot bootstrap the runtime container without internet access. Inline the small surface that the template actually uses (5 status codes + 1 status-text lookup, plus posix.dirname/join/toFileUrl) and drop the remote imports. The local posix shim was checked against node:path.posix for the path shapes this file constructs. Add a regression-pin test that fails if any HTTPS deno.land/esm.sh/ cdn.jsdelivr/unpkg import is reintroduced into templates/main.ts. Closes supabase/supabase#45570
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The edge-runtime entrypoint that
supabase startwrites into/root/index.ts(embedded frominternal/functions/serve/templates/main.ts) starts with two remote imports:Deno's graph builder resolves these every time the worker boots, so the runtime container fails to come up when the host has no network access.
Reported in supabase/supabase#45570:
Why this happens
The image is
supabase/edge-runtime:vX.Y.Z(pulled, not built here), andindex.tsis materialised on each container start via the embedded template — there is no build-timedeno cachestep we can hook into to pre-warm the module graph for these URLs. Pinning to JSR hits the same wall:jsr:specifiers also require a registry round-trip on first use unless previously cached.Fix
Inline the very small std surface this template actually depends on and drop the remote imports. Concretely:
STATUS_CODE.{OK,Unauthorized,NotFound,InternalServerError,ServiceUnavailable}fromhttps://deno.land/std/http/status.tsSTATUS_CODEconst with the same five numeric valuesSTATUS_TEXT[STATUS_CODE.InternalServerError]from the same moduleSTATUS_TEXTrecord with the same five reason phrasesposix.{dirname,join,toFileUrl}fromhttps://deno.land/std/path/posix/mod.tsposixobject with the same three helpersThe posix shim's outputs were cross-checked against
node:path.posixfor the path shapes this template constructs (/supabase/functions/<name>/index.ts, package-json discovery joins, absolute-to-file://conversion).STATUS_TEXTreason phrases match RFC 9110.This is the smallest viable diff that makes offline boot work — no Dockerfile changes, no new
//go:embedplumbing, no surrounding refactor.The
jsr:@panva/jose@6import on line 1 is unaffected: edge-runtime images already ship that module pre-cached (it has been in this template since #4721), which is why JWT verification works offline today and the std imports are the only blocker.Regression test
Added
TestMainTemplateNoRemoteImportsininternal/functions/serve/serve_test.go. It scans the embedded template forhttps://deno.land/,http://deno.land/,https://esm.sh/,https://cdn.jsdelivr.net/, andhttps://unpkg.com/and fails if any reappear. If anyone re-introduces a bare URL import here, the test catches it before the next offline-start regression.Verification
go build ./...cleango test ./internal/functions/...all pass (incl. existingTestServeCommand,TestServeFunctions, and the new pin)go vet ./...cleanCloses supabase/supabase#45570