summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs45
1 files changed, 0 insertions, 45 deletions
diff --git a/src/main.rs b/src/main.rs
index edfcd44..1686680 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -10,7 +10,6 @@ use aur_build::review::{approve as ap, candidates, diff};
#[derive(Parser)]
#[command(name = "aur-build", version, about = "AUR build server: nothing is published that a human did not approve")]
struct Cli {
- /// Server root (holds config.json, db, mirrors, repo).
#[arg(short, long, env = "AUR_BUILD_ROOT", global = true)]
root: Option<PathBuf>,
#[command(subcommand)]
@@ -19,101 +18,68 @@ struct Cli {
#[derive(Subcommand)]
enum Cmd {
- /// Create the root, config and database.
Init {
#[arg(long)]
repo: Option<String>,
#[arg(long)]
signing_key: Option<String>,
},
- /// Start watching a pkgbase.
Subscribe {
pkgbase: String,
- /// Override the AUR URL; a `file://` path is fine, which is how the
- /// test suite drives the real binary.
#[arg(long)]
url: Option<String>,
},
- /// Stop watching a pkgbase.
Unsubscribe { pkgbase: String },
- /// Poll AUR now (without this, detection runs on the watcher's schedule).
Detect { pkgbase: Option<String> },
- /// List reviews.
Reviews {
#[arg(long)]
all: bool,
},
- /// Show one review: the diff panels and the two hashes an approval must echo.
Show { candidate: i64 },
- /// Approve a review. Without --yes this only prints what would be approved.
Approve {
candidate: i64,
#[arg(long)]
yes: bool,
#[arg(long)]
note: Option<String>,
- /// Approve against hashes you were shown earlier instead of re-rendering.
#[arg(long)]
identity: Option<String>,
#[arg(long)]
diff: Option<String>,
},
- /// Reject a review with a reason.
Reject {
candidate: i64,
#[arg(long)]
note: String,
},
- /// Queue a build for a pending review.
Build { candidate: i64 },
- /// Queue a rebuild of the currently accepted version (no new approval, I6).
Rebuild { pkgbase: String },
- /// Run a queued build to completion in this process.
Run { build: String },
- /// List builds.
Builds,
- /// Show a build's step timeline.
Status { build: String },
- /// Show the current index.
Packages,
- /// Run the web server and the watcher until interrupted.
Serve {
- /// Override the bind address, e.g. 127.0.0.1:8484.
#[arg(long)]
bind: Option<String>,
},
- /// Show recent audit rows.
Audit {
#[arg(long, default_value_t = 30)]
limit: i64,
},
- /// Print metrics in Prometheus text format (the same numbers /metrics serves).
Metrics,
- /// Drop the files of releases beyond the retention window, and sweep
- /// abandoned staging directories. Rows are never deleted (§15).
Gc {
- /// Versions per pkgbase whose files are kept. Defaults to the
- /// `retention_versions` setting.
#[arg(long)]
keep: Option<usize>,
- /// Show what would be removed without removing it.
#[arg(long)]
dry_run: bool,
},
- /// Write a consistent snapshot of the database with `VACUUM INTO`.
Backup {
- /// Destination file. It must not already exist: a backup that silently
- /// overwrites last week's backup is not a backup.
to: PathBuf,
},
}
fn main() -> anyhow::Result<()> {
let cli = Cli::parse();
- // `init` is the only command that runs before a config exists. For everything
- // else a missing config is an error, not a reason to invent one: the old
- // unconditional fallback turned a typo'd `--root` into a fresh empty server
- // at the wrong path.
let root = cli.root.clone().unwrap_or_else(|| Config::default().root);
let cfg = if matches!(cli.cmd, Cmd::Init { .. }) {
Config::load(&root).unwrap_or_else(|_| Config {
@@ -123,8 +89,6 @@ fn main() -> anyhow::Result<()> {
} else {
Config::load(&root)?
};
- // Startup, not first-build: a configuration that cannot work is refused
- // before the watcher, the dispatcher or the UI are up and looking healthy.
cfg.validate()?;
if let Cmd::Serve { bind } = &cli.cmd {
let mut cfg = cfg;
@@ -141,25 +105,18 @@ fn main() -> anyhow::Result<()> {
&cfg.arch,
&cfg.signing_key_id,
)?;
- // Re-materialize the served index from the DB: if a crash left the file
- // behind the database, close the gap before anyone asks for it.
let _ = pipeline::publish::reconcile(&cfg, &db);
let stop = std::sync::Arc::new(std::sync::atomic::AtomicBool::new(false));
aur_build::watch::scheduler::spawn_scheduler(std::sync::Arc::new(cfg.clone()), db.clone(), stop.clone());
let _server = aur_build::http::spawn(cfg.clone(), db.clone())?;
- // The dispatcher reaps expired leases before its first claim, so a restart
- // recovers whatever a crash left leased (§8.2).
let _pool = aur_build::pipeline::dispatch::Pool::spawn(std::sync::Arc::new(cfg.clone()), db.clone());
println!("serving on http://{} — ctrl-c to stop", cfg.bind);
- // Single process, thread per connection: the main thread has nothing to
- // do but wait to be killed.
loop {
std::thread::sleep(std::time::Duration::from_secs(3600));
}
}
let ctx = Ctx::open(&cfg)?;
match cli.cmd {
- // Handled above, before the CLI's own database context is opened.
Cmd::Serve { .. } => Ok(()),
Cmd::Init { repo, signing_key } => {
let mut cfg = cfg;
@@ -249,8 +206,6 @@ fn main() -> anyhow::Result<()> {
}
Cmd::Approve { candidate, yes, note, identity, diff: diff_arg } => {
let c = need_candidate(&ctx.db, candidate)?;
- // Render first, always: the hashes we send are the hashes of what we
- // just rendered, unless the operator explicitly names older ones.
let (text, digest) = diff::render_current(&ctx.db, &cfg, &c)?;
candidates::set_diff_digest(&ctx.db, c.id, &digest)?;
let identity = identity.unwrap_or_else(|| c.identity_hash.clone());