Skip to content

Commit 071dd4c

Browse files
paulhaunerantondlr
andcommitted
Add self-hosted runners v2 (#4506)
## Issue Addressed NA ## Proposed Changes Carries on from #4115, with the following modifications: 1. Self-hosted runners are only enabled if `github.repository == sigp/lighthouse`. - This allows forks to still have Github-hosted CI. - This gives us a method to switch back to Github-runners if we have extended downtime on self-hosted. 1. Does not remove any existing dependency builds for Github-hosted runners (e.g., installing the latest Rust). 1. Adds the `WATCH_HOST` environment variable which defines where we expect to find the postgres db in the `watch` tests. This should be set to `host.docker.internal` for the tests to pass on self-hosted runners. ## Additional Info NA Co-authored-by: antondlr <[email protected]>
1 parent fc7f1ba commit 071dd4c

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

.github/workflows/test-suite.yml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ env:
1717
PINNED_NIGHTLY: nightly-2023-04-16
1818
# Prevent Github API rate limiting.
1919
LIGHTHOUSE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
20+
# Enable self-hosted runners for the sigp repo only.
21+
SELF_HOSTED_RUNNERS: ${{ github.repository == 'sigp/lighthouse' }}
22+
# Self-hosted runners need to reference a different host for `./watch` tests.
23+
WATCH_HOST: ${{ github.repository == 'sigp/lighthouse' && 'host.docker.internal' || 'localhost' }}
2024
jobs:
2125
target-branch-check:
2226
name: target-branch-check
@@ -48,11 +52,13 @@ jobs:
4852
run: make cargo-fmt
4953
release-tests-ubuntu:
5054
name: release-tests-ubuntu
51-
runs-on: ubuntu-latest
55+
# Use self-hosted runners only on the sigp repo.
56+
runs-on: ${{ github.repository == 'sigp/lighthouse' && fromJson('["self-hosted", "linux", "large"]') || 'ubuntu-latest' }}
5257
needs: cargo-fmt
5358
steps:
5459
- uses: actions/checkout@v3
5560
- name: Get latest version of stable Rust
61+
if: env.SELF_HOSTED_RUNNERS == false
5662
run: rustup update stable
5763
- name: Install Protoc
5864
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
@@ -64,11 +70,12 @@ jobs:
6470
run: make test-release
6571
release-tests-windows:
6672
name: release-tests-windows
67-
runs-on: windows-2019
73+
runs-on: ${{ github.repository == 'sigp/lighthouse' && fromJson('["self-hosted", "windows"]') || 'windows-2019' }}
6874
needs: cargo-fmt
6975
steps:
7076
- uses: actions/checkout@v3
7177
- name: Get latest version of stable Rust
78+
if: env.SELF_HOSTED_RUNNERS == false
7279
run: rustup update stable
7380
- name: Use Node.js
7481
uses: actions/setup-node@v2
@@ -83,6 +90,7 @@ jobs:
8390
- name: Install make
8491
run: choco install -y make
8592
- uses: KyleMayes/install-llvm-action@v1
93+
if: env.SELF_HOSTED_RUNNERS == false
8694
with:
8795
version: "15.0"
8896
directory: ${{ runner.temp }}/llvm
@@ -92,11 +100,13 @@ jobs:
92100
run: make test-release
93101
beacon-chain-tests:
94102
name: beacon-chain-tests
95-
runs-on: ubuntu-latest
103+
# Use self-hosted runners only on the sigp repo.
104+
runs-on: ${{ github.repository == 'sigp/lighthouse' && fromJson('["self-hosted", "linux", "large"]') || 'ubuntu-latest' }}
96105
needs: cargo-fmt
97106
steps:
98107
- uses: actions/checkout@v3
99108
- name: Get latest version of stable Rust
109+
if: env.SELF_HOSTED_RUNNERS == false
100110
run: rustup update stable
101111
- name: Install Protoc
102112
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
@@ -130,11 +140,13 @@ jobs:
130140
run: make test-slasher
131141
debug-tests-ubuntu:
132142
name: debug-tests-ubuntu
133-
runs-on: ubuntu-22.04
143+
# Use self-hosted runners only on the sigp repo.
144+
runs-on: ${{ github.repository == 'sigp/lighthouse' && fromJson('["self-hosted", "linux", "large"]') || 'ubuntu-latest' }}
134145
needs: cargo-fmt
135146
steps:
136147
- uses: actions/checkout@v3
137148
- name: Get latest version of stable Rust
149+
if: env.SELF_HOSTED_RUNNERS == false
138150
run: rustup update stable
139151
- name: Install Protoc
140152
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612
@@ -160,11 +172,13 @@ jobs:
160172
run: make run-state-transition-tests
161173
ef-tests-ubuntu:
162174
name: ef-tests-ubuntu
163-
runs-on: ubuntu-latest
175+
# Use self-hosted runners only on the sigp repo.
176+
runs-on: ${{ github.repository == 'sigp/lighthouse' && fromJson('["self-hosted", "linux", "small"]') || 'ubuntu-latest' }}
164177
needs: cargo-fmt
165178
steps:
166179
- uses: actions/checkout@v3
167180
- name: Get latest version of stable Rust
181+
if: env.SELF_HOSTED_RUNNERS == false
168182
run: rustup update stable
169183
- name: Install Protoc
170184
uses: arduino/setup-protoc@e52d9eb8f7b63115df1ac544a1376fdbf5a39612

watch/tests/tests.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ use watch::{
2222
};
2323

2424
use log::error;
25+
use std::env;
2526
use std::net::SocketAddr;
2627
use std::time::Duration;
2728
use tokio::{runtime, task::JoinHandle};
@@ -36,6 +37,11 @@ const VALIDATOR_COUNT: usize = 32;
3637
const SLOTS_PER_EPOCH: u64 = 32;
3738
const DEFAULT_TIMEOUT: Duration = Duration::from_secs(5);
3839

40+
/// Set this environment variable to use a different hostname for connecting to
41+
/// the database. Can be set to `host.docker.internal` for docker-in-docker
42+
/// setups.
43+
const WATCH_HOST_ENV_VARIABLE: &str = "WATCH_HOST";
44+
3945
fn build_test_config(config: &DatabaseConfig) -> PostgresConfig {
4046
let mut postgres_config = PostgresConfig::new();
4147
postgres_config
@@ -71,6 +77,10 @@ pub async fn create_test_database(config: &DatabaseConfig) {
7177
.expect("Database creation failed");
7278
}
7379

80+
pub fn get_host_from_env() -> String {
81+
env::var(WATCH_HOST_ENV_VARIABLE).unwrap_or_else(|_| "localhost".to_string())
82+
}
83+
7484
struct TesterBuilder {
7585
pub harness: BeaconChainHarness<EphemeralHarnessType<E>>,
7686
pub config: Config,
@@ -107,6 +117,7 @@ impl TesterBuilder {
107117
database: DatabaseConfig {
108118
dbname: random_dbname(),
109119
port: database_port,
120+
host: get_host_from_env(),
110121
..Default::default()
111122
},
112123
server: ServerConfig {

0 commit comments

Comments
 (0)