Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions actions/runner-select/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ inputs:
github-hosted-runner-label:
required: true
type: string
self-hosted-image-name:
self-hosted-profile:
required: true
type: string
force-github-hosted-runner:
Expand Down Expand Up @@ -37,7 +37,7 @@ runs:
shell: bash
run: |
github_hosted_runner_label='${{ inputs.github-hosted-runner-label }}'
self_hosted_image_name='${{ inputs.self-hosted-image-name }}'
self_hosted_profile='${{ inputs.self-hosted-profile }}'

set -euo pipefail

Expand Down Expand Up @@ -71,7 +71,7 @@ runs:
echo "artifact_path=$artifact_path" | tee -a $GITHUB_OUTPUT

echo "unique_id=$unique_id" | tee -a "$artifact_path"
echo "self_hosted_image_name=$self_hosted_image_name" | tee -a "$artifact_path"
echo "self_hosted_profile=$self_hosted_profile" | tee -a "$artifact_path"
echo "qualified_repo=${{ github.repository }}" | tee -a "$artifact_path"
echo "run_id=${{ github.run_id }}" | tee -a "$artifact_path"

Expand All @@ -89,7 +89,7 @@ runs:
shell: bash
run: |
github_hosted_runner_label='${{ inputs.github-hosted-runner-label }}'
self_hosted_image_name='${{ inputs.self-hosted-image-name }}'
self_hosted_profile='${{ inputs.self-hosted-profile }}'
disabled='${{ steps.init.outputs.disabled }}'
unique_id='${{ steps.init.outputs.unique_id }}'

Expand Down Expand Up @@ -131,10 +131,10 @@ runs:
# Retry for up to 3600 seconds, nominally once per second for up to 3600 times,
# but actually respecting Retry-After for up to 3600 times.
if curl -sS --fail-with-body --retry-max-time 3600 --retry 3600 --retry-delay 1 -X POST "$take_url_with_token" > $result \
&& jq -e . $result > /dev/null; then
&& jq -er '.[0]' $result > /dev/null; then
echo
echo "selected_runner_label=reserved-for:$unique_id" | tee -a $GITHUB_OUTPUT
echo "runner_type_label=self-hosted-image:$self_hosted_image_name" | tee -a $GITHUB_OUTPUT
echo "selected_runner_label=self-hosted-uuid:$(jq -er '.[0].runner.details.runner_uuid' $result)" | tee -a $GITHUB_OUTPUT
echo "runner_type_label=self-hosted-profile:$self_hosted_profile" | tee -a $GITHUB_OUTPUT
echo 'is_self_hosted=true' | tee -a $GITHUB_OUTPUT
exit 0
fi
Expand Down
1 change: 1 addition & 0 deletions monitor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ tracing = { workspace = true }
tracing-subscriber = { workspace = true }
web = { workspace = true }
rand = "0.9.1"
uuid = { version = "1.4.1", features = ["serde", "v4"] }

[dev-dependencies]
settings = { workspace = true, features = ["test"] }
31 changes: 11 additions & 20 deletions monitor/src/github.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{
fmt::Debug,
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
time::{Duration, Instant},
};

use chrono::{DateTime, FixedOffset};
Expand Down Expand Up @@ -124,13 +124,21 @@ pub fn list_registered_runners_for_host() -> eyre::Result<Vec<ApiRunner>> {
Ok(result.collect())
}

pub fn register_runner(runner_name: &str, label: &str, work_folder: &str) -> eyre::Result<String> {
pub fn register_runner(
runner_name: &str,
work_folder: &str,
labels: &[String],
) -> eyre::Result<String> {
let github_api_suffix = &TOML.github_api_suffix;
let github_api_scope = &TOML.github_api_scope;
let label_options = labels
.into_iter()
.flat_map(|label| ["-f".to_owned(), format!("labels[]={label}")])
.collect::<Vec<_>>();
let result = run_fun!(gh api --method POST -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28"
"$github_api_scope/actions/runners/generate-jitconfig"
-f "name=$runner_name@$github_api_suffix" -F "runner_group_id=1" -f "work_folder=$work_folder"
-f "labels[]=self-hosted" -f "labels[]=X64" -f "labels[]=$label")?;
-f "labels[]=self-hosted" $[label_options])?;

Ok(result)
}
Expand All @@ -143,23 +151,6 @@ pub fn unregister_runner(id: usize) -> eyre::Result<()> {
Ok(())
}

