Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,18 @@ impl OciDir {
description: &str,
) {
let created = chrono::offset::Utc::now();
self.push_layer_full(manifest, config, layer, annotations, description, created)
self.push_layer_full(
manifest,
config,
layer,
annotations,
Some(description),
Some(created),
)
}

/// Add a layer to the top of the image stack with optional annotations and desired timestamp.
/// Add a layer to the top of the image stack with optional annotations, description and created.
/// If both description and created are omited no history entry is added.
///
/// This is otherwise equivalent to [`Self::push_layer_annotated`].
pub fn push_layer_full(
Expand All @@ -356,8 +364,8 @@ impl OciDir {
config: &mut oci_image::ImageConfiguration,
layer: Layer,
annotations: Option<impl Into<HashMap<String, String>>>,
description: &str,
created: chrono::DateTime<chrono::Utc>,
description: Option<&str>,
created: Option<chrono::DateTime<chrono::Utc>>,
) {
let mut builder = layer.descriptor();
if let Some(annotations) = annotations {
Expand All @@ -370,12 +378,17 @@ impl OciDir {
.diff_ids_mut()
.push(layer.uncompressed_sha256_as_digest().to_string());
config.set_rootfs(rootfs);
let h = oci_image::HistoryBuilder::default()
.created(created.to_rfc3339_opts(chrono::SecondsFormat::Secs, true))
.created_by(description.to_string())
.build()
.unwrap();
config.history_mut().push(h);

if description.is_some() || created.is_some() {
let mut hb = oci_image::HistoryBuilder::default();
if let Some(created) = created {
hb = hb.created(created.to_rfc3339_opts(chrono::SecondsFormat::Secs, true));
}
if let Some(description) = description {
hb = hb.created_by(description.to_string());
}
config.history_mut().push(hb.build().unwrap());
}
}

fn parse_descriptor_to_path(desc: &oci_spec::image::Descriptor) -> Result<PathBuf> {
Expand Down