Skip to content

Commit c5956c1

Browse files
authored
Merge pull request #5548 from HastD/previous-build-manifest
build-chunked-oci: Add --previous-build option
2 parents 1d97a3e + 8940bf9 commit c5956c1

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

rust/src/compose.rs

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,13 @@ 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 reference to a
232+
/// previous build to base the layer plan on. For example,
233+
/// `docker://quay.io/registry-name/image-name:latest` to use an image in
234+
/// a remote registry (without needing to pull the remote image).
235+
#[clap(long)]
236+
previous_build: Option<String>,
237+
231238
/// Tag to use for output image, or `latest` if unset.
232239
#[clap(long, default_value = "latest")]
233240
reference: String,
@@ -324,7 +331,8 @@ impl BuildChunkedOCIOpts {
324331
// Ensure we're in the proper namespace for container operations
325332
crate::containers_storage::reexec_if_needed()?;
326333

327-
let existing_manifest = self.check_existing_image(&self.output)?;
334+
let previous_build_candidate = self.previous_build.as_ref().unwrap_or(&self.output);
335+
let existing_manifest = self.check_existing_image(previous_build_candidate)?;
328336

329337
let rootfs_source = if let Some(rootfs) = self.rootfs {
330338
FileSource::Rootfs(rootfs)
@@ -481,11 +489,14 @@ impl BuildChunkedOCIOpts {
481489
}
482490

483491
/// Check if there's already an image at the target location and if it's chunked
484-
fn check_existing_image(&self, output: &str) -> Result<Option<oci_spec::image::ImageManifest>> {
485-
// Parse the output reference to determine transport and location
486-
let (transport, _location) = output
487-
.split_once(':')
488-
.ok_or_else(|| anyhow::anyhow!("Invalid output format, expected TRANSPORT:TARGET"))?;
492+
fn check_existing_image(
493+
&self,
494+
image_ref: &str,
495+
) -> Result<Option<oci_spec::image::ImageManifest>> {
496+
// Parse the image reference to determine transport and location
497+
let (transport, _location) = image_ref.split_once(':').ok_or_else(|| {
498+
anyhow::anyhow!("Invalid image reference '{image_ref}', expected TRANSPORT:TARGET")
499+
})?;
489500

490501
let handle = tokio::runtime::Handle::current();
491502
let result: Option<oci_spec::image::ImageManifest> = handle.block_on(async {
@@ -494,9 +505,9 @@ impl BuildChunkedOCIOpts {
494505
let proxy = containers_image_proxy::ImageProxy::new().await?;
495506

496507
let img = if transport == OCI_ARCHIVE_TRANSPORT {
497-
(proxy.open_image(output).await).ok()
508+
(proxy.open_image(image_ref).await).ok()
498509
} else {
499-
proxy.open_image_optional(output).await?
510+
proxy.open_image_optional(image_ref).await?
500511
};
501512

502513
if let Some(opened_image) = img {

0 commit comments

Comments
 (0)