From dcab416d5e1041504ef9873134052ca5d6aa5676 Mon Sep 17 00:00:00 2001 From: Erdem Meydanli Date: Thu, 21 Mar 2024 21:20:26 +0000 Subject: [PATCH] enclave_build: Extract build_tarball method Extract build_tarball method from build_image in docker.rs for reusability. Signed-off-by: Erdem Meydanli --- enclave_build/src/docker.rs | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/enclave_build/src/docker.rs b/enclave_build/src/docker.rs index dd225abcd..0598e3423 100644 --- a/enclave_build/src/docker.rs +++ b/enclave_build/src/docker.rs @@ -225,19 +225,24 @@ impl DockerUtil { runtime.block_on(act) } - /// Build an image locally, with the tag provided in constructor, using a - /// directory that contains a Dockerfile - pub fn build_image(&self, dockerfile_dir: String) -> Result<(), DockerError> { - let mut archive = tar::Builder::new(GzEncoder::new(Vec::default(), Compression::best())); + fn build_tarball(dockerfile_dir: String) -> Result, DockerError> { + let encoder = GzEncoder::new(Vec::default(), Compression::best()); + let mut archive = tar::Builder::new(encoder); + archive.append_dir_all(".", &dockerfile_dir).map_err(|e| { error!("{:?}", e); DockerError::BuildError })?; - let bytes = archive.into_inner().and_then(|c| c.finish()).map_err(|e| { + + archive.into_inner().and_then(|c| c.finish()).map_err(|e| { error!("{:?}", e); DockerError::BuildError - })?; + }) + } + /// Build an image locally, with the tag provided in constructor, using a + /// directory that contains a Dockerfile + pub fn build_image(&self, dockerfile_dir: String) -> Result<(), DockerError> { let act = async move { let mut stream = self.docker.build_image( BuildImageOptions { @@ -246,7 +251,7 @@ impl DockerUtil { ..Default::default() }, None, - Some(bytes.into()), + Some(Self::build_tarball(dockerfile_dir)?.into()), ); loop {