Skip to content

Commit

Permalink
lib: Add an API to write layers with timestamps
Browse files Browse the repository at this point in the history
I didn't have an immediate use case, I was just reading
the code for unrelated reasons and noticed this.

But I'm sure we'd want this for reproducible builds.

Signed-off-by: Colin Walters <walters@verbum.org>
  • Loading branch information
cgwalters committed Aug 1, 2024
1 parent ec96b90 commit 27cba61
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,22 @@ impl OciDir {
layer: Layer,
annotations: Option<impl Into<HashMap<String, String>>>,
description: &str,
) {
let created = chrono::offset::Utc::now();
self.push_layer_full(manifest, config, layer, annotations, description, created)
}

/// Add a layer to the top of the image stack with optional annotations and desired timestamp.
///
/// This is otherwise equivalent to [`Self::push_layer_annotated`].
pub fn push_layer_full(
&self,
manifest: &mut oci_image::ImageManifest,
config: &mut oci_image::ImageConfiguration,
layer: Layer,
annotations: Option<impl Into<HashMap<String, String>>>,
description: &str,
created: chrono::DateTime<chrono::Utc>,
) {
let mut builder = layer.descriptor().media_type(MediaType::ImageLayerGzip);
if let Some(annotations) = annotations {
Expand All @@ -287,9 +303,8 @@ impl OciDir {
.diff_ids_mut()
.push(format!("{SHA256_NAME}:{}", layer.uncompressed_sha256));
config.set_rootfs(rootfs);
let now = chrono::offset::Utc::now();
let h = oci_image::HistoryBuilder::default()
.created(now.to_rfc3339_opts(chrono::SecondsFormat::Secs, true))
.created(created.to_rfc3339_opts(chrono::SecondsFormat::Secs, true))
.created_by(description.to_string())
.build()
.unwrap();
Expand Down

0 comments on commit 27cba61

Please sign in to comment.