All posts

5 min readPost 18

The China mirror and the release pipeline

GitHub Releases frequently times out or crawls inside mainland China, so Obituary shipped a geo-routed China mirror on launch day. Serving static files was trivial—getting every new release archive onto the mirror reliably and atomically took three complete pipeline rewrites.

On this page
  1. One domain, geo-routed origins, automatic fallback
  2. Iteration 1: direct upload from CI failed on day one
  3. Iteration 2: server-side pull hit a 2-in-3 GitHub timeout rate
  4. Iteration 3: CI pushes to staging; the server verifies and renames atomically
  5. Manual fallback and a pre-written rollback

Obituary hosts its release archives, install scripts, and update metadata on GitHub. For users in mainland China, GitHub asset downloads frequently stall or time out, so on 1.0.0 launch day (11 November) we put a mainland China mirror online alongside GitHub Pages.

Running a static file server was the easy part. The hard problem was syncing 60+ MB of release archives to that mirror safely, atomically, and without breaking live downloads. Getting there took three full iterations: direct CI upload, server-side pull, and finally CI push-to-staging with server-side verification and atomic rename.

One domain, geo-routed origins, automatic fallback ​

Rather than making users juggle separate URLs, both sites share one domain layout:

  • Geo-DNS routes overseas traffic to GitHub Pages and mainland China traffic to the China server, alongside a dedicated mirror subdomain pinned for CLI clients.
  • A dedicated mirror build rewrites every link, agent prompt, and install script on the site to the mirror origin with zero third-party external requests.
  • install.ps1 tries GitHub first and falls back to the mirror after 10 seconds (or immediately with -Mirror cn), always fetching both archive and checksums.txt from the same origin.
  • Install receipts record where the build came from so future updates reuse that channel, and update checks fall back to the mirror's latest.json under the same verification rules.

Iteration 1: direct upload from CI failed on day one ​

Our first pipeline simply uploaded release zips from GitHub Actions directly to the China server. Launch day exposed two failures immediately:

  • Pushing 26 MB from a US runner across the link took over ten minutes and hit job timeout until retried.
  • Website deploys and binary uploads collided on the server's single-uploader lock, causing the second job to abort.

Adding retries and longer timeouts patched the symptom while leaving the cross-border upload brittle.

Iteration 2: server-side pull hit a 2-in-3 GitHub timeout rate ​

In 1.4.2 (19 November) we flipped direction so the China server pulled new releases straight from GitHub using parallel connections.

The very first live run stalled: requesting checksums.txt from GitHub's release download URL timed out two out of three times, while hitting the GitHub API endpoint for the exact same file answered in under a second.

We switched to fetching temporary signed URLs via anonymous API calls per asset and handing them to 16-connection aria2 with resume. Pulling all 9 assets of v1.4.1 (66.6 MB) took 317 seconds, matching upstream byte for byte, and install scripts switched to raw LF bytes from the exact Git tag instead of earlier CRLF uploads.

Iteration 3: CI pushes to staging; the server verifies and renames atomically ​

Server-side pulls still depended on the flakiest hop in the topology: a mainland server dialing GitHub. Early on 21 November we moved to our third architecture—GitHub runners fetch locally at full speed and push to staging, while the mirror server never touches GitHub and only verifies and publishes atomically.

Runner side ​

  • Downloads all 6 platform archives, checksums.txt, and both install scripts straight from the Git tag using a read-only token.
  • Verifies the manifest and every SHA-256 checksum.
  • Pushes files plus transport.sha256 (strictly for transit integrity, not a publisher signature) over SSH with a pinned host key into a staging area.

Server side (least privilege + atomic publish) ​

The mirror's upload account is restricted to one wrapper command accepting only write-only uploads or publish vX.Y.Z, serialized under a single lock:

  • Re-verifies every file and SHA-256 hash inside staging.
  • Atomically renames the verified release folder into place on the same filesystem, then atomically updates latest.json to the newest stable tag.
  • Refuses to overwrite an existing tag if a single byte differs (re-publishing identical bytes is an idempotent no-op).
  • Queues deploys strictly in order instead of canceling in-flight uploads.

Testing the real server publish function against synthetic releases proves all four rejection gates—modified archive, modified install script, prerelease version tag, and divergent bytes under an existing tag—all exit 1, leaving the live download directory untouched with only latest.json and v1.2.3.

Terminal output exercising the mirror server publish script: initial and idempotent publishes succeed, while tampered archive, tampered script, prerelease tag, and divergent re-tag all fail with exit code 1 leaving download/ clean
Real execution of the mirror server publish script against synthetic inputs: every tampered or invalid release fails closed with exit code 1, leaving live downloads untouched.

Manual fallback and a pre-written rollback ​

Manual pull vX.Y.Z stays available as an emergency fallback—the sole remaining path where the server ever contacts GitHub. Before cutting over, we also wrote down a four-step rollback: wait for deploys to go idle, revert the workflow, revoke only the push SSH key without touching site-deploy keys, and leave every published release folder intact.

All posts