From be0922cbb35adc6b6668221ffaef2b0de23ec3f0 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Fri, 19 Feb 2021 09:42:53 +0100 Subject: Implement patch-to-container copying Signed-off-by: Matthias Beyer --- src/endpoint/configured.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) (limited to 'src/endpoint') diff --git a/src/endpoint/configured.rs b/src/endpoint/configured.rs index ba1c54e..0d3927b 100644 --- a/src/endpoint/configured.rs +++ b/src/endpoint/configured.rs @@ -287,8 +287,9 @@ impl<'a> PreparedContainer<'a> { let create_info = Self::build_container(endpoint, &job).await?; let container = endpoint.docker.containers().get(&create_info.id); - let (cpysrc, cpyart, cpyscr) = tokio::join!( + let (cpysrc, cpypch, cpyart, cpyscr) = tokio::join!( Self::copy_source_to_container(&container, &job), + Self::copy_patches_to_container(&container, &job), Self::copy_artifacts_to_container(&container, &job, staging_store, &release_stores), Self::copy_script_to_container(&container, &script) ); @@ -301,6 +302,14 @@ impl<'a> PreparedContainer<'a> { ) })?; + let _ = cpypch.with_context(|| { + anyhow!( + "Copying the patches to container {} on '{}'", + create_info.id, + endpoint.name + ) + })?; + let _ = cpyart.with_context(|| { anyhow!( "Copying the artifacts to container {} on '{}'", @@ -409,6 +418,44 @@ impl<'a> PreparedContainer<'a> { .map_err(Error::from) } + async fn copy_patches_to_container<'ca>( + container: &Container<'ca>, + job: &RunnableJob, + ) -> Result<()> { + use tokio::io::AsyncReadExt; + + log::debug!("Copying patches to container: {:?}", job.package().patches()); + job.package() + .patches() + .iter() + .map(|patch| async move { + let destination = PathBuf::from("/patches").join(patch); + trace!("Copying patch {} to container at /patches/{}", patch.display(), destination.display()); + + let mut buf = vec![]; + tokio::fs::OpenOptions::new() + .create(false) + .create_new(false) + .append(false) + .write(false) + .read(true) + .open(&patch) + .await + .with_context(|| anyhow!("Getting patch file: {}", patch.display()))? + .read_to_end(&mut buf) + .await + .with_context(|| anyhow!("Reading file {}", patch.display()))?; + + let _ = container.copy_file_into(destination, &buf).await?; + Ok(()) + }) + .collect::>() + .collect::>() + .await + .with_context(|| anyhow!("Copying patches to container {}", container.id())) + .map_err(Error::from) + } + async fn copy_artifacts_to_container<'ca>( container: &Container<'ca>, job: &RunnableJob, -- cgit v1.2.3