Skip to main content

max / makenotwork

1.6 KB · 49 lines History Blame Raw
1 //! Daemon-local config (`bento-daemon.toml`) — paths and listen address that
2 //! belong to the machine bentod runs on, not to the build matrix (which lives
3 //! in the separate topology file, see [`crate::topology`]).
4
5 use anyhow::{Context, Result};
6 use serde::Deserialize;
7 use std::path::PathBuf;
8
9 #[derive(Debug, Clone, Deserialize)]
10 pub struct Config {
11 pub listen: String,
12 pub db_path: PathBuf,
13 pub topology_path: PathBuf,
14 /// Root of the Syncthing private layer (`~/Code/_private`); the `secret()`
15 /// host function reads credential files relative to here. Never logged.
16 pub secrets_root: PathBuf,
17 /// Where collected artifacts land (`<dist_root>/<app>/<version>/`).
18 pub dist_root: PathBuf,
19 /// Root for per-step run logs
20 /// (`<logs_root>/<app>/<version>/<target>/<step>.log`).
21 #[serde(default = "default_logs_root")]
22 pub logs_root: PathBuf,
23 }
24
25 fn default_logs_root() -> PathBuf {
26 PathBuf::from("/srv/bento/logs")
27 }
28
29 impl Config {
30 pub fn load() -> Result<Self> {
31 let path = std::env::var("BENTO_CONFIG").unwrap_or_else(|_| "bento-daemon.toml".into());
32 let raw = std::fs::read_to_string(&path)
33 .with_context(|| format!("reading daemon config at {path}"))?;
34 Ok(toml::from_str(&raw)?)
35 }
36
37 #[cfg(test)]
38 pub fn for_tests(root: &std::path::Path) -> Self {
39 Self {
40 listen: "127.0.0.1:0".into(),
41 db_path: root.join("bento.db"),
42 topology_path: root.join("bento.toml"),
43 secrets_root: root.join("secrets"),
44 dist_root: root.join("dist"),
45 logs_root: root.join("logs"),
46 }
47 }
48 }
49