Skip to content

Commit

Permalink
enclave_build: Refactor docker.rs for consistent Runtime creation
Browse files Browse the repository at this point in the history
Create Runtime instances at the beginning of method blocks in docker.rs
for consistency.

Signed-off-by: Erdem Meydanli <[email protected]>
  • Loading branch information
meerd committed Mar 29, 2024
1 parent 7b0bbdd commit d750455
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions enclave_build/src/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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<Vec<u8>, DockerError> {
Expand All @@ -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(),
Expand Down Expand Up @@ -274,11 +274,7 @@ impl DockerUtil {
break Ok(());
}
}
};

let runtime = Runtime::new().map_err(|_| DockerError::RuntimeError)?;

runtime.block_on(act)
})
}

fn inspect(&self) -> Result<ImageInspect, DockerError> {
Expand Down

0 comments on commit d750455

Please sign in to comment.