Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

export: Add progress flag #644

Merged
merged 1 commit into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/src/container/encapsulate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ async fn build_impl(
dest,
authfile.as_deref(),
Some((std::sync::Arc::new(tempdir.try_clone()?.into()), target_fd)),
false,
)
.await?;
Some(digest)
Expand Down
6 changes: 5 additions & 1 deletion lib/src/container/skopeo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,14 @@ pub(crate) async fn copy(
dest: &ImageReference,
authfile: Option<&Path>,
add_fd: Option<(std::sync::Arc<OwnedFd>, i32)>,
progress: bool,
) -> Result<String> {
let digestfile = tempfile::NamedTempFile::new()?;
let mut cmd = new_cmd();
cmd.stdout(std::process::Stdio::null()).arg("copy");
cmd.arg("copy");
if !progress {
cmd.stdout(std::process::Stdio::null());
}
cmd.arg("--digestfile");
cmd.arg(digestfile.path());
if let Some((add_fd, n)) = add_fd {
Expand Down
8 changes: 6 additions & 2 deletions lib/src/container/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,8 @@ pub struct ExportToOCIOpts {
pub skip_compression: bool,
/// Path to Docker-formatted authentication file.
pub authfile: Option<std::path::PathBuf>,
/// Output progress to stdout
pub progress_to_stdout: bool,
}

/// The way we store "chunk" layers in ostree is by writing a commit
Expand Down Expand Up @@ -1358,19 +1360,20 @@ pub async fn export(
dest_imgref: &ImageReference,
opts: Option<ExportToOCIOpts>,
) -> Result<String> {
let opts = opts.unwrap_or_default();
let target_oci = dest_imgref.transport == Transport::OciDir;
let tempdir = if !target_oci {
let vartmp = cap_std::fs::Dir::open_ambient_dir("/var/tmp", cap_std::ambient_authority())?;
let td = cap_std_ext::cap_tempfile::TempDir::new_in(&vartmp)?;
// Always skip compression when making a temporary copy
let opts = ExportToOCIOpts {
skip_compression: true,
progress_to_stdout: opts.progress_to_stdout,
..Default::default()
};
export_to_oci(repo, src_imgref, &td, None, opts)?;
td
} else {
let opts = opts.unwrap_or_default();
let (path, tag) = parse_oci_path_and_tag(dest_imgref.name.as_str());
tracing::debug!("using OCI path={path} tag={tag:?}");
let path = Dir::open_ambient_dir(path, cap_std::ambient_authority())
Expand All @@ -1384,12 +1387,13 @@ pub async fn export(
transport: Transport::OciDir,
name: format!("/proc/self/fd/{target_fd}"),
};
let authfile = opts.as_ref().and_then(|o| o.authfile.as_deref());
let authfile = opts.authfile.as_deref();
skopeo::copy(
&tempoci,
dest_imgref,
authfile,
Some((std::sync::Arc::new(tempdir.try_clone()?.into()), target_fd)),
opts.progress_to_stdout,
)
.await
}
Expand Down
4 changes: 2 additions & 2 deletions lib/src/container/update_detachedmeta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub async fn update_detached_metadata(
};

// Full copy of the source image
let pulled_digest: String = skopeo::copy(src, &tempsrc_ref, None, None)
let pulled_digest: String = skopeo::copy(src, &tempsrc_ref, None, None, false)
.await
.context("Creating temporary copy to OCI dir")?;

Expand Down Expand Up @@ -124,7 +124,7 @@ pub async fn update_detached_metadata(

// Finally, copy the mutated image back to the target. For chunked images,
// because we only changed one layer, skopeo should know not to re-upload shared blobs.
crate::container::skopeo::copy(&tempsrc_ref, dest, None, None)
crate::container::skopeo::copy(&tempsrc_ref, dest, None, None, false)
.await
.context("Copying to destination")
}
Loading