feat(release): publish package binaries through Cloudflare

Move files deployments to Wrangler, make CLI and desktop own their publishing destinations, add direct-download update metadata and desktop feeds, and refresh installation docs.
This commit is contained in:
Dax Raad
2026-09-07 19:17:25 -04:00
Unverified
parent 0ab661a9cc
commit d1d1c6f890
24 changed files with 528 additions and 419 deletions
+5 -5
View File
@@ -3,11 +3,11 @@
Independently deployed services supporting OpenCode live here. Runtime packages
and clients live in `packages/`.
| Service | Purpose | Deployment |
| ---------------------- | -------------------------------------- | -------------------------- |
| [`www`](./www) | Website and V2 documentation | `deploy-www.yml`, Wrangler |
| [`updates`](./updates) | Release metadata and update selection | `publish.yml`, Wrangler |
| [`files`](./files) | Public file distribution at `/files/*` | `deploy-files.yml`, Pulumi |
| Service | Purpose | Deployment |
| ---------------------- | -------------------------------------- | ---------------------------- |
| [`www`](./www) | Website and V2 documentation | `deploy-www.yml`, Wrangler |
| [`updates`](./updates) | Release metadata and update selection | `publish.yml`, Wrangler |
| [`files`](./files) | Public file distribution at `/files/*` | `deploy-files.yml`, Wrangler |
These directories are Bun workspaces. Run package commands from each service's
directory. Repository-wide Turbo commands discover them through `services/*`.
+1 -1
View File
@@ -1,4 +1,4 @@
node_modules/
dist/
.pulumi/
.wrangler/
.turbo/
-2
View File
@@ -1,2 +0,0 @@
environment:
- shared/dev
-2
View File
@@ -1,2 +0,0 @@
environment:
- shared/production
-7
View File
@@ -1,7 +0,0 @@
name: files
description: OpenCode public file distribution
main: pulumi.ts
runtime:
name: nodejs
options:
packagemanager: bun
+57 -29
View File
@@ -1,9 +1,8 @@
# Public Files
Each stack owns one R2 bucket, a Worker, and a `/files/*` route on its domain.
Production resources are Pulumi-protected.
Each environment has one R2 bucket, a Worker, and a `/files/*` route on its domain.
| Stack | Bucket and Worker | Public URL |
| Environment | Bucket and Worker | Public URL |
| ----------- | --------------------------- | -------------------------------- |
| Development | `opencode-dev-files` | `https://dev.opencode.ai/files/` |
| Production | `opencode-production-files` | `https://opencode.ai/files/` |
@@ -21,39 +20,27 @@ URL: https://opencode.ai/files/videos/demo.mp4
## Deployment
This directory is the standalone `anomalyco/files` Pulumi project. Pulumi manages
the bucket, Worker source, R2 binding, and zone route. The preview and deploy
scripts bundle the Worker with Bun first; Wrangler is unnecessary.
The route uses the stage's existing proxied DNS record
and takes precedence over broader website routes. Production uses `opencode.ai`;
development uses `dev.opencode.ai`, and personal stages use `<stage>.dev.opencode.ai`.
Wrangler bundles and deploys the Worker, its R2 binding, and its path route.
`wrangler.jsonc` defines the `dev` and `production` environments. Their routes
use the existing proxied stage hostnames and take precedence over broader website
routes.
```bash
bun typecheck
bun run preview --stack anomalyco/files/dev
bun run deploy --stack anomalyco/files/dev
bun run preview --stack anomalyco/files/production
bun run deploy --stack anomalyco/files/production
bun run build
bun run deploy --env dev
bun run deploy --env production
```
The stack exports `bucketName` and `url`. The Cloudflare credential
comes from the stack's imported Pulumi ESC environment and needs R2, Workers
Scripts, and Workers Routes write permissions, plus zone read access.
Initialize new stacks once with `bunx pulumi stack init anomalyco/files/<stage>`.
The checked-in development and production stack files import `shared/dev` and
`shared/production` respectively. Personal stages need an ESC import providing
`CLOUDFLARE_ACCOUNT_ID` and `CLOUDFLARE_API_TOKEN`, and a proxied stage hostname.
The existing buckets are reused. For a fresh environment, create its bucket once
with `bunx wrangler r2 bucket create opencode-<stage>-files` and add the matching
environment to `wrangler.jsonc`.
`.github/workflows/deploy-files.yml` deploys development on every push to `dev`
and production on every push to `v2`. It uses the same Pulumi Cloud OIDC login as
the platform workflow; Cloudflare credentials are supplied through ESC.
The `anomalyco` Pulumi organization's GitHub OIDC issuer must allow organization
tokens with audience `urn:pulumi:org:anomalyco` and these subjects:
- `repo:anomalyco/opencode:ref:refs/heads/dev`
- `repo:anomalyco/opencode:ref:refs/heads/v2`
and production on every push to `v2`, using the existing
`CLOUDFLARE_API_TOKEN` GitHub secret. The token needs Workers Scripts and Workers
Routes write permissions, plus zone read access. Creating buckets and uploading
objects also requires R2 write access.
## Uploading
@@ -78,6 +65,47 @@ video seeking and download resumption, including If-Range. Unsupported or
malformed range formats fall back to a full response. Public CORS allows these
files to be consumed from other origins.
## Release Binaries
Each package owns its publishing destinations. `packages/cli/script/publish.ts`
publishes npm packages, Cloudflare archives, and AUR releases.
`packages/desktop/scripts/publish.ts` publishes GitHub release assets, finalizes
desktop manifests, uploads to Cloudflare, and registers its update artifacts.
The root release script invokes these package publishers.
Both publishers upload signed/packaged outputs to the production bucket for
every release channel:
```text
R2 key: bin/0.0.0-dev-123/opencode2-linux-x64.tar.gz
URL: https://opencode.ai/files/bin/0.0.0-dev-123/opencode2-linux-x64.tar.gz
R2 key: bin/2.0.0/opencode-desktop-mac-arm64.dmg
URL: https://opencode.ai/files/bin/2.0.0/opencode-desktop-mac-arm64.dmg
```
CLI and Node CLI archives contain the standalone executable at their root, with
execute permissions restored after GitHub artifact downloads. Linux uses
`.tar.gz`; macOS and Windows use `.zip`. Desktop uploads retain their GitHub
release filenames, including blockmaps and `.app.tar.gz` bundles.
The package publishers use the shared `UpdateArtifact.upload` helper with the
existing GitHub `CLOUDFLARE_API_TOKEN` secret and R2 object write access. It derives
S3 credentials from the verified token, streams uploads, and sets the content
type, download filename, and immutable cache headers.
The publishers register `cli`, `cli-node` (when built), and `desktop` (when
released) with distribution `opencode`. Each record is published only after all
of its files have uploaded successfully.
Every `metadata.files` entry contains the direct CDN `url`, SHA-256 checksum,
and byte size. Desktop `metadata.manifests` also use those CDN URLs and retain
the original SHA-512 and blockmap metadata.
For local verification, each package publisher accepts `--dry-run` with
`OPENCODE_VERSION` and `OPENCODE_CHANNEL` matching the build. CLI reads its own
`dist/` directory (or `OPENCODE_CLI_DIST`). Desktop reads `OPENCODE_DESKTOP_DIST`;
its dry run expects already-finalized manifests in `RUNNER_TEMP`.
## Caching
Complete GET responses up to 512 MiB are cached through the Workers Cache API
+5 -11
View File
@@ -4,21 +4,15 @@
"private": true,
"type": "module",
"scripts": {
"build": "bun build src/index.ts --target browser --outfile dist/worker.js",
"preview": "bun run build && pulumi preview",
"deploy": "bun run build && pulumi up",
"typecheck": "tsgo --noEmit && tsgo --noEmit --project tsconfig.pulumi.json"
"build": "wrangler deploy --dry-run --env dev --outdir dist",
"dev": "wrangler dev --env dev",
"deploy": "wrangler deploy",
"typecheck": "tsgo --noEmit"
},
"devDependencies": {
"@cloudflare/workers-types": "catalog:",
"@tsconfig/node22": "catalog:",
"@types/node": "catalog:",
"@typescript/native-preview": "catalog:",
"pulumi": "3.246.0",
"typescript": "catalog:"
},
"dependencies": {
"@pulumi/cloudflare": "6.17.0",
"@pulumi/pulumi": "3.246.0"
"wrangler": "4.110.0"
}
}
-49
View File
@@ -1,49 +0,0 @@
import { R2Bucket, WorkersScript, WorkersRoute, getZoneOutput } from "@pulumi/cloudflare"
import { getStack } from "@pulumi/pulumi"
import { readFileSync } from "node:fs"
const stage = getStack()
const protect = stage === "production"
const domain = stage === "production" ? "opencode.ai" : stage === "dev" ? "dev.opencode.ai" : `${stage}.dev.opencode.ai`
const accountId = process.env.CLOUDFLARE_ACCOUNT_ID
if (!accountId) throw new Error("CLOUDFLARE_ACCOUNT_ID is required")
if (!process.env.CLOUDFLARE_API_TOKEN) throw new Error("CLOUDFLARE_API_TOKEN is required")
const zone = getZoneOutput({ filter: { account: { id: accountId }, name: "opencode.ai" } })
const bucket = new R2Bucket(
"files",
{
accountId,
name: `opencode-${stage}-files`,
jurisdiction: "default",
storageClass: "Standard",
},
{ protect },
)
const worker = new WorkersScript(
"files",
{
accountId,
scriptName: `opencode-${stage}-files`,
compatibilityDate: "2026-08-01",
mainModule: "worker.js",
content: readFileSync(new URL("./dist/worker.js", import.meta.url), "utf8"),
bindings: [{ name: "FILES", type: "r2_bucket", bucketName: bucket.name }],
},
{ protect },
)
new WorkersRoute(
"files",
{
zoneId: zone.zoneId,
pattern: `${domain}/files/*`,
script: worker.scriptName,
},
{ protect },
)
export const bucketName = bucket.name
export const url = `https://${domain}/files/`
+1 -1
View File
@@ -35,7 +35,7 @@ export default {
if (!key) return new Response(null, { status: 404, headers: cors })
// Public object responses never vary by cookies, authorization, or origin.
const cacheKey = new Request(url, { method: "GET" })
const cacheKey = new Request(url.href, { method: "GET" })
const cacheControl = request.headers.get("Cache-Control") ?? ""
const noStore = /\bno-store\b/i.test(cacheControl)
const bypass = noStore || /\bno-cache\b|\bmax-age=0\b/i.test(cacheControl)
-8
View File
@@ -1,8 +0,0 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"lib": ["ES2023"],
"types": ["node"]
},
"include": ["pulumi.ts"]
}
+20
View File
@@ -0,0 +1,20 @@
{
"$schema": "node_modules/wrangler/config-schema.json",
"name": "opencode-files",
"main": "src/index.ts",
"compatibility_date": "2026-08-01",
"workers_dev": false,
"preview_urls": false,
"env": {
"dev": {
"name": "opencode-dev-files",
"routes": [{ "pattern": "dev.opencode.ai/files/*", "zone_name": "opencode.ai" }],
"r2_buckets": [{ "binding": "FILES", "bucket_name": "opencode-dev-files" }],
},
"production": {
"name": "opencode-production-files",
"routes": [{ "pattern": "opencode.ai/files/*", "zone_name": "opencode.ai" }],
"r2_buckets": [{ "binding": "FILES", "bucket_name": "opencode-production-files" }],
},
},
}
+29
View File
@@ -11,6 +11,20 @@ curl 'https://opencode.ai/update/api/latest/cli/npm'
The same Worker also serves the original `https://update.opencode.ai` hostname without
the `/update` prefix. Admin forms, pagination, and redirects preserve the request's mount.
## Desktop update feeds
Electron updater manifests are available at `/api/<channel>/desktop/<distribution>/<filename>`:
```sh
curl 'https://opencode.ai/update/api/beta/desktop/opencode/latest-mac.yml'
```
Use `latest.yml` for Windows, `latest-mac.yml` for macOS, `latest-linux.yml` for Linux x64,
and `latest-linux-arm64.yml` for Linux ARM64. The distribution selects the stored download
URLs (`opencode` or `github`). Each manifest includes the selected artifact's version,
file URLs, SHA-512 checksums, sizes, and release date. Existing minimum-version selection
and `current`/User-Agent handling also apply to these feeds.
## Minimum releases
Each channel/name/distribution can mark one retained artifact as `minimum`, independently
@@ -68,6 +82,21 @@ has a single public deployment.
## Publishing
The publish workflow also registers direct binary downloads with distribution
`opencode`, after uploading every file to the public files bucket:
```sh
curl 'https://opencode.ai/update/api/dev/cli/opencode'
curl 'https://opencode.ai/update/api/dev/cli-node/opencode'
curl 'https://opencode.ai/update/api/latest/desktop/opencode'
```
`metadata.files` maps each filename to its direct
`https://opencode.ai/files/bin/<version>/<filename>` URL, SHA-256 checksum, and
byte size. Desktop records additionally contain `metadata.manifests`, with
the CDN URLs and the original Electron update checksums. Existing `npm`,
`github`, and `aur` distributions are published independently.
GitHub Actions publishes artifacts through `POST https://opencode.ai/update/api/publish`
using a short-lived OIDC token with audience `https://update.opencode.ai`. The original
hostname and token audience remain supported. The Worker accepts only tokens signed by
+2 -1
View File
@@ -13,7 +13,8 @@
},
"dependencies": {
"jose": "6.0.11",
"semver": "catalog:"
"semver": "catalog:",
"yaml": "2.9.0"
},
"devDependencies": {
"@cloudflare/workers-types": "catalog:",
+20 -1
View File
@@ -1,6 +1,7 @@
import { createRemoteJWKSet, jwtVerify, type JWTPayload } from "jose"
import type { Pipeline } from "cloudflare:pipelines"
import semver from "semver"
import { stringify } from "yaml"
interface Env {
DB: D1Database
@@ -71,7 +72,7 @@ export default {
if (request.method !== "GET") return new Response("Method not allowed", { status: 405 })
const [root, ...path] = pathname.split("/").filter(Boolean)
if (root !== "api" || path.length < 1 || path.length > 3 || !path.every(validIdentifier)) {
if (root !== "api" || path.length < 1 || path.length > 4 || !path.every(validIdentifier)) {
return new Response("Not found", { status: 404 })
}
@@ -80,6 +81,12 @@ export default {
const current = url.searchParams.get("current") ?? agent?.[2] ?? agent?.[3]
const source = agent?.[1] ?? current?.match(/^v?0\.0\.0-(.+)-\d+(?:\.\d+)?(?:\+.*)?$/)?.[1]
const caller = source === undefined || resolveChannel(source) === resolved ? current : undefined
if (path.length === 4) {
if (path[1] !== "desktop" || !/^latest(?:-mac|-linux(?:-arm64)?)?\.yml$/.test(path[3])) {
return new Response("Not found", { status: 404 })
}
return artifactDistribution(env.DB, resolved, path[1], path[2], caller, path[3])
}
if (path.length === 1) return channel(env.DB, resolved, caller)
if (path.length === 2) return artifactName(env.DB, resolved, path[1], caller)
return artifactDistribution(env.DB, resolved, path[1], path[2], caller)
@@ -112,6 +119,7 @@ async function artifactDistribution(
name: string,
distribution: string,
current: string | undefined,
manifest?: string,
) {
const result = await db
.prepare(`${select} WHERE channel = ? AND name = ? AND distribution = ? AND (active = 1 OR minimum = 1)`)
@@ -119,6 +127,17 @@ async function artifactDistribution(
.all<ArtifactRow>()
const artifact = selectArtifacts(result.results, current)[0]
if (!artifact) return json({ error: "Artifact not found" }, 404)
if (manifest) {
const metadata = decodeMetadata(artifact.metadata)
const value =
isRecord(metadata) && isRecord(metadata.manifests)
? metadata.manifests[manifest.replace(/^latest/, "desktop")]
: undefined
if (!isRecord(value)) return json({ error: "Manifest not found" }, 404)
return new Response(stringify({ ...value, version: artifact.version }), {
headers: { "Content-Type": "application/yaml; charset=utf-8", "Cache-Control": "no-store" },
})
}
return updateResponse(decodeArtifact(artifact))
}
+6 -2
View File
@@ -16,14 +16,18 @@ versions installed and run them side by side.
$ bun install -g --trust @opencode/cli@beta
$ pnpm add -g --allow-build=@opencode/cli @opencode/cli@beta
$ yarn global add @opencode/cli@beta
$ paru -S opencode-beta
$ curl -fsSL https://opencode.ai/v2/install | bash`}
/>
</div>
The package uses a trusted postinstall script to select the native `opencode2` binary for your platform. The Bun and pnpm
The npm package uses a trusted postinstall script to select the native `opencode2` binary for your platform. The Bun and pnpm
commands above explicitly allow that script to run.
Homebrew, Arch Linux, Windows package managers, Docker, and standalone binaries are not supported during the beta.
On Arch Linux, install [`opencode-beta`](https://aur.archlinux.org/packages/opencode-beta) from the AUR with `paru`.
It provides the `opencode2` command; manage updates through your AUR helper.
Homebrew, Windows package managers, Docker, and standalone binaries are not supported during the beta.
---