pub fn reserve_runner(
id: usize,
unique_id: &str,
reserved_since: SystemTime,
reserved_by: &str,
) -> eyre::Result<()> {
let github_api_scope = &TOML.github_api_scope;
let reserved_since = reserved_since.duration_since(UNIX_EPOCH)?.as_secs();
run_cmd!(gh api --method POST -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28"
"$github_api_scope/actions/runners/$id/labels"
-f "labels[]=reserved-for:$unique_id"
-f "labels[]=reserved-since:$reserved_since"
-f "labels[]=reserved-by:$reserved_by")?;

Ok(())
}

pub fn list_workflow_run_artifacts(
qualified_repo: &str,
run_id: &str,
Expand Down
31 changes: 22 additions & 9 deletions monitor/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use settings::{
TOML,
};
use tracing::{debug, error, info, warn};
use uuid::Uuid;

use crate::{
libvirt::{list_rebuild_guests, list_template_guests},
Expand Down Expand Up @@ -298,16 +299,28 @@ pub fn delete_template(profile: &Profile, snapshot_name: &str) -> eyre::Result<(
}
}

pub fn register_runner(profile: &Profile, runner_guest_name: &str) -> eyre::Result<String> {
pub fn register_runner(
profile: &Profile,
runner_guest_name: &str,
runner_uuid: Uuid,
) -> eyre::Result<String> {
let labels = vec![
format!("self-hosted-profile:{}", profile.profile_name),
format!(
"self-hosted-runner:{}@{}",
runner_guest_name, TOML.github_api_suffix
),
format!("self-hosted-uuid:{}", runner_uuid),
];
match &*profile.profile_name {
"servo-macos13" => macos13::register_runner(profile, runner_guest_name),
"servo-macos14" => macos13::register_runner(profile, runner_guest_name),
"servo-macos15" => macos13::register_runner(profile, runner_guest_name),
"servo-ubuntu2204" => ubuntu2204::register_runner(profile, runner_guest_name),
"servo-ubuntu2204-bench" => ubuntu2204::register_runner(profile, runner_guest_name),
"base-ubuntu2204" => ubuntu2204::register_runner(profile, runner_guest_name),
"servo-ubuntu2204-wpt" => ubuntu2204::register_runner(profile, runner_guest_name),
"servo-windows10" => windows10::register_runner(profile, runner_guest_name),
"servo-macos13" => macos13::register_runner(runner_guest_name, &labels),
"servo-macos14" => macos13::register_runner(runner_guest_name, &labels),
"servo-macos15" => macos13::register_runner(runner_guest_name, &labels),
"servo-ubuntu2204" => ubuntu2204::register_runner(runner_guest_name, &labels),
"servo-ubuntu2204-bench" => ubuntu2204::register_runner(runner_guest_name, &labels),
"base-ubuntu2204" => ubuntu2204::register_runner(runner_guest_name, &labels),
"servo-ubuntu2204-wpt" => ubuntu2204::register_runner(runner_guest_name, &labels),
"servo-windows10" => windows10::register_runner(runner_guest_name, &labels),
other => todo!("Runner registration not yet implemented: {other}"),
}
}
Expand Down
8 changes: 2 additions & 6 deletions monitor/src/image/macos13.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,8 @@ pub(super) fn delete_template(profile: &Profile, snapshot_name: &str) -> eyre::R
Ok(())
}

pub fn register_runner(profile: &Profile, runner_guest_name: &str) -> eyre::Result<String> {
monitor::github::register_runner(
runner_guest_name,
&profile.github_runner_label,
"/Users/servo/a",
)
pub fn register_runner(runner_guest_name: &str, labels: &[String]) -> eyre::Result<String> {
monitor::github::register_runner(runner_guest_name, "/Users/servo/a", labels)
}

pub fn create_runner(
Expand Down
4 changes: 2 additions & 2 deletions monitor/src/image/ubuntu2204.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ pub(super) fn delete_template(profile: &Profile, snapshot_name: &str) -> eyre::R
Ok(())
}

pub fn register_runner(profile: &Profile, runner_guest_name: &str) -> eyre::Result<String> {
monitor::github::register_runner(runner_guest_name, &profile.github_runner_label, "/a")
pub fn register_runner(runner_guest_name: &str, labels: &[String]) -> eyre::Result<String> {
monitor::github::register_runner(runner_guest_name, "/a", labels)
}

pub fn create_runner(
Expand Down
4 changes: 2 additions & 2 deletions monitor/src/image/windows10.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ pub(super) fn delete_template(profile: &Profile, snapshot_name: &str) -> eyre::R
Ok(())
}

pub fn register_runner(profile: &Profile, runner_guest_name: &str) -> eyre::Result<String> {
monitor::github::register_runner(runner_guest_name, &profile.github_runner_label, r"C:\a")
pub fn register_runner(runner_guest_name: &str, labels: &[String]) -> eyre::Result<String> {
monitor::github::register_runner(runner_guest_name, r"C:\a", labels)
}

pub fn create_runner(
Expand Down
2 changes: 1 addition & 1 deletion monitor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub fn validate_tokenless_select(
"Wrong run_id in artifact"
)))?;
}
let Some(profile_key) = args.remove("self_hosted_image_name") else {
let Some(profile_key) = args.remove("self_hosted_profile") else {
Err(EyreReport::InternalServerError(eyre!(
"Wrong run_id in artifact"
)))?
Expand Down
26 changes: 13 additions & 13 deletions monitor/src/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use settings::{
TOML,
};
use tracing::{debug, info, info_span, warn};
use uuid::Uuid;

use crate::{
data::{get_profile_configuration_path, get_profile_data_path, get_runner_data_path},
Expand Down Expand Up @@ -283,16 +284,18 @@ impl Policy {
match profile.image_type {
ImageType::Rust => {
create_dir(get_runner_data_path(id, None)?)?;
let runner_uuid = Uuid::new_v4();
let mut runner_toml =
File::create_new(get_runner_data_path(id, Path::new("runner.toml"))?)?;
writeln!(runner_toml, r#"image_type = "Rust""#)?;
writeln!(runner_toml, r#"runner_uuid = "{}""#, runner_uuid)?;
symlink(
get_profile_configuration_path(&profile, Path::new("boot-script"))?,
get_runner_data_path(id, Path::new("boot-script"))?,
)?;
if !TOML.dont_register_runners() {
let github_api_registration =
register_runner(&profile, &runner_guest_name)?;
register_runner(&profile, &runner_guest_name, runner_uuid)?;
let mut github_api_registration_file = File::create_new(
get_runner_data_path(id, Path::new("github-api-registration"))?,
)?;
Expand Down Expand Up @@ -889,12 +892,15 @@ mod test {

use chrono::{SecondsFormat, Utc};
use jane_eyre::eyre;
use monitor::github::{ApiRunner, ApiRunnerLabel};
use monitor::github::ApiRunner;
use settings::{profile::Profile, TOML};

use crate::{
policy::{Override, RunnerChanges},
runner::{set_runner_created_time_for_test, Runners, Status},
runner::{
clear_runner_reserved_since_for_test, set_runner_created_time_for_test,
set_runner_reserved_since_for_test, Runners, Status,
},
};

use super::Policy;
Expand Down Expand Up @@ -981,6 +987,7 @@ mod test {

let mut registrations = vec![];
let mut guest_names = vec![];
clear_runner_reserved_since_for_test();
for fake in fake_runners {
let (runner_id, guest_name) = make_runner_id_and_guest_name(fake.profile_key);
set_runner_created_time_for_test(runner_id, fake.created_time);
Expand All @@ -994,18 +1001,11 @@ mod test {
guest_names.push(guest_name);
}
Status::Reserved => {
let mut api_runner = make_registration(&guest_name);
api_runner.labels.push(ApiRunnerLabel {
name: "reserved-for:".to_owned(), // any value
});
registrations.push(make_registration(&guest_name));
guest_names.push(guest_name);
if let Some(reserved_since) = fake.reserved_since {
let reserved_since = reserved_since.as_secs();
api_runner.labels.push(ApiRunnerLabel {
name: format!("reserved-since:{reserved_since}"),
});
set_runner_reserved_since_for_test(runner_id, reserved_since.as_secs());
}
registrations.push(api_runner);
guest_names.push(guest_name);
}
Status::Idle => {
let mut api_runner = make_registration(&guest_name);
Expand Down
Loading