Skip to content

Build app commits from Widefleet Git on the server - #455

Merged
tnkuehne merged 10 commits into
mainfrom
server-builds
Nov 28, 2026
Merged

tnkuehne merged 10 commits into
mainfrom
server-builds

Conversation

@tnkuehne

@tnkuehne tnkuehne commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What

Apps whose source is in Widefleet Git can be built and deployed by the server, without a local build. This is the base for clients that have no shell, such as chat assistants.

  • packages/app-ci: a Worker with one Durable Object container per build. The container clones the commit onto the app's branch and runs pnpm install --frozen-lockfile (skipped without package.json, as in deploy). It then runs widefleet deploy --no-wait <app>, the same command as on a computer. An install that changes files of the repository fails the build, and the log lists the files, because deploy would commit them and builds cannot push. At the build's deadline, and on any error, the container is stopped. A build released while its container starts does not start it. A released build keeps its outcome without the log, so a late run of the same build returns that outcome instead of building again. A log nobody released is dropped after a day.

  • Credentials stay in the CI Worker. The container has no Internet access. All HTTP and HTTPS goes through an outbound entrypoint, which allows only:

    • registry.npmjs.org
    • reads of the app's repository: clone, fetch, and the ref check of the source push. Each request gets a fresh repository token from the control plane, through the write-credential route that deploy uses. Pushes are refused.
    • the control plane calls of widefleet deploy for the build's app. These are source target, source prepare, upload session, asset uploads, publish, and the network state that deploy reports.

    The entrypoint adds the build's token to these calls. It also sets the build ID as the idempotency key, so a build publishes at most once. Everything else is answered with 403.

  • Control plane:

    • POST /apps/{appId}/builds builds the branch's latest commit. It uses the project directory of the active deployment, or directory. The caller needs the same app rights as for deploying.

    • GET /apps/{appId}/builds and GET /apps/{appId}/builds/{buildId} report builds. The detail includes the end of the install and deploy output.

    • A BuildWorkflow runs each build. Each run gets a build token (wfb_<build ID>.…) that names its build and is sealed with the installation's keyring, so it is not stored. The token:

      • is valid while the build runs, until the build's deadline 30 minutes after it was started;
      • acts with the starter's recorded sign-in, so company SSO requirements apply as they did when the build was started;
      • has the scopes of the credential that started the build, so it reads only if that credential could;
      • works only on the routes widefleet deploy uses, and only for the build's app. This holds even when input fields name another app, which the API's input decoding allows.

      Build tokens cannot start builds, list apps, or manage network access. Origins that a new version requests stay requested, as with every deploy.

    • A repeated call joins a build that is still running; the tokens of all its runs stay valid. A retry after publishing waits for the CI's outcome. No run of a build goes past its deadline.

    • Setup failures of the workflow, and apps without a repository, finish their builds as failed. A build whose workflow ended without finishing it is reported as failed, as in deployment history.

    • If the branch moved on before the build saved its source, widefleet deploy refuses, as it does locally, and the build fails.

  • Hosted installations deploy the app CI next to the app builders and bind it as APP_CI. The image needs the CLI in packages/app-ci/dist/cli, and restores its execute bits: run pnpm --filter @platform/app-ci build --binary <widefleet built for Debian bookworm>, for example with the binary from tools/build-release-binaries.sh.

Installations without an app CI report that they do not build apps on the server. Nothing changes for them.

Checks

  • pnpm lint, typecheck, and format
  • pnpm exec vitest run in the control plane: all tests pass, including builds.integration.test.ts. Its cases:
    • deploy with the build token and source metadata
    • the token stops working after the build and at its deadline
    • a token works only for the build it names
    • the token is confined to its app, also against input overrides
    • publish once after an interrupted run, keeping the recorded log
    • failed builds with their log
    • builds that do not publish
    • no network changes through builds
    • apps without saved source
  • Earlier runs: the CI image (Node 26, pnpm 12.4.2, Git, the CLI from the release toolchain) and wrangler deploy --dry-run of the control plane and the app CI.
  • Not verified yet: outbound interception in a deployed container. Locally, wrangler dev cannot bind the egress listener with rootless Docker, so this is checked on the first deployment.

Documentation: #456 (draft until a release includes this).

A server build runs the app's locked install and the new
`widefleet build --output` in a container of the app CI, then publishes
the output through the same upload path as `widefleet deploy`, with the
built commit as the deployment's source.

- `widefleet build --output DIR` builds as `deploy` does and writes the
  deployment to a directory; `deploy` uses the same build.
- packages/app-ci: a Worker with a Durable Object container per build. Only
  the npm registry and the app's repository are reachable; the repository
  credential stays in the Worker.
- POST/GET /apps/{appId}/builds start and report builds; a Workflow runs
  each build and publishes it under the account that started it.
