# CI and the runner

Every workflow job runs on the self-hosted VPS runner, never on a GitHub-hosted one: what the runner image offers, what each job adds, and the rules a job follows on a shared machine.

## The rule [#the-rule]

**All CI runs on the self-hosted VPS runner. GitHub-hosted runners are never used.** The repository is private, so every minute on `ubuntu-latest` (or any other hosted label) is billed; the owner decided on 2026-11-28 that the project pays no GitHub Actions bill. Every job of every workflow under `.github/workflows/` therefore says:

```yaml
runs-on: [self-hosted, vps]
timeout-minutes: 30
```

A job the runner cannot run is disabled (`if: false`, with a comment that names what the image lacks) and keeps the same `runs-on`, so enabling it again cannot bring a hosted runner back. It is never moved to a hosted runner, not even for one run.

`[test]` [`scripts/ci-runners.test.mjs`](https://github.com/CarlosZiegler/fofo/blob/main/scripts/ci-runners.test.mjs) (in `pnpm test`) fails on a `runs-on` that is not exactly `[self-hosted, vps]` (disabled jobs included), a job without `timeout-minutes`, `services:` or `container:`, a workflow called from another repository, a workflow without a `concurrency` group, and a preview job that is not limited to pull requests into `main`. [`scripts/preview-workflow.test.mjs`](https://github.com/CarlosZiegler/fofo/blob/main/scripts/preview-workflow.test.mjs) holds the [trust zones](#trust-zones).

## The runner [#the-runner]

The runner is one ephemeral Docker container per job on the owner's VPS, started by `vps-runners-agent` from the image `vps-runner:latest` (the private repository `CarlosZiegler/vps-runners` holds its Dockerfile). Two jobs run at once; each has 8 CPU cores, 16 GB of memory and an 8 GB memory-backed `/tmp`. A third job waits in the queue. A project made from this template points `runs-on` at its own runner with the same label, or builds one from that image.

| The image has                                                                 | The image does not have                                           |
| ----------------------------------------------------------------------------- | ----------------------------------------------------------------- |
| Ubuntu 24.04, `git`, `curl`, `jq`, `unzip`, `build-essential`, Python 3       | A Docker daemon: no `services:`, `container:` or Docker actions   |
| Node 24 in the tool cache (`actions/setup-node` resolves it without download) | PostgreSQL 15 or 18 (the RLS matrix installs them, see below)     |
| The pinned pnpm (its default store on `/cache` is not used, see the rules)    | Chromium and its system libraries (the e2e job installs them)     |
| PostgreSQL 16 server binaries on `PATH` (`initdb`, `pg_ctl`, `psql`)          | `wrangler`, `gh` (Wrangler comes from the lockfile or its action) |
| Passwordless `sudo` inside the container                                      | Access to the VPS, its private network or other containers        |

So a workflow skips `pnpm/action-setup`: pnpm is already there. It also skips `cache: pnpm`, for the reason every job has a package store of its own (below).

## What each job needs [#what-each-job-needs]

| Workflow                 | Job                | Runs on                               | Adds to its own container                          |
| ------------------------ | ------------------ | ------------------------------------- | -------------------------------------------------- |
| `ci.yml`                 | `checks`           | every pull request                    | nothing                                            |
| `ci.yml`                 | `rls-matrix`       | every pull request                    | PostgreSQL 15 and 18 from `apt.postgresql.org`     |
| `e2e.yml`                | `web`              | same-repository pull requests, `main` | Chromium with its system libraries (`--with-deps`) |
| `pr-preview.yml`         | `provision`        | pull requests into `main`             | nothing (its own package store)                    |
| `pr-preview.yml`         | `build`            | pull requests into `main`             | nothing (its own package store)                    |
| `pr-preview.yml`         | `deploy`           | pull requests into `main`             | the lockfile's Wrangler, under `/tmp`              |
| `pr-preview.yml`         | `cleanup`          | closed pull requests into `main`      | nothing (its own package store)                    |
| `deploy-prod.yml`        | `prod`             | push to `main`                        | nothing (Wrangler through `wrangler-action`)       |
| `delete-deploy.yml`      | `delete`, `reject` | manual                                | nothing (`curl`)                                   |
| `emergency-shutdown.yml` | `toggle`, `reject` | manual                                | nothing (`curl`, `jq`)                             |

What a job installs with `apt` lands in its container and is removed with it. Baking PostgreSQL 15 and 18 and the Chromium libraries into the image would save that download on every run; the jobs already skip what they find.

**The RLS matrix without Docker.** `rls-matrix.mjs` has one seam, `startPostgres(version)`, with two adapters. `docker` (the default, for a laptop) starts a `postgres:<major>` container per server. `native` starts an `initdb`/`pg_ctl` cluster per server in the temp directory from each major's own binaries (`PG_BIN_<major>`, then `/usr/lib/postgresql/<major>/bin`, then Homebrew's `postgresql@<major>`), which is what CI uses:

