Skip to main content

bv_builder/
registry.rs

1use anyhow::Result;
2
3use crate::spec::ResolvedSpec;
4
5/// Snapshot of the repodata used during resolve, stored as an OCI artifact
6/// alongside the image using the OCI 1.1 referrers spec.
7///
8/// Media type: `application/vnd.bv.repodata.snapshot.v1+json`
9pub const REPODATA_SNAPSHOT_MEDIA_TYPE: &str = "application/vnd.bv.repodata.snapshot.v1+json";
10
11/// Produce a JSON snapshot of the channels + package pins used during resolve.
12/// This is pushed as an OCI referrer so that any future `bv-builder resolve`
13/// can reproduce the exact same `ResolvedSpec` without hitting live repodata.
14pub fn build_repodata_snapshot(resolved: &ResolvedSpec) -> Result<Vec<u8>> {
15    let snapshot = serde_json::json!({
16        "schema": "bv.repodata.snapshot.v1",
17        "name": resolved.name,
18        "version": resolved.version,
19        "platform": resolved.platform.to_string(),
20        "channels": resolved.channels,
21        "packages": resolved.packages.iter().map(|p| serde_json::json!({
22            "name": p.name,
23            "version": p.version,
24            "build": p.build,
25            "channel": p.channel,
26            "url": p.url,
27            "sha256": p.sha256,
28            "filename": p.filename,
29        })).collect::<Vec<_>>(),
30    });
31    Ok(serde_json::to_vec_pretty(&snapshot)?)
32}