diff options
author | Matthias Beyer <matthias.beyer@atos.net> | 2021-02-19 09:42:53 +0100 |
---|---|---|
committer | Matthias Beyer <matthias.beyer@atos.net> | 2021-03-10 11:10:20 +0100 |
commit | be0922cbb35adc6b6668221ffaef2b0de23ec3f0 (patch) | |
tree | 762fd8af4de19410249b81ac57c2a0e3be1d3030 | |
parent | 0a2ec1ec96832e798dfd376d996c0604cb38439f (diff) |
Implement patch-to-container copying
Signed-off-by: Matthias Beyer <matthias.beyer@atos.net>
-rw-r--r-- | src/endpoint/configured.rs | 49 |
1 files changed, 48 insertions, 1 deletions
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::<futures::stream::FuturesUnordered<_>>() + .collect::<Result<()>>() + .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, |