- Hosted installations deploy the app CI and bind it to the control plane.
@tnkuehne tnkuehne mentioned this pull request Nov 27, 2026
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
✅ Deployment successful!
View logs
widefleet-docs ffb58c4 Nov 28 2026, 01:26 PM

The app CI no longer needs a build command of its own: the container clones
the commit, installs the locked dependencies and runs widefleet deploy for the
app. Credentials stay in the CI Worker. Its egress gateway passes only the npm
registry, reads of the app's repository with a fresh token for each request,
and the deploy calls of the build's app, to which it adds a build token that
acts for whoever started the build while the build runs. The gateway sets the
build ID as the idempotency key, so a build publishes at most once.
Build tokens work only through the API's app routes and only for the build's
app, also when input fields name another app. They act with the starter's
recorded sign-in and expire with the workflow run. The CI stops the container at
the build deadline and on errors, skips the install without package.json,
refuses installs that change files of the repository, runs widefleet deploy
without waiting for the rollout and keeps outcomes at most a day. Workflow
setup failures and apps without a repository finish their builds.
Build tokens now work only on the routes widefleet deploy uses: source target,
source prepare, upload session and uploads, and the network state. The build is
recorded together with its workflow; a run that starts before the commit is
retried. A repeated run reports the CI's recorded outcome and log. Overlapping
calls for one build share its run, the container is stopped also when its setup
fails, command output is kept as a bounded tail while it streams, NUL is removed
from stored logs, and the cleanup alarm is retried until it succeeds.
The CI's Git credential request was rejected since build tokens are limited to
the deploy routes; the write-credential route that widefleet deploy uses is now
one of them, and the CI uses it for every Git request. A build reads only when
the credential that started it could. A repeated call joins a build that is
still running and hands it the new token; a retry after publishing waits for its
outcome. Failure recording waits for the build's commit, and builds whose
workflow ended report that they failed.
A repeated run keeps the previous token valid, so requests of the run it joins
are not refused. Reading a build whose workflow ended records its failure and
ends its tokens, unless the build finished meanwhile. A build that published
another commit than it was asked to build fails, a build whose CI restarted
says that its log was lost, and the CI intercepts a control plane on another
HTTPS port than 443.
A build's token names its build and is sealed with the installation's
keyring instead of being stored, so every run of a build gets a valid
token and a repeated run no longer ends the one a running container uses.
Tokens and runs end at the deadline set when the build starts.

The CI keeps a released build's outcome without its log, so a run that
arrives after the release returns it instead of building again.
…es in database time

A release during intercept registration no longer lets the run start its
container or removes the deadline alarm it still needs. Build deadlines
are set and checked with the database clock. The image restores the
execute bits of the CLI and esbuild, which build artifacts can lose.
…ore looking up its repository

Cloudflare advises Workflow step timeouts of at most 30 minutes. A build
stops at its deadline, which starts before its step, so the step needs no
longer. A repeated run of a build that already published now concludes it
before it looks up the repository, which may be gone by then.
@tnkuehne
tnkuehne merged commit aaf2b28 into main Nov 28, 2026
16 checks passed
@tnkuehne
tnkuehne deleted the server-builds branch November 28, 2026 13:38
tnkuehne added a commit that referenced this pull request Nov 28, 2026
…459)

## What

Server builds (#455) cost container time. With this change an
installation can decide who builds and for how long.

- **Build policy:** a runtime extension can provide `buildPolicy`
(`runtime-extension.ts`).
- `admit` runs in the transaction that records a build. It returns the
seconds of container time the build may use, or why it cannot start, for
example because the organization has no build time.
- `settle` runs in the transaction that finishes the build, with the
container time the CI reported. It runs only then, so each build settles
at most once.
- A build that ends without that report keeps its whole reservation.
This happens when its workflow stopped, the setup failed, or the CI lost
the run. Its container may still run until its deadline. The policy can
keep the slot and the charge until then.
- `@platform/control-plane/builds` exports `ciBuildTimeLimit`, the most
a policy can grant.
- **Time limit:** a build's deadline is its admission plus the seconds
the policy granted, at most 30 minutes. It counts from the transaction
that admits the build, as the policy's reservation does.
- No run of the build goes past the deadline, so a build that waited
past it in the queue runs no container at all.
- An alarm in the Durable Object stops the container at the deadline,
even if the object restarts in between.
- A run that the object lost counts until it restarted, at most until
the deadline.
  - The CI reports the container time it used (`seconds`).
- **Without a policy:** every build may use the CI's longest build time.
Self-hosted installations pay for their own Cloudflare account.

## Checks

- `pnpm lint`, typecheck, format
- `pnpm exec vitest run` in the control plane: all tests pass, including
new `builds.integration.test.ts` cases:
  - a build the policy refuses is not recorded and gets no workflow
  - granted time reaches the CI, and the used time is settled once
  - builds that end without the CI's time keep their reservation
  - the CI receives the deadline of the granted time
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant