From a130124db76cb1785375d3f28e5b489d80e72483 Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Tue, 17 Jun 2025 04:09:29 +0000 Subject: [PATCH] feat(pegboard): add support for custom host entries --- .../edge/infra/client/config/src/manager.rs | 15 +++++++++++++ .../infra/client/manager/src/actor/setup.rs | 22 ++++++++++++++----- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/packages/edge/infra/client/config/src/manager.rs b/packages/edge/infra/client/config/src/manager.rs index 2dfa33f438..7638c57e1f 100644 --- a/packages/edge/infra/client/config/src/manager.rs +++ b/packages/edge/infra/client/config/src/manager.rs @@ -101,6 +101,10 @@ pub struct Runner { pub container_runner_binary_path: Option, pub isolate_runner_binary_path: Option, + + /// Custom host entries to append to /etc/hosts in actor containers. + #[serde(default)] + pub custom_hosts: Option>, } impl Runner { @@ -127,6 +131,10 @@ impl Runner { .clone() .unwrap_or_else(|| Path::new("/usr/local/bin/rivet-isolate-v8-runner").into()) } + + pub fn custom_hosts(&self) -> &[HostEntry] { + self.custom_hosts.as_deref().unwrap_or(&[]) + } } #[derive(Clone, Deserialize, JsonSchema, Default)] @@ -292,3 +300,10 @@ pub enum Addresses { pub struct Vector { pub address: String, } + +#[derive(Clone, Deserialize, JsonSchema)] +#[serde(rename_all = "snake_case", deny_unknown_fields)] +pub struct HostEntry { + pub ip: String, + pub hostname: String, +} diff --git a/packages/edge/infra/client/manager/src/actor/setup.rs b/packages/edge/infra/client/manager/src/actor/setup.rs index a993a3f906..b995d19759 100644 --- a/packages/edge/infra/client/manager/src/actor/setup.rs +++ b/packages/edge/infra/client/manager/src/actor/setup.rs @@ -242,12 +242,7 @@ impl Actor { ); // hosts file content - let hosts_content = indoc!( - " - 127.0.0.1 localhost - ::1 localhost ip6-localhost ip6-loopback - " - ); + let hosts_content = build_hosts_content(ctx); // Write all files in parallel tracing::info!( @@ -775,6 +770,21 @@ impl Actor { } } +fn build_hosts_content(ctx: &Ctx) -> String { + let mut content = indoc!( + " + 127.0.0.1 localhost + ::1 localhost ip6-localhost ip6-loopback + " + ).to_string(); + + for host_entry in ctx.config().runner.custom_hosts() { + content.push_str(&format!("{}\t{}\n", host_entry.ip, host_entry.hostname)); + } + + content +} + async fn bind_ports_inner( ctx: &Ctx, actor_id: Uuid,