Deploy a worker
This guide walks through the full lifecycle of a worker on a self-hosted OpenFlare: write it, deploy it, give it configuration and a hostname, ship updates and roll back.
Prerequisites
Section titled “Prerequisites”- A running OpenFlare (Quickstart).
- The
ofCLI installed and logged in (CLI reference). - The plane admin token (
PLANE_ADMIN_TOKEN) from your installation’s configuration.
printf '%s' "$PLANE_ADMIN_TOKEN" | of login --url http://127.0.0.1:8787 --team acmeof whoami1. Write a worker
Section titled “1. Write a worker”A worker is an ES module with a default export, as on Cloudflare Workers.
export default { async fetch(request, env) { const count = Number((await env.KV.get("hits")) ?? 0) + 1; await env.KV.put("hits", String(count)); return Response.json({ hello: env.GREETING, count }); },};Describe it with a wrangler-style configuration file in the project root. of looks for vrt.toml, cloudflare.config.ts/.js, wrangler.json, wrangler.jsonc, then wrangler.toml, in that order of precedence.
name = "hello"main = "src/index.js"compatibility_date = "2025-01-01"
[vars]GREETING = "hello from OpenFlare"
[[kv_namespaces]]binding = "KV"id = "hello-kv"2. Create the resources your bindings need
Section titled “2. Create the resources your bindings need”Deploy resolves each binding against the plane and fails if the resource is missing. Create resources first:
of kv namespace create hello-kvYou can also create them in the console or through the management API.
3. Build and check offline
Section titled “3. Build and check offline”of check .of check runs configuration normalization, bundling and validation without contacting the plane, and prints a JSON report. Use it as a CI gate.
Bundling is done by of-bundler, a helper (built on rolldown) that is embedded in the of binary. It bundles main and everything it imports into one ES module. cloudflare:* and node:* imports stay external, dynamic import() is split into extra chunks, and files matched by rules ship as separate modules. Setting no_bundle = true in config turns bundling off and ships the directory contents instead.
4. Deploy
Section titled “4. Deploy”of deploy .Output is a JSON summary with the versionId, bundleDigest, revision and counts of uploaded secrets, attached hostnames and so on. A deploy creates an immutable version, activates it and publishes a new signed snapshot. Cells pick the snapshot up and the worker starts serving.
Check the rollout
Section titled “Check the rollout”Publishing is asynchronous: the plane signs a snapshot with a revision number and the cell acknowledges it. The Deployments tab in the console shows each version’s publication and a rollout banner. The status values are:
| Status | Meaning |
|---|---|
PENDING |
Published, not yet acknowledged. |
PARTIAL |
Applied by some but not all targets. |
APPLIED |
The cell applied the revision. |
SUPERSEDED |
A newer revision replaced it. |
List publications with GET /api/v1/cells/{cell}/publications (parameters limit 1 to 200, workerId, before, includeSystem). Publications carry a one-hour expiry, and the plane re-signs each cell automatically in the final third of that window (default sweep every 15 minutes, PLANE_PUBLISH_HEARTBEAT_MS). Those renewals appear with source SYSTEM_RENEWAL and are hidden unless includeSystem=true.
Useful flags:
| Flag | Use |
|---|---|
--dry-run |
Validate and print a summary, send nothing. |
--env <name> |
Deploy an [env.<name>] block. Required when the config defines environments. |
--name <n> |
Override the worker name. |
--tag <t> |
Label the version (at most 128 UTF-16 code units). |
--var K:V |
Set a string var for this deploy. |
--secrets-file <f|-> |
Upload secrets from a dotenv file or stdin. |
--profile <p> |
Use a different saved login. |
See the CLI reference for the full list and the refusal rules.
5. Variables and secrets
Section titled “5. Variables and secrets”Vars are plain configuration values. Declare them in [vars], or pass --var KEY:VALUE (always a string). Typed values from wrangler config (numbers, booleans, objects, arrays) are preserved as typed JSON vars up to 16 KiB each.
If your config declares no vars, a deploy keeps the worker’s existing vars, so values edited in the console are not wiped. Once your config declares vars, it is authoritative for the whole set.
Secrets are write-only values. Declare the name in config (a secrets binding) and supply the value in one of two ways.
# one-off, value on stdinprintf '%s' "$API_KEY" | of secret put --worker hello API_KEY
# at deploy time, from the environment (CI-friendly)printf 'API_KEY=%s\n' "$API_KEY" | of deploy --secrets-file - .A declared secret with no value (neither in --secrets-file nor already stored) fails the deploy. A name cannot be both a var and a secret. List names with of secret ls --worker hello; values are never returned.
Handling secrets in CI
Section titled “Handling secrets in CI”Keep secrets in your CI system’s secret store and pass them through the environment, never through command-line arguments (which are visible in process listings) or committed files:
printf 'API_KEY=%s\nDB_URL=%s\n' "$API_KEY" "$DB_URL" | of deploy --secrets-file - .The of login token is the plane admin token; a CI job with it has full control. For narrower access, create a worker API token limited to code deployment for one worker.
6. Domains
Section titled “6. Domains”A worker is reachable on a hostname you attach to it.
of hostnames add --worker hello hello.example.comof hostnames ls --worker helloA custom hostname starts as a pending claim. The API returns a verification record: a TXT-style name _openflare.<hostname> and a token value that expires after 24 hours. Publish that record in DNS, then verify the hostname from the console or with POST .../hostnames/{hostname}/verify. Hostnames must be lowercase fully-qualified names with at least two labels, ASCII (use punycode for international names), no wildcards, and at most 253 characters. Managed hostnames must sit under the platform’s configured base domain, and reserved labels are refused with VRT_HOSTNAME_NOT_ALLOWED.
You can also declare hostnames in config (routes = [{ pattern = "hello.example.com", custom_domain = true }]). On a first deploy they are attached before the version is activated; on later deploys after. A plain (non-custom_domain) route pattern must refer to a hostname that is already attached and verified. of deploy never deletes a hostname: a custom hostname on the worker that your config does not list makes the deploy fail until you declare it or run of hostnames rm.
For DNS and TLS in the Docker installation see DNS with Cloudflare, TLS certificates and Local hostnames.
7. Ship updates and roll back
Section titled “7. Ship updates and roll back”Every deploy is a new version. List them and activate an older one to roll back:
of versions list --worker helloof rollback --worker hello <version_id>of rollback activates an existing version and publishes the cell; it does not create a new version, and it does not change secrets or hostnames. Versions are attributed to the member or token that created them.
8. D1 migrations
Section titled “8. D1 migrations”Deploys never apply migrations. Apply them explicitly, before or after the deploy that needs them:
of d1 migrations apply hello-db --config wrangler.tomlWith no explicit file list, the CLI reads the database’s migrations_dir (default migrations) from your wrangler config, orders files by their numeric prefix, and sends only those not yet in the plane’s ledger, so re-running is safe. You can also pass --file migrations.json or repeated --migration name=path. Limits: 512 migrations per call, 256 KiB each. See CLI: D1.
Deploying via the API
Section titled “Deploying via the API”Without the CLI, you can deploy by sending module source to the plane, which builds the runtime bundle server side:
curl -sS -X POST \ -H "Authorization: Bearer $PLANE_ADMIN_TOKEN" \ -H "Content-Type: application/json" \ "$PLANE/api/v1/cells/$CELL/teams/$TEAM/workers/hello/deploy-source" \ -d '{ "mainModule": "index.js", "modules": [{"name":"index.js","type":"esModule","text":"export default { fetch() { return new Response(\"ok\") } }"}], "activate": true, "publish": true }'The response contains the new version, whether it was created and activated, the cell revision and the bundleDigest. publish: true requires the plane to have a signing key; otherwise it returns 501. Create the worker first with POST /api/v1/cells/{cell}/workers (body {teamId, name, ...}). Full details are in the Management API guide.
Send "activate": false, "publish": false to save a candidate version without changing what is served; activate it later with POST .../versions/{id}/activate. To read a version’s modules back, call GET .../versions/{id}/source.
A cell without the jsonBindings capability cannot serve JSON variables, so the console only saves them as candidates there. The plane answers VRT_CELL_CAPABILITY_MISSING (409) when a request needs a capability the cell does not advertise.
Deploying from the console
Section titled “Deploying from the console”In Workers, open a worker and press Deploy to paste or edit modules, or use the Files tab and Save & deploy to edit the current modules. See Console.
Deploying with a scoped worker token
Section titled “Deploying with a scoped worker token”For CI, create a per-worker API token with the code:deploy scope (see the console guide). Such a token can only call the deploy-source endpoint and a few read endpoints for that one worker, and every deploy must send the baseVersionId it was built from:
curl -sS -X POST \ -H "Authorization: Bearer $OFW_TOKEN" -H "Content-Type: application/json" \ "$PLANE/api/v1/cells/$CELL/teams/$TEAM/workers/hello/deploy-source" \ -d '{"baseVersionId":"<active version id>","modules":[{"name":"index.js","type":"esModule","text":"..."}],"activate":true}'A token deploy preserves the worker’s existing configuration (bindings, vars) and rejects any other fields with 403. If the active version changed since your base, you get 409; fetch .../deployment-state and retry. A revoked or expired token gets 401.
Read the state to find the base:
curl -sS -H "Authorization: Bearer $OFW_TOKEN" \ "$PLANE/api/v1/cells/$CELL/teams/$TEAM/workers/hello/deployment-state"On a worker’s first deploy there is no active version, so send "baseVersionId": null. Create tokens in the console under the worker’s Settings tab.
Deploying from GitHub
Section titled “Deploying from GitHub”OpenFlare can build and deploy a worker from a GitHub repository on push. See Git push deploy. In the console the flow is:
- Settings > GitHub installations > Add installation, then Find installations.
- Workers > Create worker, set the source to GitHub repository, and choose Create and queue build. Alternatively use Settings > GitHub deployments > Browse repositories.
- Add build variables and secrets with Add build variable, or later under the worker’s Settings in the Git build variables section.
Build jobs and their logs are available at .../git-deploy/jobs, .../jobs/{id}/logs and .../jobs/{id}/logs/{attempt}/{stage}.
Troubleshooting
Section titled “Troubleshooting”VRT_CONFIG_UNSUPPORTED_FIELD: your config uses a Cloudflare feature OpenFlare does not implement; see Compatibility.- “does not support –preview”:
--previewis not available for control-plane deploys. 409on activation or deploy: the active version changed under you; re-read state and retry.- Worker slow on first request after idle: idle workers are frozen and wake on demand; see Compatibility.
- More in Troubleshooting.