Produce a two-layer OCI image: a base layer (the `base_view` materialized) plus a thin delta layer (files that differ on `view` versus `base_view`, with whiteouts for files removed on `view`). Built for the inner loop: the base is content-addressed by its `diff_id` and can be pulled once and cached, so each iteration ships only the small delta. Provenance (view names and Merkle states) is recorde
(&self, opts: StageOptions)
| 499 | /// delta. Provenance (view names and Merkle states) is recorded in the |
| 500 | /// manifest annotations. Returns the manifest digest and base `diff_id`. |
| 501 | pub fn stage(&self, opts: StageOptions) -> Result<StageResult, RepositoryError> { |
| 502 | // Resolve both snapshots before creating output state. Each snapshot |
| 503 | // builds and validates its view closure once. |
| 504 | let base_files = self.materialized_view_files(&opts.base_view)?; |
| 505 | let view_files = self.materialized_view_files(&opts.view)?; |
| 506 | |
| 507 | // 1. Base layer: materialize the shared base view to a temp dir. |
| 508 | let base_dir = tempfile::tempdir()?; |
| 509 | Self::write_materialized_files(base_dir.path(), &base_files)?; |
| 510 | let base_layer = oci::layer_from_dir(base_dir.path())?; |
| 511 | let base_diff_id = base_layer.diff_id.clone(); |
| 512 | |
| 513 | // 2. Delta: files new or changed on `view` vs. `base_view`, plus |
| 514 | // whiteouts for files present on the base but gone on `view`. |
| 515 | let mut changed: Vec<(String, Vec<u8>)> = Vec::new(); |
| 516 | for (path, view_bytes) in &view_files { |
| 517 | if base_files.get(path) != Some(view_bytes) { |
| 518 | changed.push((path.clone(), view_bytes.clone())); |
| 519 | } |
| 520 | } |
| 521 | |
| 522 | let mut whiteouts: Vec<String> = Vec::new(); |
| 523 | for path in base_files.keys() { |
| 524 | if !view_files.contains_key(path) { |
| 525 | whiteouts.push(path.clone()); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | let delta_files = changed.len(); |
| 530 | let delta_layer = oci::layer_from_entries(&changed, &whiteouts)?; |
| 531 | |
| 532 | // 3. Assemble the layout with provenance annotations. |
| 533 | let view_info = self.get_view_info(&opts.view)?; |
| 534 | let base_info = self.get_view_info(&opts.base_view)?; |
| 535 | let mut annotations = BTreeMap::new(); |
| 536 | annotations.insert("org.atomic.view".to_string(), opts.view.clone()); |
| 537 | annotations.insert("org.atomic.base-view".to_string(), opts.base_view.clone()); |
| 538 | annotations.insert( |
| 539 | "org.atomic.view-merkle".to_string(), |
| 540 | view_info.state_base32(), |
| 541 | ); |
| 542 | annotations.insert( |
| 543 | "org.atomic.base-merkle".to_string(), |
| 544 | base_info.state_base32(), |
| 545 | ); |
| 546 | |
| 547 | let config = OciImageConfig { |
| 548 | architecture: oci::host_arch(), |
| 549 | os: "linux".to_string(), |
| 550 | env: Vec::new(), |
| 551 | entrypoint: Vec::new(), |
| 552 | annotations, |
| 553 | }; |
| 554 | |
| 555 | let manifest_digest = |
| 556 | oci::write_image_layout(&opts.out, &[base_layer, delta_layer], &config)?; |
| 557 | |
| 558 | Ok(StageResult { |