diff options
Diffstat (limited to 'src/pipeline')
| -rw-r--r-- | src/pipeline/steps.rs | 147 |
1 files changed, 115 insertions, 32 deletions
diff --git a/src/pipeline/steps.rs b/src/pipeline/steps.rs index 89c01f2..c989476 100644 --- a/src/pipeline/steps.rs +++ b/src/pipeline/steps.rs @@ -16,7 +16,7 @@ pub fn run_step(ctx: &Ctx, step: &str) -> Result<StepResult> { match step { "materialize" => materialize(ctx), "plan" => plan(ctx), - "chroot" => chroot(ctx), + "chroot" => provision(ctx), "sources" => sources(ctx), "pkgver" => pkgver(ctx), "build" => build(ctx), @@ -113,26 +113,115 @@ fn plan(ctx: &Ctx) -> Result<StepResult> { Ok(StepResult::Done(Some(hash))) } -/// Step 2 — warm chroot seed, created once per profile and never mutated; each -/// build gets a copy-on-write snapshot from it (§8.3). -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()))?; - // Real devtools usage: `mkarchroot [options] <working-dir> <packages...>`. - 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(), - }); +/// Step 2 — provision the sandbox with the pinned lease set. +/// +/// The devtools chroot is gone: the sandbox boots from a base that already +/// carries the official packages, and everything *we* publish that this build +/// needs arrives as content-addressed blobs installed with `pacman -U`. The +/// step id stays `chroot` in the checkpoint table — the DB does not care what +/// the string means, and renaming would strand every existing checkpoint row. +/// +/// Nothing is resolved at build time: the lease manifest is the plan, every +/// blob is re-hashed before it is staged, and the sandbox's own `pacman -Q` +/// must confirm the pinned world actually landed. A byte that hashes to +/// something else, or a world that drifted, fails the build closed. +fn provision(ctx: &Ctx) -> Result<StepResult> { + let lease = lease_manifest(ctx)?; + if lease.is_empty() { + return Ok(StepResult::Skipped("no of-our-packages dependencies to install".into())); + } + let sbx = ctx.sandbox()?; + for e in &lease { + let path = ctx.cfg.store_path(&e.digest); + // The hub hashes what it sends: store corruption is caught here, not + // discovered by a confused package manager inside the sandbox. + let (digest, _) = crate::hash::digest_file(&path)?; + if digest != e.digest { + return Err(Error::fail_closed(format!( + "lease artifact {}-{}: store bytes hash to {digest} but the index says {}", + e.name, e.version, e.digest + ))); } - ctx.log_line(&format!(" created chroot seed {}", seed.display())); + let mut f = std::fs::File::open(&path)?; + sbx.put(&e.digest, &mut f)?; } - Ok(StepResult::Done(Some(seed.display().to_string()))) + let mut argv = vec![ctx.cfg.pacman_bin.clone(), "-U".into(), "--noconfirm".into()]; + argv.extend(lease.iter().map(|e| format!("blob:{}", e.digest))); + let out = sbx.run(&Cmd::new(argv), &mut |_| {})?; + if !out.success() { + return Err(Error::fail_closed(format!( + "{} -U refused the lease set: {}", + ctx.cfg.pacman_bin, + tail(&out.stderr) + ))); + } + // Fail-closed world check: every pinned entry must be present in the + // sandbox at exactly the pinned version. The world we approved is the + // world we build in, or nothing. + let q = sbx.run(&Cmd::new(vec![ctx.cfg.pacman_bin.clone(), "-Q".into()]), &mut |_| {})?; + if !q.success() { + return Err(Error::fail_closed(format!( + "{} -Q failed: {}", + ctx.cfg.pacman_bin, + tail(&q.stderr) + ))); + } + let installed: std::collections::BTreeSet<(String, String)> = String::from_utf8_lossy(&q.stdout) + .lines() + .filter_map(|l| { + let mut it = l.split_whitespace(); + let (name, ver) = (it.next()?, it.next()?); + Some((name.to_string(), ver.to_string())) + }) + .collect(); + for e in &lease { + if !installed.contains(&(e.name.clone(), e.version.clone())) { + return Err(Error::fail_closed(format!( + "sandbox world is missing {}-{} after installing the lease set", + e.name, e.version + ))); + } + } + ctx.log_line(&format!( + " provisioned {} pinned package(s): {}", + lease.len(), + lease.iter().map(|e| format!("{}-{}", e.name, e.version)).collect::<Vec<_>>().join(", ") + )); + let world: Vec<(&str, &str)> = lease.iter().map(|e| (e.name.as_str(), e.version.as_str())).collect(); + Ok(StepResult::Done(Some(crate::hash::canonical_json(&world)?))) +} + +/// One pinned entry of the lease manifest. +#[derive(Debug, Clone)] +struct LeasePkg { + name: String, + version: String, + digest: String, +} + +/// The lease manifest: every dependency this build needs that we publish, +/// pinned to the exact version and digest of the artifact we serve. Official +/// packages are the base image's business — they arrive with the sandbox, and +/// pinning them is the hub's official-repo cache, not this step. Anything +/// unresolvable here would have been `plan()`'s problem (blocked, not built). +fn lease_manifest(ctx: &Ctx) -> Result<Vec<LeasePkg>> { + let recipe = recipe_at(&ctx.srcdir)?; + let mut wanted: Vec<String> = Vec::new(); + for list in [&recipe.depends, &recipe.makedepends, &recipe.checkdepends] { + wanted.extend(crate::pkgver::dep_names(list)); + } + wanted.sort(); + wanted.dedup(); + let mut out = Vec::new(); + for dep in wanted { + if dep == ctx.pb.name || recipe.pkgnames.contains(&dep) { + continue; // this build's own output is not its own dependency + } + if let Some((version, digest)) = db::index_artifact(&ctx.db, &dep)? { + out.push(LeasePkg { name: dep, version, digest }); + } + } + Ok(out) } /// Step 3 — make sure every source we reviewed is on disk and hashes to what the @@ -211,19 +300,13 @@ fn pkgver(ctx: &Ctx) -> Result<StepResult> { Ok(StepResult::Done(Some(text))) } -/// Step 5 — `makechrootpkg -c -r <chroot> -- -f`, with the log going to the -/// file the SSE tail reads. No `-si`: the build environment never holds the -/// signing key — packages are signed hub-side at ingest. +/// Step 5 — `makepkg -c -f` in the provisioned sandbox, with the log going to +/// the file the SSE tail reads. No `-s`: the lease set is already installed, +/// and a build that resolves dependencies at build time is exactly what the +/// pinning model forbids. No `-si`: the sandbox never holds the signing key; +/// ingest signs hub-side. fn build(ctx: &Ctx) -> Result<StepResult> { - let seed = ctx.cfg.chroot_seed(&ctx.profile); - let argv = vec![ - ctx.cfg.makechrootpkg_bin.clone(), - "-c".into(), - "-r".into(), - seed.display().to_string(), - "--".into(), - "-f".into(), - ]; + let argv = vec![ctx.cfg.makepkg_bin.clone(), "-c".into(), "-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. @@ -242,7 +325,7 @@ fn build(ctx: &Ctx) -> Result<StepResult> { 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(), + cmd: ctx.cfg.makepkg_bin.clone(), detail: tail(&out.stderr), }); } |
