difftreelog
feat prefetch command
in: trunk
3 files changed
cmds/fleet/src/cmds/build_systems.rsdiffbeforeafterboth--- a/cmds/fleet/src/cmds/build_systems.rs
+++ b/cmds/fleet/src/cmds/build_systems.rs
@@ -120,6 +120,9 @@
"--json",
// "--show-trace",
"--no-link",
+ "--option",
+ "log-lines",
+ "200",
])
.comparg("--out-link", &built)
.arg(
cmds/fleet/src/command.rsdiffbeforeafterboth254 NixLog::Start { text, level: 1, typ: 111, .. } if text.starts_with("waiting for a machine to build ") => {254 NixLog::Start { text, level: 1, typ: 111, .. } if text.starts_with("waiting for a machine to build ") => {255 // Useless repeating notification about build255 // Useless repeating notification about build256 }256 }257 NixLog::Start { text, level: 3, typ: 111, .. } if text.starts_with("resolved derivation: ") => {257 NixLog::Start { text, level: 3, typ: 111, .. } if text.starts_with("resolved derivation: ") => {258 // CA resolved258 // CA resolved259 }259 }260 NixLog::Start { text, level: 1, typ: 111, .. } if text.starts_with("waiting for lock on ") => {261 // Concurrent build of the same message262 }260 NixLog::Stop { .. } => {},263 NixLog::Stop { .. } => {},261 NixLog::Result { .. } => {},264 NixLog::Result { .. } => {},262 _ => warn!("unknown log: {:?}", log)265 _ => 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(())
}