From ef4046165e40be6e08a50c74876baeaf47af46d9 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Fri, 4 Nov 2022 10:54:05 +0100 Subject: [PATCH] Allow configuring the `dora up` behavior through a `dora-config.yml` file --- Cargo.lock | 1 + binaries/cli/Cargo.toml | 1 + binaries/cli/src/main.rs | 9 ++++++++- binaries/cli/src/up.rs | 40 ++++++++++++++++++++++++++++++++++++---- 4 files changed, 46 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index a9c5f76c..50793535 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -878,6 +878,7 @@ dependencies = [ "clap 4.0.3", "dora-core", "eyre", + "serde", "serde_json", "serde_yaml 0.9.11", "sysinfo 0.26.6", diff --git a/binaries/cli/Cargo.toml b/binaries/cli/Cargo.toml index 0016c02e..1b9c79ca 100644 --- a/binaries/cli/Cargo.toml +++ b/binaries/cli/Cargo.toml @@ -13,6 +13,7 @@ path = "src/main.rs" clap = { version = "4.0.3", features = ["derive"] } eyre = "0.6.8" dora-core = { path = "../../libraries/core" } +serde = { version = "1.0.136", features = ["derive"] } serde_yaml = "0.9.11" tempfile = "3.3.0" webbrowser = "0.8.0" diff --git a/binaries/cli/src/main.rs b/binaries/cli/src/main.rs index c96b23dc..ccde387c 100644 --- a/binaries/cli/src/main.rs +++ b/binaries/cli/src/main.rs @@ -47,6 +47,8 @@ enum Command { }, Dashboard, Up { + #[clap(long)] + config: Option, #[clap(long)] roudi_path: Option, #[clap(long)] @@ -118,9 +120,14 @@ fn main() -> eyre::Result<()> { Command::New { args } => template::create(args)?, Command::Dashboard => todo!(), Command::Up { + config, roudi_path, coordinator_path, - } => up::up(roudi_path.as_deref(), coordinator_path.as_deref())?, + } => up::up( + config.as_deref(), + roudi_path.as_deref(), + coordinator_path.as_deref(), + )?, Command::Start { dataflow } => start_dataflow(dataflow, &mut session)?, Command::List => list(&mut session)?, Command::Stop { uuid } => stop_dataflow(uuid, &mut session)?, diff --git a/binaries/cli/src/up.rs b/binaries/cli/src/up.rs index 80ddc628..c65cc56e 100644 --- a/binaries/cli/src/up.rs +++ b/binaries/cli/src/up.rs @@ -1,17 +1,49 @@ use crate::{check::coordinator_running, zenoh_control_session}; use dora_core::topics::ZENOH_CONTROL_DESTROY; use eyre::{bail, eyre, Context}; -use std::{path::Path, process::Command, sync::Arc}; +use std::{fs, path::Path, process::Command, sync::Arc}; use sysinfo::{ProcessExt, SystemExt}; use zenoh::{prelude::Receiver, sync::ZFuture}; -pub(crate) fn up(roudi: Option<&Path>, coordinator: Option<&Path>) -> eyre::Result<()> { +#[derive(Debug, serde::Serialize, serde::Deserialize)] +struct UpConfig { + iceoryx: bool, +} + +impl Default for UpConfig { + fn default() -> Self { + Self { iceoryx: true } + } +} + +pub(crate) fn up( + config_path: Option<&Path>, + roudi: Option<&Path>, + coordinator: Option<&Path>, +) -> eyre::Result<()> { + let config = { + let path = + config_path.or_else(|| Some(Path::new("dora-config.yml")).filter(|p| p.exists())); + match path { + Some(path) => { + let raw = fs::read_to_string(path) + .with_context(|| format!("failed to read `{}`", path.display()))?; + serde_yaml::from_str(&raw) + .with_context(|| format!("failed to parse `{}`", path.display()))? + } + None => Default::default(), + } + }; + let UpConfig { iceoryx } = config; + if !coordinator_running()? { start_coordinator(coordinator).wrap_err("failed to start dora-coordinator")?; } - // try to start roudi - start_roudi(roudi).wrap_err("failed to start iceoryx roudi daemon")?; + if iceoryx { + // try to start roudi + start_roudi(roudi).wrap_err("failed to start iceoryx roudi daemon")?; + } Ok(()) }