Skip to content
This repository has been archived by the owner on Dec 21, 2024. It is now read-only.

Commit

Permalink
chore: choose free port for opengb
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFlurry committed Jul 20, 2024
1 parent 88a8086 commit e4a227a
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions rivet-toolchain/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
strum = { version = "0.24", features = ["derive"] }
sysinfo = "0.30.0"
portpicker = "0.1"
tabled = "0.8.0"
tar = "0.4.40"
tempfile = "3.2"
Expand Down
28 changes: 28 additions & 0 deletions rivet-toolchain/src/tasks/backend_choose_local_port.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use global_error::prelude::*;
use serde::{Deserialize, Serialize};

use crate::util::task::TaskCtx;

#[derive(Deserialize)]
pub struct Input {}

#[derive(Serialize)]
pub struct Output {
pub port: u16,
}

pub struct Task;

impl super::Task for Task {
type Input = Input;
type Output = Output;

fn name() -> &'static str {
"backend_choose_local_port"
}

async fn run(_task: TaskCtx, _input: Self::Input) -> GlobalResult<Self::Output> {
let port = unwrap!(portpicker::pick_unused_port(), "no free ports");
Ok(Output { port })
}
}
2 changes: 2 additions & 0 deletions rivet-toolchain/src/tasks/backend_dev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{backend, config, util::task::TaskCtx};

#[derive(Deserialize)]
pub struct Input {
pub port: u16,
pub cwd: String,
}

Expand All @@ -30,6 +31,7 @@ impl super::Task for Task {
Ok(env)
})
.await?;
cmd_env.insert("OPENGB_PORT".into(), input.port.to_string());
cmd_env.insert("OPENGB_TERM_COLOR".into(), "never".into());
let exit_code = backend::run_opengb_command(
task.clone(),
Expand Down
2 changes: 2 additions & 0 deletions rivet-toolchain/src/tasks/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod backend_choose_local_port;
pub mod backend_dev;
pub mod backend_sdk_gen;
pub mod check_login_state;
Expand Down Expand Up @@ -72,6 +73,7 @@ macro_rules! gen_run_task {
}

gen_run_task!(
backend_choose_local_port::Task,
backend_dev::Task,
backend_sdk_gen::Task,
check_login_state::Task,
Expand Down

0 comments on commit e4a227a

Please sign in to comment.