Skip to content

Commit 896c4dc

Browse files
committed
feat: --previous-build-manifest option for build-chunked-oci
This allows for build-chunked-oci to take into account a previous build manifest without having to download the previous build's image into local storage. Signed-off-by: Daniel Hast <hast.daniel@protonmail.com>
1 parent 654e6ee commit 896c4dc

File tree

1 file changed

+23
-7
lines changed

1 file changed

+23
-7
lines changed

rust/src/compose.rs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ pub(crate) struct BuildChunkedOCIOpts {
228228
/// it works to use over 200 layers.
229229
max_layers: Option<NonZeroU32>,
230230

231+
/// Prevent a change in packing structure by taking a previous build metadata (oci config and
232+
/// manifest)
233+
#[clap(long)]
234+
previous_build_manifest: Option<Utf8PathBuf>,
235+
231236
/// Tag to use for output image, or `latest` if unset.
232237
#[clap(long, default_value = "latest")]
233238
reference: String,
@@ -324,7 +329,11 @@ impl BuildChunkedOCIOpts {
324329
// Ensure we're in the proper namespace for container operations
325330
crate::containers_storage::reexec_if_needed()?;
326331

327-
let existing_manifest = self.check_existing_image(&self.output)?;
332+
let existing_manifest = if self.previous_build_manifest.is_some() {
333+
None
334+
} else {
335+
self.check_existing_image(&self.output)?
336+
};
328337

329338
let rootfs_source = if let Some(rootfs) = self.rootfs {
330339
FileSource::Rootfs(rootfs)
@@ -438,6 +447,14 @@ impl BuildChunkedOCIOpts {
438447
};
439448
let manifest_data = manifest_data_tmpfile.as_ref().map(|t| t.path());
440449

450+
// Use provided build manifest if provided, otherwise use manifest of chunked image
451+
// already at target location if present.
452+
let manifest_path = self
453+
.previous_build_manifest
454+
.as_ref()
455+
.map(|m| m.as_os_str())
456+
.or_else(|| manifest_data.map(|m| m.as_os_str()));
457+
441458
let st = crate::isolation::self_command()
442459
.args([
443460
"compose",
@@ -456,12 +473,11 @@ impl BuildChunkedOCIOpts {
456473
.flat_map(|c| [OsStr::new("--image-config"), c.as_os_str()]),
457474
)
458475
.args([commitid.as_str(), self.output.as_str()])
459-
.args(manifest_data.as_ref().iter().flat_map(|manifest| {
460-
[
461-
OsStr::new("--previous-build-manifest"),
462-
manifest.as_os_str(),
463-
]
464-
}))
476+
.args(
477+
manifest_path
478+
.iter()
479+
.flat_map(|manifest| [OsStr::new("--previous-build-manifest"), manifest]),
480+
)
465481
.status()?;
466482
if !st.success() {
467483
anyhow::bail!("Failed to run compose container-encapsulate: {st:?}");

0 commit comments

Comments
 (0)