difftreelog
feat prefetch command
in: trunk
3 files changed
cmds/fleet/src/cmds/build_systems.rsdiffbeforeafterboth120 "--json",120 "--json",121 // "--show-trace",121 // "--show-trace",122 "--no-link",122 "--no-link",123 "--option",124 "log-lines",125 "200",123 ])126 ])124 .comparg("--out-link", &built)127 .comparg("--out-link", &built)125 .arg(128 .arg(cmds/fleet/src/command.rsdiffbeforeafterboth--- a/cmds/fleet/src/command.rs
+++ b/cmds/fleet/src/command.rs
@@ -254,9 +254,12 @@
NixLog::Start { text, level: 1, typ: 111, .. } if text.starts_with("waiting for a machine to build ") => {
// Useless repeating notification about build
}
- NixLog::Start { text, level: 3, typ: 111, .. } if text.starts_with("resolved derivation: ") => {
+ NixLog::Start { text, level: 3, typ: 111, .. } if text.starts_with("resolved derivation: ") => {
// CA resolved
}
+ NixLog::Start { text, level: 1, typ: 111, .. } if text.starts_with("waiting for lock on ") => {
+ // Concurrent build of the same message
+ }
NixLog::Stop { .. } => {},
NixLog::Result { .. } => {},
_ => warn!("unknown log: {:?}", log)
cmds/fleet/src/main.rsdiffbeforeafterboth--- a/cmds/fleet/src/main.rs
+++ b/cmds/fleet/src/main.rs
@@ -5,23 +5,56 @@
mod fleetdata;
+use std::ffi::OsString;
use std::io;
-use anyhow::{anyhow, Result};
+use anyhow::{anyhow, bail, Result};
use clap::Parser;
use cmds::{build_systems::BuildSystems, info::Info, secrets::Secrets};
use host::{Config, FleetOpts};
+use tokio::fs;
+use tokio::process::Command;
use tracing::{info, metadata::LevelFilter};
use tracing_subscriber::EnvFilter;
#[derive(Parser)]
+struct Prefetch {}
+impl Prefetch {
+ async fn run(&self, config: &Config) -> Result<()> {
+ let mut prefetch_dir = config.directory.to_path_buf();
+ prefetch_dir.push("prefetch");
+ if !prefetch_dir.is_dir() {
+ info!("nothing to prefetch: no prefetch directory");
+ return Ok(());
+ }
+ for entry in std::fs::read_dir(&prefetch_dir)? {
+ let entry = entry?;
+ if !entry.metadata()?.is_file() {
+ bail!("only files should exist in prefetch directory");
+ }
+ info!("prefetching {:?}", entry.file_name());
+ let mut path = OsString::new();
+ path.push("file://");
+ path.push(entry.path());
+ let status = Command::new("nix-prefetch-url").arg(path).status().await?;
+ if !status.success() {
+ bail!("failed with {status}");
+ }
+ }
+ Ok(())
+ }
+}
+
+#[derive(Parser)]
enum Opts {
/// Prepare systems for deployments
BuildSystems(BuildSystems),
/// Secret management
#[clap(subcommand)]
Secrets(Secrets),
+ /// Upload prefetch directory to the nix store
+ Prefetch(Prefetch),
/// Config parsing
Info(Info),
}
@@ -40,6 +73,7 @@
Opts::BuildSystems(c) => c.run(config).await?,
Opts::Secrets(s) => s.run(config).await?,
Opts::Info(i) => i.run(config).await?,
+ Opts::Prefetch(p) => p.run(config).await?,
};
Ok(())
}