diff --git a/src/lib.rs b/src/lib.rs index 95461b2..d34f2f0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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( @@ -356,8 +364,8 @@ impl OciDir { config: &mut oci_image::ImageConfiguration, layer: Layer, annotations: Option>>, - description: &str, - created: chrono::DateTime, + description: Option<&str>, + created: Option>, ) { let mut builder = layer.descriptor(); if let Some(annotations) = annotations { @@ -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 {