From d7504553bd5e59933950be7f4efdb397ad9b4cc3 Mon Sep 17 00:00:00 2001 From: Erdem Meydanli Date: Thu, 21 Mar 2024 21:26:52 +0000 Subject: [PATCH] enclave_build: Refactor docker.rs for consistent Runtime creation Create Runtime instances at the beginning of method blocks in docker.rs for consistency. Signed-off-by: Erdem Meydanli --- enclave_build/src/docker.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/enclave_build/src/docker.rs b/enclave_build/src/docker.rs index 0598e342..55358738 100644 --- a/enclave_build/src/docker.rs +++ b/enclave_build/src/docker.rs @@ -177,7 +177,9 @@ impl DockerUtil { return Ok(()); } - let act = async { + let runtime = Runtime::new().map_err(|_| DockerError::RuntimeError)?; + + runtime.block_on(async { let create_image_options = CreateImageOptions { from_image: self.docker_image.clone(), ..Default::default() @@ -218,11 +220,7 @@ impl DockerUtil { break Ok(()); } } - }; - - let runtime = Runtime::new().map_err(|_| DockerError::RuntimeError)?; - - runtime.block_on(act) + }) } fn build_tarball(dockerfile_dir: String) -> Result, DockerError> { @@ -243,7 +241,9 @@ impl DockerUtil { /// 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 runtime = Runtime::new().map_err(|_| DockerError::RuntimeError)?; + + runtime.block_on(async move { let mut stream = self.docker.build_image( BuildImageOptions { dockerfile: "Dockerfile".to_string(), @@ -274,11 +274,7 @@ impl DockerUtil { break Ok(()); } } - }; - - let runtime = Runtime::new().map_err(|_| DockerError::RuntimeError)?; - - runtime.block_on(act) + }) } fn inspect(&self) -> Result {