Repository navigation
feat(deploy): one image for every environment, configured at runtime - #1139
Merged
Merged
Conversation
The image takes no environment's values at build time. Its entrypoint checks ENVIRONMENT (staging or production) and nginx writes it into every HTML page as window.__DOCS_ENV__; the browser picks the Mixpanel project from it. Links to (www.|staging.)thegraph.com follow the page's own origin after mount. image.yml builds ghcr.io/graphprotocol/graph-docs (<commit> on every run, latest from the default branch), checks the runtime environment, and pushes. release.yml gives a v* tag of a default-branch commit that commit's image digest under the tag's name, without rebuilding. ci-cd-production.yml is unchanged; .k8s/production sets ENVIRONMENT=production. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
cjorge-thegraph
marked this pull request as ready for review
November 30, 2026 18:18
cjorge-thegraph
marked this pull request as draft
November 30, 2026 18:22
cjorge-thegraph
marked this pull request as ready for review
November 30, 2026 18:36
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.
Makes the docs image environment-agnostic: the build takes no environment's values and each deployment supplies its environment at runtime, so the image tested in staging is the one a release promotes to production. Adds a
releaseworkflow that tags that image forv*releases. The production deploy workflow (ci-cd-production.yml) is unchanged and still deploys production onv*tags until the production cutover.graph-infra companion: graphprotocol/graph-infra#1148 (draft). Merge this first (see Merge order).
Current state (
main)ci-cd-staging.ymlandci-cd-production.ymleach build an image with build argsENVIRONMENTandORIGIN.next.config.jsinlinesORIGINand a Mixpanel token chosen byENVIRONMENTinto the bundle. In practice, neither build arg reachesnext build: turbo 2 runs tasks in strict env mode and passes only declared variables, so Next falls back towebsite/.env(ENVIRONMENT=local,ORIGIN=http://localhost:3000). Both deployed images therefore carry the same values:e57a98…. Production page views go to the staging project. A local run ofgraph-docs-production:latestsendse57a9892339b2acfd02943c86b746d32, and the livehttps://thegraph.com/docs/en/bundle_app-a91ab44bebbcc1d4.jscontains that token andlocalhost:3000.ORIGINishttp://localhost:3000, which is not a thegraph.com origin, so the staging→staging link rewrite in_app.tsxnever runs. Staging's links to thegraph.com go to production.Nothing else differs by environment.
BASE_PATH, Algolia and the GA measurement ID are the same everywhere. The sitemap uses relative URLs (siteUrl: '/') and is not in the image. There is no canonical link or robots file, and the Open Graph URL is fixed tohttps://thegraph.com/.What changes
Runtime environment
docker-entrypoint.shis the image's entrypoint. It requiresENVIRONMENTto bestagingorproduction; otherwise the container exits and never becomes ready. It writes an nginx include, and nginx'ssub_filterinserts<script>window.__DOCS_ENV__={"ENVIRONMENT":"…"}</script>right after<head>in every HTML response, ahead of Next's deferred scripts.website/src/runtimeEnv.tsreads it in the browser.mixpanelToken()returns the environment's project token, or none (no tracking) without an environment, as innext dev. The two tokens are the onesnext.config.jsalready held.next.config.jsno longer inlinesENVIRONMENT,ORIGINorMIXPANEL_TOKEN, andwebsite/.envdropsENVIRONMENT/ORIGIN. The Dockerfile has noARGs._app.tsxrewrites absolute thegraph.com links to the origin the page is served from, once mounted, when that origin is(www.|staging.)thegraph.com. Until then the links stay as written, in the build-time HTML and in the first client render, so hydration matches. This replacesORIGINwith no configuration: the value was always the site's own origin.Why this mechanism: the site is a static export served by nginx, so there is no server render to carry runtime values (Studio's approach). The pages rendered at build time must therefore be environment-independent. Injecting one inline script per HTML response needs no extra request, and no call site depends on build output. Rewriting placeholders in the bundle at container start would mutate the image and break on constant-folded comparisons. A separate
/env.jswould cost a render-blocking request per page load. Choosing the Mixpanel token by hostname would hard-code environments into the code. The nginx image stays at1.16.0-alpine. Itssub_filterhandles gzip responses, which I checked.Image and workflows
ci-cd-staging.ymlbecomesimage.yml. It buildsghcr.io/graphprotocol/graph-docswith no build args and checks it (.github/scripts/check-runtime-env.sh). It then pushes:<commit>on every run, and:latestonly from the default branch. It no longer pushesgraph-docs-staging. Runs of a branch are serialized and never cancelled (concurrency, replacingcancel-workflow-action), solatestonly moves forward and each built commit keeps its image for a release.ci-cd-pull-request.ymlbuilds the same image without pushing it and runs the same check.check-runtime-env.shasserts the following. The image's config sets noENVIRONMENT/ORIGIN. Forstagingandproduction,/docs/en/and/docs/en/about/start<head>with that environment's script. The container exits whenENVIRONMENTis unset, empty,localorprod.release.yml, modelled on subgraph-studio#42'sreleasejob, runs on av*tag:graph-docs:<tag>at the digestmain's build pushed asgraph-docs:<commit>, as a carbon copy with no rebuild (docker buildx imagetools create --prefer-index=false), and verifies the result.main's build of the commit is still running, it waits up to 40 minutes for<commit>.latest.delivery.follow.image.releases) lands.ci-cd-production.ymlis unchanged. Its build args are now unused, so its image is the same agnostic build..k8s/productionsetsENVIRONMENT=productionon the container, so the next tag's deploy keeps serving..k8s/stagingsetsENVIRONMENT=staging, so the overlay stays valid.package.json:docker:buildtakes no build args;docker:upruns withENVIRONMENT=staging.Behaviour changes the owner should know
cfeac8…) from the next production deploy after this merges, which is whatnext.config.jsalways intended. Today they go to the staging project. If production should keep reporting where it does now, say so before tagging a release./studio,/explorer) go tostaging.thegraph.com, as the code intended.Evidence: one local build, run as staging and as production
I built
Dockerfilelocally with podman (localhost/graph-docs:branch, no build args). To fit an 8 GiB memory cap, the local copy ofnext.config.jssetexperimental.cpus: 2, which changes nothing but the number of static-generation workers. CI builds the same Dockerfile unchanged, and itsbuildjob passes the same check on this PR.check-runtime-env.shagainst the local image (CI'sbuildjob prints the same):In a browser. I loaded
/docs/en/in headless Chrome, using the container as the HTTP proxy, so the page's origin is the real hostname. Nothing left the machine: Mixpanel's request was captured, not delivered. These are the hydrated page's values after 12 s, served over plain HTTP (in deployment the links arehttps://):ENVIRONMENT<head>starts withgraph-docs-production:latest(today)<meta charset>e57a98…(staging)https://thegraph.com/…graph-docs-production:latest(today)<meta charset>e57a98…(staging)https://thegraph.com/…stagingwindow.__DOCS_ENV__={"ENVIRONMENT":"staging"}e57a98…(staging)http://staging.thegraph.com/,/brand/,/privacy/,/terms-of-service/productionwindow.__DOCS_ENV__={"ENVIRONMENT":"production"}cfeac8…(production)http://thegraph.com/,/brand/,/privacy/,/terms-of-service/The same image served both rows: one build, with the environment set only on the container. Other subdomains (
forum.,status.,testnet.) are left as written. The image config sets noENVIRONMENTorORIGIN. Neither environment serves a sitemap, robots file or canonical link, the same as today.Production keeps deploying.
ci-cd-production.ymlis unchanged: it builds this Dockerfile (itsENVIRONMENT/ORIGINbuild args are now unused, which Docker only warns about) and runs.github/scripts/kustomize-apply.sh production. Rendering.k8s/productionthe way that script does (kustomize edit set image graph-docs=…; kustomize build) gives:Run with exactly that environment, the image answers the readiness probe's
GET /with 200 and serves the production row above. A deploy that leftENVIRONMENTout would fail its readiness rather than serve with the wrong label: the container exits, the rollout stalls on its first new Pod, and the old Pods keep serving. There is no default: a default could only mislabel one of the two environments.Merge order
ghcr.io/graphprotocol/graph-docsand no longer movesgraph-docs-staging:latest, so staging stays on its current image. Kargo, which now merges image pins itself (graph-infra#1144), never pins an image that needsENVIRONMENTbefore staging supplies it.mainbuild pushesgraph-docs:<commit>and:latest.fleet-ghcr-pull), Kargo's registry credential (kargo-ghcr-read) and forge's node credential can read the new package's manifest.graph-docs:latestand generatesdocs-env(ENVIRONMENT=staging) in the stg leaves. Kargo then pins each new build as today.graph-docs-stagingpackage can be deleted.At no point does staging lose its followed image or receive one it cannot run. Production's tag deploy keeps working throughout (see Evidence).
Checked locally
pnpm lint,pnpm prettier:check,pnpm typecheck: clean.actionlint: no findings in the changed workflows (only existing SC2086 notes inci-cd-production.yml).shellcheckis clean on both scripts.lint,format,typecheckandbuild(image build pluscheck-runtime-env.sh) pass.🤖 Generated with Claude Code