summaryrefslogtreecommitdiffstats
path: root/src/pipeline
diff options
context:
space:
mode:
authoraur-build <aur-build@localhost>2026-11-18 22:34:16 +0000
committeraur-build <aur-build@localhost>2026-11-18 22:34:16 +0000
commit632a08c8543f0db533efc7bfb6728b50a77ae3d8 (patch)
tree318fb224b15d09913e1111b8cdb80d9c578a8995 /src/pipeline
parent8835a0a86c82d922a2d674f3543c331dc9adb9e5 (diff)
downloadaur-build-632a08c8543f0db533efc7bfb6728b50a77ae3d8.tar.gz
aur-build-632a08c8543f0db533efc7bfb6728b50a77ae3d8.zip
sandbox: the seam between the pipeline and where build code runs
The step machine spawned its own subprocesses, which quietly made "build code runs on this machine, inside a devtools chroot, under §14's sudo rules" a pipeline fact rather than a deployment fact. Every build subprocess now goes through SandboxBackend: acquire a lease, run argv shaped commands (never a shell string), move content-addressed blobs, destroy. The loopback backend is today's behavior wearing the interface - same child_env shim protocol, same captured output - which is why the shim suite passes untouched: a step that cannot tell loopback from a remote sandbox is the property under test.
Diffstat (limited to 'src/pipeline')
-rw-r--r--src/pipeline/mod.rs23
-rw-r--r--src/pipeline/steps.rs56
2 files changed, 55 insertions, 24 deletions
diff --git a/src/pipeline/mod.rs b/src/pipeline/mod.rs
index bd37258..5e0a823 100644
--- a/src/pipeline/mod.rs
+++ b/src/pipeline/mod.rs
@@ -10,12 +10,15 @@ pub mod dispatch;
mod steps;
use std::path::PathBuf;
+use std::sync::Arc;
+use std::time::Duration;
use crate::config::Config;
use crate::db::{self, builds, Db, Pkgbase};
use crate::db::model::*;
use crate::db::SnapshotRow;
use crate::error::{Error, Result};
+use crate::sandbox::{Sandbox, SandboxBackend};
/// The approved source identity a build must reproduce.
///
@@ -120,6 +123,9 @@ pub struct Ctx {
pub log: PathBuf,
pub profile: String,
pub attempt: i64,
+ /// Where build code runs. Defaults to the loopback backend (§8, sandbox
+ /// seam); the pipeline itself never spawns a build subprocess directly.
+ pub backend: Arc<dyn SandboxBackend>,
}
impl Ctx {
@@ -165,9 +171,26 @@ impl Ctx {
log: cfg.build_log_path(build_id),
profile,
attempt,
+ backend: Arc::new(crate::sandbox::loopback::LoopbackBackend::new(cfg)),
})
}
+ /// Lease a sandbox for this build's profile. Today every step acquires and
+ /// releases around itself; a remote backend will hold one sandbox across
+ /// the sandbox-bearing steps of a build, and steps stay idempotent either
+ /// way (I5). The TTL is the lease window: a sandbox that outlives it is
+ /// assumed dead, which is exactly what the reaper already concludes about
+ /// an expired build lease.
+ pub fn sandbox(&self) -> Result<Arc<dyn Sandbox>> {
+ let spec = crate::sandbox::SandboxSpec {
+ profile: self.profile.clone(),
+ task: self.build.id.clone(),
+ ttl: Duration::from_secs(self.cfg.lease_secs.max(1) as u64),
+ disk_mb: self.cfg.min_free_disk_mb,
+ };
+ self.backend.acquire(&spec)
+ }
+
/// Append to the build log; the SSE tail reads this file (§12).
pub fn log_line(&self, line: &str) {
use std::io::Write;
diff --git a/src/pipeline/steps.rs b/src/pipeline/steps.rs
index 7187e13..98089ca 100644
--- a/src/pipeline/steps.rs
+++ b/src/pipeline/steps.rs
@@ -4,12 +4,12 @@
//! the long-running child process happens outside any transaction (§11a).
use std::path::Path;
-use std::process::Command;
use crate::db::{self, builds, model::*};
use crate::error::{Error, Result};
use crate::git;
use crate::pipeline::{Collect, CollectedPkg, Ctx, StepResult};
+use crate::sandbox::Cmd;
use crate::watch::digests::cached_path;
pub fn run_step(ctx: &Ctx, step: &str) -> Result<StepResult> {
@@ -119,12 +119,12 @@ fn chroot(ctx: &Ctx) -> Result<StepResult> {
let seed = ctx.cfg.chroot_seed(&ctx.profile);
if !seed.exists() {
std::fs::create_dir_all(seed.parent().unwrap_or(&ctx.cfg.chroot_dir()))?;
- let mut cmd = Command::new(&ctx.cfg.mkarchroot_bin);
// Real devtools usage: `mkarchroot [options] <working-dir> <packages...>`.
- cmd.arg(&seed).args(&ctx.cfg.mkarchroot_args);
- ctx.cfg.child_env(&mut cmd);
- let out = cmd.output()?;
- if !out.status.success() {
+ let mut argv = vec![ctx.cfg.mkarchroot_bin.clone(), seed.display().to_string()];
+ argv.extend(ctx.cfg.mkarchroot_args.iter().cloned());
+ let sbx = ctx.sandbox()?;
+ let out = sbx.run(&Cmd::new(argv), &mut |_| {})?;
+ if !out.success() {
return Err(Error::Subprocess {
cmd: ctx.cfg.mkarchroot_bin.clone(),
detail: String::from_utf8_lossy(&out.stderr).into_owned(),
@@ -187,11 +187,10 @@ fn pkgver(ctx: &Ctx) -> Result<StepResult> {
}
return Ok(StepResult::Skipped("no VCS sources; pkgver is static".into()));
}
- let mut cmd = Command::new(&ctx.cfg.makepkg_bin);
- cmd.current_dir(&ctx.srcdir).arg("--vercheck");
- ctx.cfg.child_env(&mut cmd);
- let out = cmd.output()?;
- if !out.status.success() {
+ let cmd = vec![ctx.cfg.makepkg_bin.clone(), "--vercheck".to_string()];
+ let sbx = ctx.sandbox()?;
+ let out = sbx.run(&Cmd::new(cmd).in_dir(&ctx.srcdir), &mut |_| {})?;
+ if !out.success() {
return Err(Error::Subprocess {
cmd: ctx.cfg.makepkg_bin.clone(),
detail: String::from_utf8_lossy(&out.stderr).into_owned(),
@@ -216,25 +215,34 @@ fn pkgver(ctx: &Ctx) -> Result<StepResult> {
/// the file the SSE tail reads.
fn build(ctx: &Ctx) -> Result<StepResult> {
let seed = ctx.cfg.chroot_seed(&ctx.profile);
- let mut cmd = Command::new(&ctx.cfg.makechrootpkg_bin);
- cmd.current_dir(&ctx.srcdir);
- cmd.args(["-c", "-r", &seed.display().to_string(), "--"]);
+ let mut argv = vec![
+ ctx.cfg.makechrootpkg_bin.clone(),
+ "-c".into(),
+ "-r".into(),
+ seed.display().to_string(),
+ "--".into(),
+ ];
if !ctx.cfg.signing_key_id.is_empty() {
- cmd.arg(format!("-si{}", ctx.cfg.signing_key_id));
+ argv.push(format!("-si{}", ctx.cfg.signing_key_id));
}
- cmd.arg("-f");
- ctx.cfg.child_env(&mut cmd);
- let out = cmd.output()?;
- // Capture the child's output into the build log regardless of outcome.
+ argv.push("-f".into());
+ // Capture the child's output into the build log regardless of outcome —
+ // the sandbox streams it here as it arrives, and the SSE tail reads the
+ // same file.
if let Some(parent) = ctx.log.parent() {
let _ = std::fs::create_dir_all(parent);
}
use std::io::Write;
- if let Ok(mut f) = std::fs::OpenOptions::new().create(true).append(true).open(&ctx.log) {
- let _ = f.write_all(&out.stdout);
- let _ = f.write_all(&out.stderr);
- }
- if !out.status.success() {
+ let mut log_file = std::fs::OpenOptions::new().create(true).append(true).open(&ctx.log).ok();
+ let mut on_log = move |bytes: &[u8]| {
+ if let Some(f) = log_file.as_mut() {
+ let _ = f.write_all(bytes);
+ }
+ };
+ let sbx = ctx.sandbox()?;
+ let out = sbx.run(&Cmd::new(argv).in_dir(&ctx.srcdir), &mut on_log)?;
+ drop(on_log); // closes the log file before the outcome is recorded
+ if !out.success() {
return Err(Error::Subprocess {
cmd: ctx.cfg.makechrootpkg_bin.clone(),
detail: tail(&out.stderr),