Skip to content

Commit 20bf086

Browse files
committed
ostree-ext: make OCI history reproducible
OciDir push_layer() calls push_layer_full() with created = chrono::offset::Utc::now() Signed-off-by: Etienne Champetier <e.champetier@ateme.com>
1 parent 9698500 commit 20bf086

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

ostree-ext/src/container/encapsulate.rs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,21 +133,34 @@ pub(crate) fn export_chunked(
133133
.uncompressed_sha256
134134
.clone();
135135

136+
let created = imgcfg
137+
.created()
138+
.as_deref()
139+
.and_then(bootc_utils::try_deserialize_timestamp)
140+
.unwrap_or_default();
136141
// Add the ostree layer
137-
ociw.push_layer(manifest, imgcfg, ostree_layer, description, None);
142+
ociw.push_layer_full(
143+
manifest,
144+
imgcfg,
145+
ostree_layer,
146+
None::<HashMap<String, String>>,
147+
description,
148+
created,
149+
);
138150
// Add the component/content layers
139151
let mut buf = [0; 8];
140152
let sep = COMPONENT_SEPARATOR.encode_utf8(&mut buf);
141153
for (layer, name, mut packages) in layers {
142154
let mut annotation_component_layer = HashMap::new();
143155
packages.sort();
144156
annotation_component_layer.insert(CONTENT_ANNOTATION.to_string(), packages.join(sep));
145-
ociw.push_layer(
157+
ociw.push_layer_full(
146158
manifest,
147159
imgcfg,
148160
layer,
149-
name.as_str(),
150161
Some(annotation_component_layer),
162+
name.as_str(),
163+
created,
151164
);
152165
}
153166

ostree-ext/src/container/store.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,12 +1490,22 @@ pub(crate) fn export_to_oci(
14901490
.get(i)
14911491
.and_then(|h| h.comment().as_deref())
14921492
.unwrap_or_default();
1493-
dest_oci.push_layer(
1493+
1494+
let previous_created = srcinfo
1495+
.configuration
1496+
.history()
1497+
.get(i)
1498+
.and_then(|h| h.created().as_deref())
1499+
.and_then(bootc_utils::try_deserialize_timestamp)
1500+
.unwrap_or_default();
1501+
1502+
dest_oci.push_layer_full(
14941503
&mut new_manifest,
14951504
&mut new_config,
14961505
layer,
1497-
previous_description,
14981506
previous_annotations,
1507+
previous_description,
1508+
previous_created,
14991509
)
15001510
}
15011511

ostree-ext/src/fixture.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use ocidir::cap_std::fs::{DirBuilder, DirBuilderExt as _};
2626
use ocidir::oci_spec::image::ImageConfigurationBuilder;
2727
use regex::Regex;
2828
use std::borrow::Cow;
29+
use std::collections::HashMap;
2930
use std::ffi::CString;
3031
use std::fmt::Write as _;
3132
use std::io::{self, Write};
@@ -1014,8 +1015,20 @@ impl NonOstreeFixture {
10141015
let bw = bw.into_inner()?;
10151016
let new_layer = bw.complete()?;
10161017

1017-
self.src_oci
1018-
.push_layer(&mut manifest, &mut config, new_layer, "root", None);
1018+
let created = config
1019+
.created()
1020+
.as_deref()
1021+
.and_then(bootc_utils::try_deserialize_timestamp)
1022+
.unwrap_or_default();
1023+
1024+
self.src_oci.push_layer_full(
1025+
&mut manifest,
1026+
&mut config,
1027+
new_layer,
1028+
None::<HashMap<String, String>>,
1029+
"root",
1030+
created,
1031+
);
10191032
let config = self.src_oci.write_config(config)?;
10201033

10211034
manifest.set_config(config);

0 commit comments

Comments
 (0)