Cloudflare container runner

Runs GitHub Actions jobs in Cloudflare Containers: one fresh container for each job, started 2-3 seconds after the job queues. It is opt-in and off by default. runner-up keeps serving everything else.

Turn it on

Add a cloudflare_runner block to .local/host.yml. credentials_file and repos are required.

crewship:
  cloudflare_runner:
    credentials_file: /home/you/super.env   # CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID
    repos:
      - { repo: owner/name, label: cf-name }   # workflows use `runs-on: cf-name`
  #   max_instances: 4                       # most containers at one time
  #   poll_seconds: 60

inspect refuses a label that every runner has (self-hosted, linux, ...) or that looks GitHub-hosted, and a repository named twice. ./ship.sh launch installs the dispatcher and the Worker sources, makes the token between them, deploys the Worker, and starts cf-runner-dispatch.service. A second apply changes nothing. Deploying needs node and Docker on the host; the first image build is slow on a busy host.

How it works

  1. cf-runner-dispatch.service polls each repository for queued jobs whose runs-on has its label.

  2. For each one it asks GitHub for a just-in-time runner named cf-<job id> (the host's gh login; the token never leaves the host) and posts only that runner config to the Worker.

  3. The Worker starts one container. Its entrypoint runs the runner once; GitHub removes the runner after the job, and the container stops.

If the container does not start, the dispatcher deletes the runner it registered. A job still queued after 15 minutes gets a new runner, up to three tries. At most max_instances jobs run at one time; the Worker's own limit is the same number.

Deploying and changing it

cf-runner.py deploy runs a deploy only when the Worker source or its settings changed, and refuses while a dispatched job is in flight, because a deploy replaces running containers. Credentials come from credentials_file and reach wrangler through its environment only.

Limits

Fill a shared cluster

A repository entry may also carry a kvz block. Its jobs then run on a shared Kubernetes cluster (kvz) while the cluster has spare capacity, and on this host otherwise. It is off unless the block is there, and it runs Linux jobs only (the schema accepts only os: linux).

crewship:
  cloudflare_runner:
    repos:
      - repo: owner/name
        label: kvz-name                  # workflows use `runs-on: [self-hosted, kvz-name]`
        kvz:
          ssh: user@cluster-host         # runs `kvz kubectl`; key auth, no prompt
          node: [node-a, node-b]         # nodes that may take a job, in order
          image: ghcr.io/actions/actions-runner:latest
  #       namespace: crewship-ci         # the one namespace of ours; created when missing
  #       max: 1                         # most jobs in the cluster at one time
  #       cpu: "2"  memory: 4Gi          # request and limit of each job
  #       cpu_pct: 60  mem_pct: 60       # busy above this share of a node requested
  #       path: /opt/homebrew/bin        # put in front of PATH on the cluster host

credentials_file is needed only while some repository has no kvz block. For each queued job the dispatcher registers one single-use runner, then decides where it starts:

Safety rules in the code:

Roll back: remove the kvz block and apply, then restart the dispatcher. Delete what is left with kvz kubectl delete namespace <namespace> if you let the dispatcher create it.

Roll back

Change runs-on back to the runner-up label. Removing the block does not stop anything: an apply skips the feature, so the dispatcher keeps running. Stop it with systemctl --user disable --now cf-runner-dispatch.service. The Worker stays deployed until you delete it with wrangler delete.