@@ -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