Skip to content
GitHubBlueskydev.toRSS

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.

Terminal window
vx dte init
Read
tasksoutputsvx runyour CI jobrelayworker 1worker 2remote cachetasksoutputsvx runyour CI jobrelayworker 1worker 2remote cache
The relay passes tasks to the workers; outputs travel through the remote cache.

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.

Install the plugin:

Terminal window
bun add -d @vzn/vx-dte

Add it next to your cache. github() starts each worker as a GitHub Actions job.

.vx/workspace.ts
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).

Terminal window
vx lock
vx dte init
Terminal window
vx dte init: wrote .github/workflows/ci.yml
vx 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.

  1. Copy the ALLOW line vx dte init printed into the relay’s settings and deploy it again (how).

  2. Commit the two workflows, .vx/workspace.ts and the lock files.

  3. 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

Edit the last line of ci.yml. Here a pull request runs only what it changed:

.github/workflows/ci.yml
- run: bun vx run build test ${{ github.event_name == 'pull_request' && '--affected' || '--all' }}

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 } }),

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
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.

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
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).
  • ci.yml runs vx run; vx-worker.yml runs each worker. Run it again after you change workers.
  • It prints the ALLOW line naming both workflows. The relay accepts only them.
NextRun one task on a different machine →

Give end-to-end tests machines of their own.

Turborepo, Nx and other product names are trademarks of their owners. vx is not affiliated with or endorsed by them.