From d13d131130ab53fb8ee7d49d2b40718622a4ab11 Mon Sep 17 00:00:00 2001 From: Ilion Beyst Date: Sat, 16 Jul 2022 21:22:03 +0200 Subject: move storage paths to GlobalConfig --- planetwars-server/src/modules/matches.rs | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) (limited to 'planetwars-server/src/modules/matches.rs') diff --git a/planetwars-server/src/modules/matches.rs b/planetwars-server/src/modules/matches.rs index dd5e523..a1fe63d 100644 --- a/planetwars-server/src/modules/matches.rs +++ b/planetwars-server/src/modules/matches.rs @@ -11,13 +11,13 @@ use crate::{ matches::{MatchData, MatchResult}, }, util::gen_alphanumeric, - ConnectionPool, GlobalConfig, BOTS_DIR, MAPS_DIR, MATCHES_DIR, + ConnectionPool, GlobalConfig, }; pub struct RunMatch { log_file_name: String, players: Vec, - runner_config: Arc, + config: Arc, } pub enum MatchPlayer { @@ -31,10 +31,10 @@ pub enum MatchPlayer { } impl RunMatch { - pub fn from_players(runner_config: Arc, players: Vec) -> Self { + pub fn from_players(config: Arc, players: Vec) -> Self { let log_file_name = format!("{}.log", gen_alphanumeric(16)); RunMatch { - runner_config, + config, log_file_name, players, } @@ -42,16 +42,16 @@ impl RunMatch { fn into_runner_config(self) -> runner::MatchConfig { runner::MatchConfig { - map_path: PathBuf::from(MAPS_DIR).join("hex.json"), + map_path: PathBuf::from(&self.config.maps_directory).join("hex.json"), map_name: "hex".to_string(), - log_path: PathBuf::from(MATCHES_DIR).join(&self.log_file_name), + log_path: PathBuf::from(&self.config.match_logs_directory).join(&self.log_file_name), players: self .players .into_iter() .map(|player| runner::MatchPlayer { bot_spec: match player { MatchPlayer::BotVersion { bot, version } => { - bot_version_to_botspec(&self.runner_config, bot.as_ref(), &version) + bot_version_to_botspec(&self.config, bot.as_ref(), &version) } MatchPlayer::BotSpec { spec } => spec, }, @@ -98,7 +98,7 @@ impl RunMatch { } pub fn bot_version_to_botspec( - runner_config: &Arc, + runner_config: &GlobalConfig, bot: Option<&db::bots::Bot>, bot_version: &db::bots::BotVersion, ) -> Box { @@ -120,17 +120,14 @@ pub fn bot_version_to_botspec( } } -fn python_docker_bot_spec( - runner_config: &Arc, - code_bundle_path: &str, -) -> Box { - let code_bundle_rel_path = PathBuf::from(BOTS_DIR).join(code_bundle_path); +fn python_docker_bot_spec(config: &GlobalConfig, code_bundle_path: &str) -> Box { + let code_bundle_rel_path = PathBuf::from(&config.bots_directory).join(code_bundle_path); let code_bundle_abs_path = std::fs::canonicalize(&code_bundle_rel_path).unwrap(); let code_bundle_path_str = code_bundle_abs_path.as_os_str().to_str().unwrap(); // TODO: it would be good to simplify this configuration Box::new(DockerBotSpec { - image: runner_config.python_runner_image.clone(), + image: config.python_runner_image.clone(), binds: Some(vec![format!("{}:{}", code_bundle_path_str, "/workdir")]), argv: Some(vec!["python".to_string(), "bot.py".to_string()]), working_dir: Some("/workdir".to_string()), -- cgit v1.2.3