Skip to content
This repository has been archived by the owner on Nov 7, 2024. It is now read-only.

Commit

Permalink
encapsulate: Add annotation to individual OCI layers
Browse files Browse the repository at this point in the history
Annotation contains `Content` field which has a list
packages contained within each layer respectfully
  • Loading branch information
RishabhSaini committed Apr 17, 2023
1 parent 8d4f939 commit 6c3460a
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
2 changes: 2 additions & 0 deletions lib/src/chunking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ pub(crate) struct Chunk {
pub(crate) name: String,
pub(crate) content: ChunkMapping,
pub(crate) size: u64,
pub(crate) packages: Vec<String>,
}

#[derive(Debug, Deserialize, Serialize)]
Expand Down Expand Up @@ -312,6 +313,7 @@ impl Chunking {
n => Cow::Owned(format!("{n} components")),
};
let mut chunk = Chunk::new(&*name);
chunk.packages = bin.iter().map(|v| String::from(&*v.meta.name)).collect();
for szmeta in bin {
for &obj in rmap.get(&szmeta.meta.identifier).unwrap() {
self.remainder.move_obj(&mut chunk, obj.as_str());
Expand Down
26 changes: 21 additions & 5 deletions lib/src/container/encapsulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ fn export_chunks(
ociw: &mut OciDir,
chunks: Vec<Chunk>,
opts: &ExportOpts,
) -> Result<Vec<(Layer, String)>> {
) -> Result<Vec<(Layer, String, Vec<String>)>> {
chunks
.into_iter()
.enumerate()
Expand All @@ -111,7 +111,7 @@ fn export_chunks(
ostree_tar::export_chunk(repo, commit, chunk.content, &mut w)
.with_context(|| format!("Exporting chunk {i}"))?;
let w = w.into_inner()?;
Ok((w.complete()?, chunk.name))
Ok((w.complete()?, chunk.name, chunk.packages))
})
.collect()
}
Expand Down Expand Up @@ -155,10 +155,26 @@ fn export_chunked(
.clone();

// Add the ostree layer
ociw.push_layer(manifest, imgcfg, ostree_layer, description);
let mut annotation_ostree_layer = HashMap::new();
annotation_ostree_layer.insert("Content".to_string(), "ostree_commit".to_string());
ociw.push_layer(
manifest,
imgcfg,
ostree_layer,
description,
Some(annotation_ostree_layer),
);
// Add the component/content layers
for (layer, name) in layers {
ociw.push_layer(manifest, imgcfg, layer, name.as_str());
for (layer, name, packages) in layers {
let mut annotation_component_layer = HashMap::new();
annotation_component_layer.insert("Content".to_string(), packages.join(","));
ociw.push_layer(
manifest,
imgcfg,
layer,
name.as_str(),
Some(annotation_component_layer),
);
}
// This label (mentioned above) points to the last layer that is part of
// the ostree commit.
Expand Down
2 changes: 1 addition & 1 deletion lib/src/container/ocidir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ impl OciDir {
config: &mut oci_image::ImageConfiguration,
layer: Layer,
description: &str,
annotations: Option<HashMap<String, String>>,
) {
let annotations: Option<HashMap<String, String>> = None;
self.push_layer_annotated(manifest, config, layer, annotations, description);
}

Expand Down

0 comments on commit 6c3460a

Please sign in to comment.