```sh
pnpm --filter @fofo/db test:rls-matrix -- --driver native
```

Both accept the same password over TCP, so the suites are identical. See [database](/docs/features/database#tenant-isolation).

**Previews only for pull requests into `main`.** A preview rehearses the production deploy with the Neon parent branch and domain of `main`. A pull request into another branch (an integration branch, a stacked pull request) gets none; before this rule it failed after it had created a database branch. `cleanup` runs when a pull request into `main` closes: the trusted jobs need an environment that accepts `main` alone. It first asks GitHub whether the pull request is still closed, removes what was recorded when the preview was provisioned, and then sweeps the previews of other closed pull requests (one retargeted away from `main`, one whose cleanup failed). See [deployment](/docs/deploy#pull-request-previews).

## Rules for a job [#rules-for-a-job]

The runner is shared by every private repository of the account, and two jobs run side by side.

- **A timeout on every job.** A hung job holds one of two slots; the agent only kills it after six hours.
- **A `concurrency` group on every workflow.** Pull request workflows cancel the superseded run (`cancel-in-progress`); deploys and preview operations never cancel, because a run stopped halfway leaves a Worker, a Hyperdrive or a database branch behind.
- **Nothing outside the workspace and `/tmp`.** The container, its processes, its ports and its file system disappear with the job. The `/cache` volume does not, so no job writes to it: every job that installs sets `pnpm_config_store_dir` to `.pnpm-store` in its own workspace. The image's shared store would hand what one job wrote, a pull request's code included, to the next job of any repository. The cost is one download per job.
- **No cache on `main`.** A `pull_request_target` run executes pull request code and saves caches into the default branch's scope, the one a push to `main` restores from. The e2e job restores its browser cache on pull requests only; jobs that hold a credential use no cache. Every `setup-node` step sets `package-manager-cache: false`.
- **Secrets in files go to `/tmp`, never to the workspace or `runner.temp`.** Both sit on the `/cache` volume while the job runs, where the other running job can read them; `/tmp` is the job's own. The file lives in a directory the job creates with mode `0700` and removes in an `always()` step. Checkouts of jobs that hold deploy secrets use `persist-credentials: false`.
- **No connection string in `GITHUB_ENV` or in a job output.** The runner keeps both as files under `runner.temp`. A value one job hands to the next crosses the job output sealed ([`scripts/preview-handoff.mjs`](https://github.com/CarlosZiegler/fofo/blob/main/scripts/preview-handoff.mjs)) and is masked where it is opened.
- **Local servers stop with the step.** `scripts/test-local-postgres.mjs`, `scripts/e2e-stack.mjs` and the RLS matrix stop their clusters on every exit path and keep them under `/tmp`.
- **No Docker.** A job that needs a database starts a native cluster with `scripts/test-local-postgres.mjs`.

## Trust zones [#trust-zones]

A pull request's code is not trusted with anything that outlives its preview. `pr-preview.yml` runs on `pull_request_target`, so the workflow file comes from `main` and a pull request cannot rewrite a job; every job refuses a fork.

| Job                        | Code it runs                           | Holds                                                                             |
| -------------------------- | -------------------------------------- | --------------------------------------------------------------------------------- |
| `provision`, `cleanup`     | `main` only                            | Neon API key, Cloudflare token (environment `preview-provision`)                  |
| `build`                    | the pull request, after `main`'s steps | the preview's own database URLs (environment `preview`), a read-only GitHub token |
| `deploy`                   | `main` only                            | Cloudflare token, preview secrets (environment `preview-provision`)               |
| `prod` (`deploy-prod.yml`) | `main` only                            | production secrets (environment `production`)                                     |

- **Pull request code never holds the Cloudflare token.** `build` migrates and builds, then hands its output on as one archive. `deploy` runs none of it: `scripts/preview-deploy.mjs` checks the archive's SHA-256 against the one `build` reported, unpacks it with its own reader (files and directories under `server/` and `client/`, no link, no path outside) and validates the Wrangler configuration the build wrote.
- **A preview's name, bindings, variables, routes and triggers come from `main`** (`scripts/preview-worker-config.mjs`); a pull request contributes the shape only: entry point, compatibility date and flags, assets, placement, observability, limits. A built configuration that changes a setting, binds or routes anything else, names an account, sets a build command or turns bundling on stops the deploy. Wrangler starts on a configuration and in a directory `deploy` wrote (it loads `.env` from its working directory), with the token and nothing else of the job's environment.
- **`deploy` writes the preview comment**, from an address it derived. `build` has `contents: read` only.
- **`build` writes its configuration with `main`'s script**, kept outside the workspace before the pull request is checked out, so a head of any age builds the same way.
- **No preview job receives the production database URL.** The isolation check compares against the `PRODUCTION_DATABASE_TARGET` variable (`postgresql://<host>/<database>`, refused with a user or password).
- **`provision` hands on only the preview URLs**, sealed with `PREVIEW_HANDOFF_KEY` for that pull request and run. `build` opens them with `main`'s reader before it checks out the pull request, into a file under `/tmp`; `deploy` opens them in memory.
- **`deploy` executes nothing from the workspace.** It fetches `main` into its own directory under `/tmp`, installs the lockfile's Wrangler there without install scripts, and downloads the archive there.
- **Secrets live in environments limited to `main`, never in the repository.** A repository secret is handed to every job of every workflow, one a pull request or a pushed branch changed included. Each job reads its secrets from its own environment; `preview` holds `PREVIEW_HANDOFF_KEY` alone. `pnpm run setup --github-secrets` publishes each secret to its environment (`SECRET_ENVIRONMENTS` in `packages/project-setup-cli/src/secrets.mjs`), refuses one that accepts any branch but `main` and removes the repository-scoped copy.

A pull request that needs a new binding gets its preview once the binding is on `main`.

### Runner isolation [#runner-isolation]

The rules above are what a job can do by itself. The runner must do the rest, and this is its target layout (set up on the VPS by the owner, not by a workflow):

| Path in the container       | Target                                                                             |
| --------------------------- | ---------------------------------------------------------------------------------- |
| workspace and `runner.temp` | a directory created for the job, mounted into that container only, deleted with it |
| `/cache/pnpm-store`         | not mounted (no job uses it); a shared store only as a read-only mount             |
| Node tool cache             | part of the image, or mounted read-only                                            |
| `/tmp`                      | the job's own memory-backed mount, as today, mounted with `exec`                   |

Until then two running jobs can read each other's workspace, so the workspace of a job never holds a secret; the runner itself still writes each step's script and each action there. `deploy` starts a native binary from `/tmp` and fails in its first step, with the reason, when `/tmp` is mounted `noexec` (Docker's default for `--tmpfs`).

## Storage [#storage]

The runner costs nothing per minute, but three GitHub stores still count against the account's included quota: the e2e report artifact (kept seven days), the preview build archive (kept one day) and the Playwright browser cache (`actions/cache`, pull requests only). Both are small; lower `retention-days` before adding another artifact.

## Key files [#key-files]

- [`.github/workflows/ci.yml`](https://github.com/CarlosZiegler/fofo/blob/main/.github/workflows/ci.yml), [`e2e.yml`](https://github.com/CarlosZiegler/fofo/blob/main/.github/workflows/e2e.yml), [`pr-preview.yml`](https://github.com/CarlosZiegler/fofo/blob/main/.github/workflows/pr-preview.yml), [`deploy-prod.yml`](https://github.com/CarlosZiegler/fofo/blob/main/.github/workflows/deploy-prod.yml)
- [`scripts/ci-runners.test.mjs`](https://github.com/CarlosZiegler/fofo/blob/main/scripts/ci-runners.test.mjs), [`scripts/preview-workflow.test.mjs`](https://github.com/CarlosZiegler/fofo/blob/main/scripts/preview-workflow.test.mjs)
- [`scripts/preview.mjs`](https://github.com/CarlosZiegler/fofo/blob/main/scripts/preview.mjs), [`scripts/preview-handoff.mjs`](https://github.com/CarlosZiegler/fofo/blob/main/scripts/preview-handoff.mjs), [`scripts/preview-build-config.mjs`](https://github.com/CarlosZiegler/fofo/blob/main/scripts/preview-build-config.mjs), [`scripts/preview-deploy.mjs`](https://github.com/CarlosZiegler/fofo/blob/main/scripts/preview-deploy.mjs)
- [`packages/db/scripts/rls-matrix.mjs`](https://github.com/CarlosZiegler/fofo/blob/main/packages/db/scripts/rls-matrix.mjs)
- [`scripts/test-local-postgres.mjs`](https://github.com/CarlosZiegler/fofo/blob/main/scripts/test-local-postgres.mjs)
