07Distributed task execution
Spread a CI run over several machines
One CI job starts more jobs, gives them its tasks, and still reports one result.
vx dte initDeploy the relay
Section titled “Deploy the relay”Follow Distributed task execution server to deploy one. Come back with its URL, such as https://vx-dte-server.acme.workers.dev.
You can now own the one server your workers need, on your own account.
Add dte()
Section titled “Add dte()”Install the plugin:
bun add -d @vzn/vx-dteAdd it next to your cache. github() starts each worker as a GitHub Actions job.
import { defineWorkspace } from '@vzn/vx/config'import { vxCache } from '@vzn/vx-cache'import { github as ci } from '@vzn/vx-ci'import { dte, github } from '@vzn/vx-dte'import { bun } from '@vzn/vx-lockfile'
export default defineWorkspace({ plugins: [ bun(), ci(), vxCache({ url: 'https://vx-cache-server.acme.workers.dev', issuer: 'https://token.actions.githubusercontent.com', repository: 'acme/app', }), dte({ relay: 'https://vx-dte-server.acme.workers.dev', workers: { linux: { machines: { cpu4: { max: 8, cpu: 4, memory: '16GB', }, }, }, }, adapter: github(), }), ],})Read workers as: up to 8 machines per run, each 4 cores and 16GB.
You can now tell vx where workers meet (relay), what they are (workers) and who starts them (adapter).
Let vx write the workflows
Section titled “Let vx write the workflows”vx lockvx dte initvx dte init: wrote .github/workflows/ci.ymlvx dte init: wrote .github/workflows/vx-worker.yml
Next: 1. Let these workflows use the relay at https://vx-dte-server.acme.workers.dev: set its ALLOW. Its ALLOW (a plain var, no secret): https://token.actions.githubusercontent.com:acme/app:ci.yml https://token.actions.githubusercontent.com:acme/app:vx-worker.yml 2. A remote cache the run and the workers share: workers hand back outputs only through it. https://vznjs.github.io/vx/docs/remote-cache/ 3. Commit .github/workflows/ci.yml, .github/workflows/vx-worker.yml, .vx/workspace.ts and the lock (vx lock), and push. How a run spreads over workers: https://vznjs.github.io/vx/docs/distributed-task-execution/Two files appear:
| File | What it does |
|---|---|
ci.yml |
your CI job: runs vx run, which starts workers as needed |
vx-worker.yml |
one worker’s job: check out, install, vx dte worker |
You can now get both workflows written for you, with nothing to edit.
Let the workflows in and push
Section titled “Let the workflows in and push”-
Copy the
ALLOWlinevx dte initprinted into the relay’s settings and deploy it again (how). -
Commit the two workflows,
.vx/workspace.tsand the lock files. -
Push.
No secret goes into your repository: workers prove who they are with GitHub’s own token.
The run’s log and job summary name the worker beside each task, as in the local run.
Check yourself You push a commit that changes only README.md. How many workers start?
None, if no task reads README.md. Every task is a cache hit, and a hit needs no worker.
You can now run CI over up to eight machines and pay only for the work that changed.
PatternsCommon setups
Choose what CI runs
Section titled “Choose what CI runs”Edit the last line of ci.yml. Here a pull request runs only what it changed:
- run: bun vx run build test ${{ github.event_name == 'pull_request' && '--affected' || '--all' }}Hand workers a value from the run
Section titled “Hand workers a value from the run”github({ env }) passes variables the run’s job decides, such as a preview server’s URL:
adapter: github({ env: { API_URL: process.env.API_URL } }),A proxy in front of the relay
Section titled “A proxy in front of the relay”headers go on every call to the relay, for example a Cloudflare Access service token:
dte({ relay: 'https://vx-dte-server.acme.workers.dev', headers: { 'CF-Access-Client-Id': process.env.CF_ACCESS_CLIENT_ID }, // …}),You can now pick the tasks, pass values to workers and reach a relay behind a proxy.
DetailsEvery option
dte(options)
Section titled “dte(options)”| Option | What it does | Default |
|---|---|---|
workers |
Worker types by name, in order of preference. Each has machines: sizes the adapter may start, named <type>.<machine>. |
none |
adapter |
What starts workers: github(), gitlab(), local() or docker(). |
none: the run uses workers that join it |
relay |
The relay’s URL. VX_DTE_RELAY overrides it. |
the adapter’s own (local() has one) |
token |
A function returning the bearer token for the relay. | VX_DTE_TOKEN, else GitHub’s OIDC token |
unmeasured |
{ cpu, memory }: what a task with no history counts for when vx decides how many workers to start. On a worker it takes any free core. |
2 cores, 4GB; once planning, the measured tasks’ mean |
headers |
Headers on every call to the relay. An unset value is left out. | none |
Each machine’s fields (max, cpu, memory, platform, runsOn): Give heavy tasks a bigger machine.
github(options?)
Section titled “github(options?)”| Option | What it does | Default |
|---|---|---|
workflow |
The workers’ workflow file in .github/workflows. |
'vx-worker.yml' |
env |
Variables handed to every worker. An unset value is left out. | none |
Other adapters
Section titled “Other adapters”| Adapter | Option | What it does |
|---|---|---|
gitlab() |
tags |
Runner tags per machine, { 'linux.cpu4': ['saas-linux-medium-amd64'] }. |
docker() |
image |
An image with Bun and git. Required. |
docker() |
prepare |
A shell line the clone runs first, such as bun install. |
local() |
prepare |
The same, in each worktree (try it). |
What vx dte init writes
Section titled “What vx dte init writes”ci.ymlrunsvx run;vx-worker.ymlruns each worker. Run it again after you changeworkers.- It prints the
ALLOWline naming both workflows. The relay accepts only them.