diff options
Diffstat (limited to 'src/pipeline/mod.rs')
| -rw-r--r-- | src/pipeline/mod.rs | 23 |
1 files changed, 23 insertions, 0 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; |
