Skip to content

Commit

Permalink
Merge pull request #375 from serpent-os/write-monitoring-template
Browse files Browse the repository at this point in the history
boulder: Write a monitoring.yaml file with boulder new
  • Loading branch information
ikeycode authored Jan 9, 2025
2 parents dfe12af + 81d90a4 commit 04ad263
Show file tree
Hide file tree
Showing 6 changed files with 290 additions and 23 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

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

46 changes: 34 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
[workspace]
members = [
"boulder",
"moss",
"crates/*",
]
default-members = [
"moss"
]
members = ["boulder", "moss", "crates/*"]
default-members = ["moss"]
resolver = "2"

[workspace.package]
Expand All @@ -23,9 +17,17 @@ clap_complete = "4.5.37"
clap_mangen = "0.2.24"
criterion = { version = "0.5.1", features = ["html_reports"] }
crossterm = "0.28.1"
derive_more = { version = "1.0.0", features = ["as_ref", "display", "from", "into"] }
derive_more = { version = "1.0.0", features = [
"as_ref",
"display",
"from",
"into",
] }
dialoguer = "0.11.0"
diesel = { version = "2.2.1", features = ["sqlite", "returning_clauses_for_sqlite_3_35"] }
diesel = { version = "2.2.1", features = [
"sqlite",
"returning_clauses_for_sqlite_3_35",
] }
diesel_migrations = "2.2.0"
dirs = "5.0.1"
elf = "0.7.4"
Expand All @@ -39,11 +41,31 @@ indextree = "4.6.1"
libsqlite3-sys = { version = "0.30.1", features = ["bundled"] }
log = "0.4.22"
nom = "7.1.3"
nix = { version = "0.27.1", features = ["user", "fs", "sched", "process", "mount", "hostname", "signal", "term"] }
nix = { version = "0.27.1", features = [
"user",
"fs",
"sched",
"process",
"mount",
"hostname",
"signal",
"term",
] }
petgraph = "0.6.5"
rayon = "1.10.0"
regex = "1.10.5"
reqwest = { version = "0.12.5", default-features = false, features = ["brotli", "charset", "deflate", "gzip", "http2", "rustls-tls", "stream", "zstd"] }
reqwest = { version = "0.12.5", default-features = false, features = [
"brotli",
"charset",
"deflate",
"gzip",
"http2",
"rustls-tls",
"stream",
"zstd",
"blocking",
"json",
] }
serde = { version = "1.0.204", features = ["derive"] }
serde_json = "1.0.120"
serde_yaml = "0.9.34"
Expand Down
1 change: 1 addition & 0 deletions boulder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ hex.workspace = true
itertools.workspace = true
nix.workspace = true
regex.workspace = true
reqwest.workspace = true
serde.workspace = true
serde_json.workspace = true
serde_yaml.workspace = true
Expand Down
23 changes: 14 additions & 9 deletions boulder/src/cli/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,7 @@ pub enum Subcommand {
},
#[command(about = "Create skeletal stone.yaml recipe from source archive URIs")]
New {
#[arg(
short,
long,
default_value = "./stone.yaml",
help = "Location to output generated build recipe"
)]
#[arg(short, long, default_value = ".", help = "Location to output generated files")]
output: PathBuf,
#[arg(required = true, value_name = "URI", help = "Source archive URIs")]
upstreams: Vec<Url>,
Expand Down Expand Up @@ -154,12 +149,20 @@ fn new(output: PathBuf, upstreams: Vec<Url>) -> Result<(), Error> {
// We use async to fetch upstreams
let _guard = runtime::init();

const RECIPE_FILE: &str = "stone.yaml";
const MONITORING_FILE: &str = "monitoring.yaml";

let drafter = Drafter::new(upstreams);
let recipe = drafter.run()?;
let draft = drafter.run()?;

if !output.is_dir() {
fs::create_dir_all(&output).map_err(Error::CreateDir)?;
}

fs::write(&output, recipe).map_err(Error::Write)?;
fs::write(PathBuf::from(&output).join(RECIPE_FILE), draft.stone).map_err(Error::Write)?;
fs::write(PathBuf::from(&output).join(MONITORING_FILE), draft.monitoring).map_err(Error::Write)?;

println!("Saved recipe to {output:?}");
println!("Saved {RECIPE_FILE} & {MONITORING_FILE} to {output:?}");

Ok(())
}
Expand Down Expand Up @@ -418,6 +421,8 @@ pub enum Error {
Read(#[source] io::Error),
#[error("writing recipe")]
Write(#[source] io::Error),
#[error("creating output directory")]
CreateDir(#[source] io::Error),
#[error("deserializing recipe")]
Deser(#[from] serde_yaml::Error),
#[error("fetch upstream")]
Expand Down
19 changes: 17 additions & 2 deletions boulder/src/draft.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,29 @@ use url::Url;
use crate::util;

use self::metadata::Metadata;
use self::monitoring::Monitoring;
use self::upstream::Upstream;

mod build;
mod metadata;
mod monitoring;
mod upstream;

pub struct Drafter {
upstreams: Vec<Url>,
}

pub struct Draft {
pub stone: String,
pub monitoring: String,
}

impl Drafter {
pub fn new(upstreams: Vec<Url>) -> Self {
Self { upstreams }
}

pub fn run(&self) -> Result<String, Error> {
pub fn run(&self) -> Result<Draft, Error> {
// TODO: Use tempdir
let extract_root = PathBuf::from("/tmp/boulder-new");

Expand All @@ -40,6 +47,9 @@ impl Drafter {
// Build metadata from extracted upstreams
let metadata = Metadata::new(extracted);

let monitoring = Monitoring::new(&metadata.source.name, &metadata.source.homepage);
let monitoring_result = monitoring.run()?;

// Enumerate all extracted files
let files = util::enumerate_files(&extract_root, |_| true)?
.into_iter()
Expand Down Expand Up @@ -96,7 +106,10 @@ license : UPDATE LICENSE
metadata.upstreams(),
);

Ok(template)
Ok(Draft {
stone: template,
monitoring: monitoring_result,
})
}
}

Expand Down Expand Up @@ -135,6 +148,8 @@ pub enum Error {
AnalyzeBuildSystem(#[source] build::Error),
#[error("upstream")]
Upstream(#[from] upstream::Error),
#[error("monitoring")]
Monitoring(#[from] monitoring::Error),
#[error("io")]
Io(#[from] io::Error),
}
Expand Down
Loading

0 comments on commit 04ad263

Please sign in to comment.