Skip to content

feat(website): publish new media to R2 in the Vercel build - #100

Merged
JUNERDD merged 1 commit into
mainfrom
feat/website-media-publish
Nov 4, 2026
Merged

JUNERDD merged 1 commit into
mainfrom
feat/website-media-publish

Conversation

@JUNERDD

@JUNERDD JUNERDD commented Nov 4, 2026

Copy link
Copy Markdown
Owner

Removes the manual upload and redeploy that every case-clip change needed (e.g. #97 and #99 both failed their first preview).

Cause

vercel.json runs assets:check after the build. It fails the deployment if any media the site references is missing from assets.atd.best, and that guard is right. But putting the media there was a manual wrangler r2 object put step from a logged-in machine, which in practice came after the push. Each upload also re-sent all 107 files (34 MiB).

Change

  • Build command: build → assets:publish → assets:check.
  • assets:publish (scripts/upload-assets.mjs --bucket atd-assets --if-configured):
    • Validates the manifest as before.
    • Asks the bucket through R2's S3 API which content-addressed keys it holds, and uploads only the missing ones, 8 at a time.
    • Nothing is ever deleted. A held key whose size differs fails rather than being overwritten under caches.
    • Without credentials (a fork's preview, a local build) it skips and leaves the decision to the check, so behavior without the token is unchanged.
  • Client: requests are signed with aws4fetch (MIT, 64 kB, no dependencies), the client Cloudflare documents for R2. It's added to the workspace catalog at 1.0.20.
  • Why not Wrangler: an Object Read & Write token scoped to one bucket works only with the S3 API (Cloudflare: object-level tokens fail against the REST API). Wrangler's object commands use the REST API and would need an account-wide Admin token in every preview build.
  • README: documents the token, the variables and the manual path.

Setup needed (owner)

  1. Cloudflare dashboard → R2 → Manage API tokens → Create Account API token: permission Object Read & Write, applied to atd-assets only.
  2. In the Vercel project atd-agent, add sensitive variables for Production and Preview: R2_ASSETS_ACCOUNT_ID, R2_ASSETS_ACCESS_KEY_ID, R2_ASSETS_SECRET_ACCESS_KEY.

Until then, builds skip the upload exactly as today.

Verification

  • pnpm --filter @atd/website lint, oxfmt --check and a CDN build of the site pass, and assets:check passes locally.
  • No credentials: assets:publish skips with exit 0; a manual assets:upload fails with "Set R2_ASSETS_… to upload."
  • Fake keys against the real bucket endpoint: the signed HEAD gets 401, and the script fails naming only the key and status.
  • Not yet exercised: the successful path (HEAD 200/404, then PUT). It needs the token; the first Vercel build after setup will run it, and assets:check --full re-verifies every byte.

🤖 Generated with Claude Code

Every change to the case clips failed its first deployment: the build's delivery check needs the
media on the CDN, but uploading them was a manual Wrangler step taken after the push, followed by
a redeploy.

- The Vercel build now runs `assets:publish` between the build and the check. It asks the
  `atd-assets` bucket, through R2's S3 API, which content-addressed keys it already holds and
  uploads only the others; a held key whose size differs fails instead of being overwritten.
- Credentials are a bucket-scoped R2 API token's S3 pair in R2_ASSETS_* environment variables.
  Without them (a fork's preview, a local build) the step skips and the check decides, as before.
- Requests are signed with aws4fetch, the client Cloudflare documents for R2. Wrangler cannot use
  a bucket-scoped token, since its object commands call the REST API, which needs an Admin token.
@vercel

vercel Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
atd-agent Ready Ready Preview Nov 4, 2026 11:04am UTC

@JUNERDD
JUNERDD merged commit 412a7ac into main Nov 4, 2026
9 checks passed
@JUNERDD
JUNERDD deleted the feat/website-media-publish branch November 4, 2026 11:39

This branch was successfully deployed

1 active deployment
Preview — f2b6ffe0 Deployed Nov 4, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant