Skip to content

Deploying Fiber

Fiber is two Workers in your Cloudflare account: <name>-api serves the UI and the API, and <name>-engine keeps runs, their logs and the queue of steps. They share a D1 database, and the engine keeps logs and artifacts in two R2 buckets. Steps run on runners you start (runner).

You need a Cloudflare account on the Workers Paid plan, with R2 turned on; Node 24 and pnpm; and a clone of this repository. Every command below is run from the top of the clone, unless it says otherwise.

Terminal window
pnpm install
pnpm --filter @fiber/api exec wrangler login

Wrangler uses CLOUDFLARE_API_TOKEN in place of that login when it is set in your shell. Such a token needs to edit Workers, D1 and R2, or wrangler d1 create fails with an authentication error: unset it while deploying, or give it those permissions.

The name is that of each of the deployment’s parts: lower-case letters, digits and -, such as ci. The address is where people will reach Fiber: a custom domain on a zone of the account, such as https://ci.example.com, or https://<name>-api.<your subdomain>.workers.dev. wrangler whoami does not say the subdomain; the dashboard does, under Workers & Pages.

Terminal window
NAME=ci
URL=https://ci.example.com
Terminal window
cd apps/api
pnpm exec wrangler d1 create $NAME # prints the database's id
pnpm exec wrangler r2 bucket create $NAME-logs
pnpm exec wrangler r2 bucket create $NAME-artifacts
cd ../..
Terminal window
pnpm --filter @fiber/api deploy-config --name $NAME --url $URL --database-id <the id>

It writes apps/api/wrangler.deploy.json and apps/engine/wrangler.deploy.json from the committed wrangler.jsonc of each, with this deployment’s names: the Workers, database, buckets, Workflow and metrics dataset; its own rate-limit namespaces, so that two deployments in an account do not share counters; its address as FIBER_AUTH_ORIGINS and FIBER_PUBLIC_URL; and a route to the custom domain, or workers.dev. Git ignores both files. Write them again after each update of the repository, before deploying it.

Terminal window
cd apps/api
pnpm exec wrangler d1 migrations apply DB --remote -c wrangler.deploy.json
cd ../..

Keep the settings in two files outside the repository, readable only by you, and never commit them:

Terminal window
mkdir -p ~/.config/fiber/$NAME && chmod 700 ~/.config/fiber ~/.config/fiber/$NAME && cd ~/.config/fiber/$NAME
umask 077
KEY=$(openssl rand -hex 32)
printf 'FIBER_SECRETS_KEY=%s\n' "$KEY" > engine.env
printf 'FIBER_SECRETS_KEY=%s\nFIBER_PASSWORD_SIGN_IN=on\nFIBER_ADMIN_PASSWORD=%s\n' \
"$KEY" "$(openssl rand -base64 24)" > api.env
cd -
  • FIBER_SECRETS_KEY encrypts project secrets, and is the same on both Workers. Keep a copy elsewhere: without it the stored secrets cannot be read (secrets).
  • FIBER_PASSWORD_SIGN_IN and FIBER_ADMIN_PASSWORD let you sign in as admin with that password. To sign in with GitHub as well or instead, add its settings to api.env (sign-in).
  • Other settings go in the same files: limits and retention in engine.env (storage), FIBER_METRICS_TOKEN in api.env (metrics). Not FIBER_AUTH_ORIGINS or FIBER_PUBLIC_URL: the configuration has those.

They are stored as the Workers’ secrets when each is deployed with its file, and kept by later deploys that are not given one. A variable of the same name in your shell’s environment wins over the file’s, so have none set while deploying.

The engine first: the API calls it.

Terminal window
pnpm --filter @fiber/web build
cd apps/engine
pnpm exec wrangler deploy -c wrangler.deploy.json --secrets-file ~/.config/fiber/$NAME/engine.env
cd ../api
pnpm exec wrangler deploy -c wrangler.deploy.json --secrets-file ~/.config/fiber/$NAME/api.env
cd ../..

A custom domain is made by the API’s deploy, with its DNS record and certificate; the first request may wait a minute for the certificate.

Terminal window
curl $URL/health # {"status":"ok"}
curl $URL/ready # {"status":"ready"}; a 503 names what is wrong in the API's logs

Then, at $URL, sign in as admin with the password in api.env, and change it in Settings. Once it is changed, take FIBER_ADMIN_PASSWORD out of api.env and remove it from the Worker:

Terminal window
cd apps/api && pnpm exec wrangler secret delete FIBER_ADMIN_PASSWORD -c wrangler.deploy.json && cd ../..

To run a step, build the command line, make a project and an agent, and start a runner:

Terminal window
pnpm --filter @fiber/cli build && pnpm --filter @fiber/runner build
alias fiber="node $PWD/apps/cli/dist/fiber.js"
export FIBER_API_URL=$URL
fiber login --username admin
fiber projects create demo # prints the project's id
TOKEN=$(fiber agents create --project <project id> --name laptop --labels os=linux)
FIBER_AGENT_TOKEN=$TOKEN FIBER_AGENT_ALLOW_HOST_SHELL=true fiber agent \
--runner apps/runner/dist/fiber-runner.js --workspace ~/fiber-workspaces

In another terminal, apply an example and run it:

Terminal window
fiber pipelines apply examples/fiber.yml --project <project id> # prints the pipeline's id
fiber run <pipeline id> --follow
Terminal window
git pull && pnpm install
pnpm --filter @fiber/api deploy-config --name $NAME --url $URL --database-id <the id>
cd apps/api && pnpm exec wrangler d1 migrations apply DB --remote -c wrangler.deploy.json && cd ../..
pnpm --filter @fiber/web build
(cd apps/engine && pnpm exec wrangler deploy -c wrangler.deploy.json)
(cd apps/api && pnpm exec wrangler deploy -c wrangler.deploy.json)

Migrations only add, so the Workers that are running go on working while they are applied. Runs go on through a deploy: their state is in Durable Objects, and runners reconnect.

Cloud runners (apps/containers) are not ready to deploy. The docs site (apps/docs) is static, and deploys with pnpm --filter @fiber/docs build and then wrangler deploy in apps/docs, once wrangler.jsonc there has a route.