Skip to content

Commit 55bd808

Browse files
committed
ostree/encapsulate: Support overriding platform (arch)
Currently the encapsulate code assumes it's generating images that match the platform (os+arch) that's running. However, for rpm-ostree we have a use case of performing "rechunking" in a cross-architecture fashion. In the end we don't run any code in that process, it's just manipulating bits, so it's perfectly fine to operate cross-arch. Allow passing in an override for the generated image platform to facilitate this. Signed-off-by: Colin Walters <[email protected]>
1 parent 13f3cb5 commit 55bd808

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

ostree-ext/src/container/encapsulate.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ fn build_oci(
191191

192192
let mut ctrcfg = opts.container_config.clone().unwrap_or_default();
193193
let mut imgcfg = oci_image::ImageConfiguration::default();
194+
// If a platform was provided, propagate it to the config
195+
if let Some(platform) = opts.platform.as_ref() {
196+
imgcfg.set_architecture(platform.architecture().clone());
197+
imgcfg.set_os(platform.os().clone());
198+
}
194199

195200
let created_at = opts
196201
.created
@@ -269,6 +274,13 @@ fn build_oci(
269274
ctrcfg.set_cmd(Some(cmd.clone()));
270275
}
271276

277+
// Our platform uses the image config
278+
let platform = oci_image::PlatformBuilder::default()
279+
.architecture(imgcfg.architecture().clone())
280+
.os(imgcfg.os().clone())
281+
.build()
282+
.unwrap();
283+
272284
ctrcfg
273285
.labels_mut()
274286
.get_or_insert_with(Default::default)
@@ -277,7 +289,7 @@ fn build_oci(
277289
let ctrcfg = writer.write_config(imgcfg)?;
278290
manifest.set_config(ctrcfg);
279291
manifest.set_annotations(Some(labels));
280-
let platform = oci_image::Platform::default();
292+
281293
if let Some(tag) = tag {
282294
writer.insert_manifest(manifest, Some(tag), platform)?;
283295
} else {
@@ -383,6 +395,8 @@ pub struct ExportOpts<'m, 'o> {
383395
pub legacy_version_label: bool,
384396
/// Image runtime configuration that will be used as a base
385397
pub container_config: Option<oci_image::Config>,
398+
/// Override the default platform
399+
pub platform: Option<oci_image::Platform>,
386400
/// A reference to the metadata for a previous build; used to optimize
387401
/// the packing structure.
388402
pub prior_build: Option<&'m oci_image::ImageManifest>,

0 commit comments

Comments
 (0)