Skip to content

Commit ba0b430

Browse files
committed
Merge bitcoin/bitcoin#32989: ci: Migrate CI to hosted Cirrus Runners
3c5da69 ci: remove un-needed lint_run*.sh files (willcl-ark) 2aa288e ci: fix annoying docker warning (will) dd1c590 ci: add ccache hit-rate warning when < 75% (will) f427284 doc: Detail configuration of hosted CI runners (will) 3f339e9 ci: dynamically match makejobs with cores (will) 4393ffd ci: remove .cirrus.yml (will) bc41848 ci: port lint (will) d290a8e ci: port msan-depends (will) 9bbae61 ci: port tsan-depends (will) bf7d536 ci: port tidy (will) 549074b ci: port centos-depends-gui (will) 58e38c3 ci: port previous-releases-depends-debug (will) 341196d ci: port fuzzer-address-undefined-integer-nodepends (will) f2068f2 ci: port no-IPC-i686-DEBUG (will) 2a00b12 ci: port nowallet-libbitcoinkernel (will) 9c2514d ci: port mac-cross-gui-notests (will) 2c990d8 ci: force reinstall of kernel headers in asan (will) 8842514 ci: update asan-lsan-ubsan (will) f253031 ci: port arm 32-bit job (will) 04e7bfb ci: update windows-cross job (will) cc1735d ci: add job to determine runner type (will) 020069e ci: add Cirrus cache host (will) 9c2b96e ci: have base install run in right dir (will) 18f6be0 ci: use docker build cache arg directly (will) 94a0932 ci: use buildx in ci (will) fdf64e5 ci: add configure-docker action (will) 33ba073 ci: add REPO_USE_CIRRUS_RUNNERS (will) b232b0f ci: add caching actions (will) b8fcc9f ci: add configure environment action (will) Pull request description: This changeset migrates all current self-hosted CI jobs over to hosted [Cirrus Runners](https://cirrus-runners.app/). These runners cost a flat rate of $150/month, and we qualify for an open source discount of 50%. Therefore they are $75/month/runner. One "runner" should more accurately be thought of in terms of the number of vCPU you are purchasing: https://cirrus-runners.app/pricing/ or in terms of "concurrency", where 1 runners gets you 1.0 concurrency. e.g. a Linux x86 Runner gets you 16 vCPU (1.0 concurrency) and 64GB RAM to be provisioned as you choose, amongst one or more jobs. Cirrus Runners currently only support Linux (x86 and Arm64) and MacOS (Arm64). This changeset does **not** move the existing Github Actions native MacOS runners away from being run on Github's infrastructure. This could be a follow up optimisation. Runs from this changeset using Cirrus Runners can be found at: https://github.com/testing-cirrus-runners/bitcoin2/actions which shows an uncached run on master ([CI#1](https://github.com/testing-cirrus-runners/bitcoin2/actions/runs/16298637161)), an outside pull request ([CI#3](https://github.com/testing-cirrus-runners/bitcoin2/actions/runs/16303305483?pr=1)) and an updated push to master ([CI#4](https://github.com/testing-cirrus-runners/bitcoin2/actions/runs/16304182527)). These workflows were run on 10 runners, and we would recommend purchasing a similar number for our CI in this repo to achieve the speed and concurrency we expect. We include some optional performance commits, but these could be split out and made into followups or dropped entirely. ## Benefits ### Maintenance As we are not self-hosting, nobody needs to maintain servers, disks etc. ### Bus factor Currently we have a very small number of people with the know-how working on server setup and maintenance. This setup fixes that so that "anyone" familiar with GitHub-style CI systems can work on it. ### Scaling These do _not_ "auto-scale"/have "unlimited concurrency" like some solutions, but if we want more workers/cpu to increase parallism or increase the runner size of certain jobs for a speed-up we can simply buy more concurrency using the web interface. ### Speed Runtimes aproximate current runtimes pretty well, with some jobs being faster. Caching improvements on pull request (re-runs) are left as future optimisations from the current changeset (see below). ### GitHub workflow syntax With a migration to the more-commonly-used GitHub workflow syntax, migration to other providers in the future is often as simple as a one-line change (and installing a new GitHub app to the repo). If we decide to self-host again, then we can also self-host GitHub runners (using https://github.com/actions/runner) and maintain new GH-style CI syntax. ### Reporting GitHub workflows provide nicer built-in reporting directly on the "Checks" page of a pr. This includes more-detailed action reporting, and a host of pretty nice integrated features, such as [Workflow Commands](https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions) for creating annotations that can print messages during runs. See for example at the bottom of this window where we report `ccache` hitrate, if it was below 90%: https://github.com/testing-cirrus-runners/bitcoin/actions/runs/16163449125?pr=1 These could be added conditionally into our CI scripts to report interesting or other information. ## Costs ### Financial Relative to competitors Cirrus runners are cheap for the hosted CI-world. However these are likely more expensive than our current setup, or a well-configured (new) self-hosted setup. If we started with 10 runners to be shared amongst all migrated jobs, this would total $750/mo = $9000/yr. Note that we are not trying to comptete here on cost directly. ### Dependencies We would be dependent on Cirrus infra. ## Forks - Forks should be able to run CI without paid Cirrus runners. This behaviour is achieved through a rather verbose `runs-on:` directive. - This directive hardcodes the main repo (unfortunately you cannot use the `env` github context in this field in particular, for some reason). - This directive also allows for a fork to patch the `runs-on:` field in the ci.yml file if they want to use Cirrus Runners too. - The workflow otherwise will fallback to the GitHub free runners on forks. - This cirrus cache action transparently falls back to github actions cache when not running on cirrus, so forks will get some free github caching (10GB per repo). All jobs work on forks, but will run (slowly) on GitHub native free hosted runners, instead of Cirrus runners. They will also suffer from poor cache hit-rates, but there's nothing that can be done about that, and the situtation is an improvement on today. ## Migration process The main org should also, in addition to pulling code changes: 1. Permit the actions `docker/setup-buildx-action@v3` and `docker/login-action@v3` to be run in this repo. ## Caching For the number of CI jobs we have, cache usage on GitHub would be an issue as GH only provides 10GB of cache space, **per repo**. However cirrus provides [10 GB per runner](https://cirrus-runners.app/setup/#speeding-up-the-cache), which scales better with the number of runners. The `cirruslabs/action/[restore|save]` action we use here redirects this to Cirrus' own cache and is both faster and larger. In the case that user is running CI on a fork, the cirrus cache falls back transparently to GitHub default cache without error. ### ccache, depends-sources, built-depends - Cached as blobs via `cirruslabs/actions/cache` action. - Current implementation: - On `push`: restores and saves caches. - On `pull_request`: restores but does **not** save caches. This means a new pull request should hit a _pretty relevant_ cache. Old pull requests **which are not being rebased on master** may suffer from lower cache hit-rate. If we save caches on all pull request runs we run the risk of evicting recent (and more relevant) cache blobs. It may be possible in a future optimisation to widen this to save on pull request runs too, but it will also depend on how many runners we provision and what cache churn rates are like in the main repo. ### Docker build layer caching - Cached using the `gha` cache backend - These cache blobs compete for space with `ccache`, `depends-sources` and `depends-built` caches - `gha` cache allows `--cache-from` to be used from pull requests, which does not work using a registry cache type (technically we could use a public read-only token to get this working, but that feels wrong) This backend does network i/o and so are marginally slower than our current disk i/o cache. ## But what about... `x`? We have tested many other providers, including [Runs-on](https://runs-on.com/), [Buildjet](https://buildjet.com/), [WarpBuild](https://www.warpbuild.com/), and GitHub hosted runners (and investigated even more). But they all fall short in one-way or another. - Runs-On and Buildjet (and others) require installing GH apps with much too-liberal permissions (e.g. `Administration: Read|Write`) for our use-case. - GitHub hosted runners suffer from all of high costs, lower speed, small cache, and the requirement for a GitHub Teams subscription. - WarpBuild seems to be simply too expensive. ## TODO: To complete migration from self-hosted to hosted for this repo, the backport branches `27.x`, `28.x` and `29.x` would also need their CI ported, but these are left for followups to this change (and pending review/changes here first). ----- Work and experimentation undertaken with m3dwards ACKs for top commit: maflcko: re-ACK 3c5da69 🏗 m3dwards: ACK 3c5da69 achow101: ACK 3c5da69 janb84: re ACK 3c5da69 Tree-SHA512: 9f7f2dddf1a5eebc56b4101663283d4219d189cda6054dba760f1288bed9e6ed3f2fa029a5caedc76c31b1271ea0a0cb0967a796086360d8f5be8277379b6397
2 parents 0eb3eae + 3c5da69 commit ba0b430

File tree

15 files changed

+372
-315
lines changed

15 files changed

+372
-315
lines changed

.cirrus.yml

Lines changed: 0 additions & 199 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: 'Configure Docker'
2+
description: 'Set up Docker build driver and configure build cache args'
3+
inputs:
4+
use-cirrus:
5+
description: 'Use cirrus cache'
6+
required: true
7+
runs:
8+
using: 'composite'
9+
steps:
10+
- name: Set up Docker Buildx
11+
uses: docker/setup-buildx-action@v3
12+
with:
13+
# Use host network to allow access to cirrus gha cache running on the host
14+
driver-opts: |
15+
network=host
16+
17+
# This is required to allow buildkit to access the actions cache
18+
- name: Expose actions cache variables
19+
uses: actions/github-script@v6
20+
with:
21+
script: |
22+
core.exportVariable('ACTIONS_CACHE_URL', process.env['ACTIONS_CACHE_URL'])
23+
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env['ACTIONS_RUNTIME_TOKEN'])
24+
25+
- name: Construct docker build cache args
26+
shell: bash
27+
run: |
28+
# Configure docker build cache backend
29+
#
30+
# On forks the gha cache will work but will use Github's cache backend.
31+
# Docker will check for variables $ACTIONS_CACHE_URL, $ACTIONS_RESULTS_URL and $ACTIONS_RUNTIME_TOKEN
32+
# which are set automatically when running on GitHub infra: https://docs.docker.com/build/cache/backends/gha/#synopsis
33+
34+
# Use cirrus cache host
35+
if [[ ${{ inputs.use-cirrus }} == 'true' ]]; then
36+
url_args="url=${CIRRUS_CACHE_HOST},url_v2=${CIRRUS_CACHE_HOST}"
37+
else
38+
url_args=""
39+
fi
40+
41+
# Always optimistically --cache‑from in case a cache blob exists
42+
args=(--cache-from "type=gha${url_args:+,${url_args}},scope=${CONTAINER_NAME}")
43+
44+
# If this is a push to the default branch, also add --cache‑to to save the cache
45+
if [[ ${{ github.event_name }} == "push" && ${{ github.ref_name }} == ${{ github.event.repository.default_branch }} ]]; then
46+
args+=(--cache-to "type=gha${url_args:+,${url_args}},mode=max,ignore-error=true,scope=${CONTAINER_NAME}")
47+
fi
48+
49+
# Always `--load` into docker images (needed when using the `docker-container` build driver).
50+
args+=(--load)
51+
52+
echo "DOCKER_BUILD_CACHE_ARG=${args[*]}" >> $GITHUB_ENV
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: 'Configure environment'
2+
description: 'Configure CI, cache and container name environment variables'
3+
runs:
4+
using: 'composite'
5+
steps:
6+
- name: Set CI and cache directories
7+
shell: bash
8+
run: |
9+
echo "BASE_ROOT_DIR=${{ runner.temp }}" >> "$GITHUB_ENV"
10+
echo "BASE_BUILD_DIR=${{ runner.temp }}/build" >> "$GITHUB_ENV"
11+
echo "CCACHE_DIR=${{ runner.temp }}/ccache_dir" >> $GITHUB_ENV
12+
echo "DEPENDS_DIR=${{ runner.temp }}/depends" >> "$GITHUB_ENV"
13+
echo "BASE_CACHE=${{ runner.temp }}/depends/built" >> $GITHUB_ENV
14+
echo "SOURCES_PATH=${{ runner.temp }}/depends/sources" >> $GITHUB_ENV
15+
echo "PREVIOUS_RELEASES_DIR=${{ runner.temp }}/previous_releases" >> $GITHUB_ENV
16+
17+
- name: Set cache hashes
18+
shell: bash
19+
run: |
20+
echo "DEPENDS_HASH=$(git ls-tree HEAD depends "ci/test/$FILE_ENV" | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
21+
echo "PREVIOUS_RELEASES_HASH=$(git ls-tree HEAD test/get_previous_releases.py | sha256sum | cut -d' ' -f1)" >> $GITHUB_ENV
22+
23+
- name: Get container name
24+
shell: bash
25+
run: |
26+
source $FILE_ENV
27+
echo "CONTAINER_NAME=$CONTAINER_NAME" >> "$GITHUB_ENV"
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: 'Restore Caches'
2+
description: 'Restore ccache, depends sources, and built depends caches'
3+
runs:
4+
using: 'composite'
5+
steps:
6+
- name: Restore Ccache cache
7+
id: ccache-cache
8+
uses: cirruslabs/cache/restore@v4
9+
with:
10+
path: ${{ env.CCACHE_DIR }}
11+
key: ccache-${{ env.CONTAINER_NAME }}-${{ github.run_id }}
12+
restore-keys: |
13+
ccache-${{ env.CONTAINER_NAME }}-
14+
15+
- name: Restore depends sources cache
16+
id: depends-sources
17+
uses: cirruslabs/cache/restore@v4
18+
with:
19+
path: ${{ env.SOURCES_PATH }}
20+
key: depends-sources-${{ env.CONTAINER_NAME }}-${{ env.DEPENDS_HASH }}
21+
restore-keys: |
22+
depends-sources-${{ env.CONTAINER_NAME }}-
23+
24+
- name: Restore built depends cache
25+
id: depends-built
26+
uses: cirruslabs/cache/restore@v4
27+
with:
28+
path: ${{ env.BASE_CACHE }}
29+
key: depends-built-${{ env.CONTAINER_NAME }}-${{ env.DEPENDS_HASH }}
30+
restore-keys: |
31+
depends-built-${{ env.CONTAINER_NAME }}-
32+
33+
- name: Restore previous releases cache
34+
id: previous-releases
35+
uses: cirruslabs/cache/restore@v4
36+
with:
37+
path: ${{ env.PREVIOUS_RELEASES_DIR }}
38+
key: previous-releases-${{ env.CONTAINER_NAME }}-${{ env.PREVIOUS_RELEASES_HASH }}
39+
restore-keys: |
40+
previous-releases-${{ env.CONTAINER_NAME }}-
41+
42+
- name: export cache hits
43+
shell: bash
44+
run: |
45+
echo "depends-sources-cache-hit=${{ steps.depends-sources.outputs.cache-hit }}" >> $GITHUB_ENV
46+
echo "depends-built-cache-hit=${{ steps.depends-built.outputs.cache-hit }}" >> $GITHUB_ENV
47+
echo "previous-releases-cache-hit=${{ steps.previous-releases.outputs.cache-hit }}" >> $GITHUB_ENV
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
name: 'Save Caches'
2+
description: 'Save ccache, depends sources, and built depends caches'
3+
runs:
4+
using: 'composite'
5+
steps:
6+
- name: debug cache hit inputs
7+
shell: bash
8+
run: |
9+
echo "depends sources direct cache hit to primary key: ${{ env.depends-sources-cache-hit }}"
10+
echo "depends built direct cache hit to primary key: ${{ env.depends-built-cache-hit }}"
11+
echo "previous releases direct cache hit to primary key: ${{ env.previous-releases-cache-hit }}"
12+
13+
- name: Save Ccache cache
14+
uses: cirruslabs/cache/save@v4
15+
if: ${{ (github.event_name == 'push') && (github.ref_name == github.event.repository.default_branch) }}
16+
with:
17+
path: ${{ env.CCACHE_DIR }}
18+
key: ccache-${{ env.CONTAINER_NAME }}-${{ github.run_id }}
19+
20+
- name: Save depends sources cache
21+
uses: cirruslabs/cache/save@v4
22+
if: ${{ (github.event_name == 'push') && (github.ref_name == github.event.repository.default_branch) && (env.depends-sources-cache-hit != 'true') }}
23+
with:
24+
path: ${{ env.SOURCES_PATH }}
25+
key: depends-sources-${{ env.CONTAINER_NAME }}-${{ env.DEPENDS_HASH }}
26+
27+
- name: Save built depends cache
28+
uses: cirruslabs/cache/save@v4
29+
if: ${{ (github.event_name == 'push') && (github.ref_name == github.event.repository.default_branch) && (env.depends-built-cache-hit != 'true' )}}
30+
with:
31+
path: ${{ env.BASE_CACHE }}
32+
key: depends-built-${{ env.CONTAINER_NAME }}-${{ env.DEPENDS_HASH }}
33+
34+
- name: Save previous releases cache
35+
uses: cirruslabs/cache/save@v4
36+
if: ${{ (github.event_name == 'push') && (github.ref_name == github.event.repository.default_branch) && (env.previous-releases-cache-hit != 'true' )}}
37+
with:
38+
path: ${{ env.PREVIOUS_RELEASES_DIR }}
39+
key: previous-releases-${{ env.CONTAINER_NAME }}-${{ env.PREVIOUS_RELEASES_HASH }}

0 commit comments

Comments
 (0)