00002 — Media Asset Delivery Architecture

By Engineering Team•October 12, 2026•4 min read

Images live in a Cloudflare R2 bucket, not in the repository (ADR-002, SR-002). The page path is in 00001.


1. Topology

Media publishing: the author saves images in a git-ignored folder and writes Markdown with /images paths; upload-media.sh sends new or changed images to the non-production media bucket, served at the assets address; astro build rewrites image paths to that address; a production release copies the images its pages link from the non-production bucket into the production bucket inside R2; the reader's browser loads the page from Pages and each image from the assets address

Two paths meet only in the reader’s browser: the page comes from the Pages project, and each image from assets.<domain>.


2. Components

Component Responsibility Requirements
images/ folder Holds every post and application image, as images/posts/<slug>/ and images/applications/<app>/. Git-ignored, so binaries never enter the repository. In development, public/images links to it, so astro dev serves the images locally. SR-002 SR-NF-01
Markdown and front matter Refer to images by root-relative paths, /images/.... The same text works locally and on the deployed site. —
scripts/upload-media.sh Runs on the host, started by a person through op run, which supplies the bucket’s access keys. Uploads only files whose content differs from the stored object, never deletes, and refuses any bucket that is not a non-production one. SR-002 SR-F-03
scripts/promote-media.sh Runs in app.yml before the deploy. Lists the images the build links, checks each in the non-production bucket, and copies it inside R2 into the target environment’s bucket; prod’s copy is checked against the checksums the non-production release recorded. SR-005 SR-F-10, SR-NF-08
Media bucket One per environment. Public reads only through assets.<domain>; no listing and no writes through that address, and the r2.dev address is off. The non-production bucket deletes objects after a set number of days. SR-002 SR-F-03, SR-NF-02
Image source resolver src/lib/image-source.mjs and the rehype plugin src/lib/rehype-image-source.mjs. At build time they prefix every /images/... path, in front matter and in Markdown, with the environment’s media base URL. With no base URL set, the path stays local. SR-003 SR-F-04
Content-Security-Policy scripts/write-headers.mjs adds the media origin to img-src, so the browser loads images from it. SR-009 SR-F-02

3. Flows

Author

  1. Save the image under images/. A diagram is exported there by npm run export:diagrams.
  2. Refer to it in Markdown as /images/....
  3. Commit the Markdown only. The image stays out of Git.
  4. Upload new and changed images to the non-production bucket with scripts/upload-media.sh through op run. Never to production: images reach it only through a release.

Build

  1. app.yml builds the site for an environment when a person releases it there, with that environment’s media base URL as a build variable (00006).
  2. The resolver writes https://assets.<domain>/images/... into every image reference in the HTML.
  3. Before the deploy, scripts/promote-media.sh copies the images the build links from the non-production bucket into the environment’s own, inside R2. A non-production release copies them onto themselves, which restarts their expiry, and records their checksums; a production release copies the images of the tested non-production build and checks them against those checksums (ADR-006).

Read

  1. The browser loads the page from the Pages project.
  2. It loads each image from assets.<domain>, through the same zone, TLS settings and firewall as the page.

Because media is not bundled into dist/, build and deploy time does not grow with the number of images (BRD-002).


4. How a release copies images: server-side in R2

The release copies images with the S3 CopyObject call, which R2 carries out inside the account, bucket to bucket. The GitHub runner sends one request per image and never holds the image itself, and production receives the object the non-production release served, checked against its recorded checksum.

The copy key pair reads objects in the non-production bucket and writes objects in its own environment’s bucket, nothing else (00005). Why a server-side copy was chosen, and the alternatives considered: ADR-006 — Release Media by Server-Side Copy from the Test Bucket.