feat: environment-aware datasette base URL - #604
Closed
stefanb wants to merge 5 commits into
Closed
Conversation
updates image podnebnik/website tag 'main-80b268f-1786858826' to 'main-bbd4950-1786939086'
Every environment previously queried the stage datasette — the base URL was baked into the JS bundle, hardcoded in two of the three islands. A shared resolver (code/datasette-base.ts) now picks the base per environment: VITE_DATASETTE_URL override > fixture base > same-origin /data on deployed hosts (podnebnik.org -> its own datasette, stage.podnebnik.org -> stage-data, via the already-live gateway routes) > stage default for Node/tests/localhost. One promoted image therefore reaches the right data on both stage and prod, with no CORS. Local: docker compose wires the website dev server to the local datasette (127.0.0.1:8001); bare `yarn start` keeps the stage default, opt in with VITE_DATASETTE_URL=http://127.0.0.1:8010 for invoke datasette. Previews: docker-preview.yaml now detects whether the PR touches the datasette path set (same list as docker-data.yaml, fail-closed via the PR files API). If so it builds ghcr.io/podnebnik/data:pr-<N> (db-export generation + multi-arch runtime in one job), bakes /data into the website preview bundle, and applies the preview-data label AFTER the push; otherwise it bakes the stage base and retracts a stale label. The chart gains a previewDatasette component (Deployment/Service + /data HTTPRoute rewrite, templated rollout revision for the mutable pr-N tag) that the infra ApplicationSet enables on the preview-data label. Fixture safety: the resolver reads import.meta.env.* as full literal member expressions (the snapshot define block replaces those exact tokens), fixture mode pins the recorded stage base, and vitest now pins VITE_DATASETTE_URL="" so a shell-exported override can no longer fail the suite. Verified: typecheck-gate OK, 100/100 unit tests, snapshot byte-identical with 0 fixture misses, helm template renders the preview component and an unchanged default, local compose end-to-end. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
stefanb
force-pushed
the
feat/env-aware-datasette-url
branch
from
August 18, 2026 04:29
ef0c991 to
6a484ab
Compare
Member
Author
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.
Problem
Every website environment queried the stage datasette:
https://stage-data.podnebnik.orgwas baked into the JS bundle (hardcoded in two of the three islands). Production served stage data, local instances couldn't use a local datasette, and previews were implicitly tied to stage.What this does
Shared resolver —
code/datasette-base.ts, consumed by all three islands (ERA5api.ts, legacyali-je-vroce/constants.ts,temperatura/heatmaps.jsx). Precedence:VITE_DATASETTE_URLbuild-time override (compose →127.0.0.1:8001; manual dev →:8010; preview builds → per-PR)podnebnik.org/stage.podnebnik.org→ same-origin/data— the gateway already routes each host's/dataprefix to its own datasette, so the single promoted image reaches prod data on prod and stage data on stage, with no CORSLocal — docker compose wires the website dev server to the local datasette container.
Previews (
preview-deploylabel) —docker-preview.yamldetects whether the PR touches the datasette path set (same list asdocker-data.yaml; PR-files API, fail-closed):ghcr.io/podnebnik/data:pr-<N>(db-export generation + multi-arch runtime in one job), bakes/datainto the website bundle, and applies thepreview-datalabel after the image pushpreview-datalabelThe Helm chart gains a
previewDatasettecomponent (Deployment/Service +/dataHTTPRoute rewrite mirroring the live stage/prod route shape; templated rollout revision so each push re-pulls the mutablepr-<N>tag). Chart 1.1.0 → 1.2.0; default render unchanged.The per-PR-preview half needs the
podnebnik-website-previewApplicationSet to enable the component when the PR carries thepreview-datalabel, e.g. in the generator/template:Everything else (prod/stage/local) works without any infra change. Ops note: prod pages will start reading
data.podnebnik.org, whose image tag is pinned by hand in the infra repo — promote the data image alongside the website when relevant.Verification
yarn typecheck:gate— OK (zero-error allowlist holds)yarn test— 100/100, fixture base guard passes (resolver + newVITE_DATASETTE_URL=""pin land atomically —""under the old??logic would have broken the suite)yarn snapshot:check— byte-identical, 0 fixture misses (the resolver keepsimport.meta.env.*as literal member expressions so the snapshotdefineblock still applies)helm template— preview render shows datasette Deployment (pr-999, revision templated) +/dataroute; default render identical to beforeVITE_DATASETTE_URL=http://127.0.0.1:8001; local datasette verified serving climate-si🤖 Generated with Claude Code