Documentation
¶
Overview ¶
Package relaydeploy is the one implementation of "put flue's relay into a Cloudflare account": the Worker module, the web bundle, the Durable Object migration, the secret, the workers.dev host. Two callers share it — `flue relay setup`/`update` in cmd/flue, and the daemon's /api/relay endpoints behind the Remote screen — and sharing is the point: a UI deploy and a CLI deploy that drifted apart would leave users running different relays depending on which button they pressed.
The package deliberately does not read config, prompt, or print. Callers own the token's arrival, the account choice, relay.json and every word shown to a human; what lives here is only the Cloudflare choreography and the constants that define the deploy's shape. Those constants have twins in relay/wrangler.jsonc, which is how the same Worker runs under `pnpm dev` and the vitest pool — the two must agree or a developer and a user end up running different relays.
Index ¶
Constants ¶
const ( // DefaultWorker is the script name `flue relay setup` deploys under when // --worker says nothing else. The script name is the unit of separation // between relays in one account: a dev relay under another name has its // own hostname, secret and hubs, and cannot touch this one. DefaultWorker = "flue-relay" CompatibilityDate = "2026-08-01" DOClass = "DaemonHub" DOBinding = "HUB" AssetsBinding = "ASSETS" // SecretName is the Worker secret the daemon authenticates its outbound // leg with (relay/src/index.ts, authorizeDaemon). SecretName = "DAEMON_SECRET" // VersionVar is the plain-text binding the deploy stamps the deploying // flue's version into. The Worker reports it on /api/health, which is what // lets a daemon (and the Remote screen's "update relay" state) see that a // deployed relay is older than the binary looking at it. VersionVar = "FLUE_VERSION" // StepTimeout bounds one ordinary API call; DeployTimeout bounds the // deploy itself, which uploads the whole web bundle over whatever link the // user has. Each step gets its own deadline rather than the whole flow // sharing one, because callers put prompts between steps: a clock started // before an account question would be counting while the user reads it. StepTimeout = time.Minute DeployTimeout = 10 * time.Minute )
Variables ¶
var RunWorkerFirst = []string{"/daemon", "/daemon/*", "/client", "/client/*", "/api/*"}
RunWorkerFirst are the paths the Worker handles itself rather than letting the asset router answer from the bundle: the two WebSocket legs and the pairing API. The bare entries matter alongside the globs — "/daemon/*" alone would let the asset router answer a bare /daemon with the SPA before the Worker's "no such machine" could.
Functions ¶
func Deploy ¶
Deploy uploads the Worker and the web bundle, and changes nothing else: no secret is minted or bound (the script upload preserves the existing secret_text binding — keptBindingTypes in internal/cloudflare), and no subdomain is touched. It is the whole of `flue relay update`, and the first half of Provision.
func Provision ¶
Provision is a first deploy: Deploy, then the workers.dev host, then a fresh secret bound to the Worker. It returns the host the relay answers on and the secret the fleet shares — the caller writes relay.json and prints the join line, because both of those are its business, not Cloudflare's.
The secret is fresh on every call, never reused: Provision is also the recovery path for a leaked or half-configured relay, and one that preserved the old secret would be unable to rotate the one credential the relay has.
func ValidWorkerName ¶
ValidWorkerName refuses a name that cannot be a Cloudflare script name reachable on workers.dev: the script name becomes the hostname's first label, so the grammar is lowercase letters, digits and inner dashes, at most 63 characters. Callers wrap the error with where the name came from (a --worker flag, a form field).
Types ¶
type Input ¶
type Input struct {
// API carries the user's token. It is used for the calls below and goes
// no further; nothing in this package stores or logs it.
API *cloudflare.Client
AccountID string
Worker string
// Module and Assets are the embedded relay Worker and web bundle. Callers
// check them before asking a human for a credential — a dev build carries
// neither, and that refusal belongs before the token prompt.
Module []byte
Assets []cloudflare.Asset
// AssetHeaders is the `_headers` document the relay serves its assets
// with. It is an input, not a constant here, because its content names
// the daemon package's CSP and this package must not import the daemon.
AssetHeaders string
// Version is stamped into the Worker as VersionVar. "dev" is an honest
// value for a from-source build.
Version string
// OnStep, when set, hears one line per completed step — "worker deployed:
// x" — in the order they happen. Callers own the formatting.
OnStep func(line string)
}
Input is one deploy's worth of decisions, all made by the caller.