Skip to content

Commit

Permalink
feat(risedev): only pull docker image if not exists (#16956)
Browse files Browse the repository at this point in the history
Signed-off-by: Bugen Zhao <[email protected]>
  • Loading branch information
BugenZhao authored May 28, 2024
1 parent 45fd904 commit 9a597ed
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/risedevtool/src/task/docker_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,23 @@ where
Self { config }
}

/// Run `docker image inspect <image>` to check if the image exists locally.
///
/// `docker run --pull=missing` does the same thing, but as we split the pull and run
/// into two commands while `pull` does not provide such an option, we need to check
/// the image existence manually.
fn check_image_exists(&self) -> bool {
Command::new("docker")
.arg("image")
.arg("inspect")
.arg(self.config.image())
.stdout(Stdio::null())
.stderr(Stdio::null())
.status()
.map(|status| status.success())
.unwrap_or(false)
}

fn docker_pull(&self) -> Command {
let mut cmd = Command::new("docker");
cmd.arg("pull").arg(self.config.image());
Expand Down Expand Up @@ -118,9 +135,11 @@ where

check_docker_installed()?;

ctx.pb
.set_message(format!("pulling image `{}`...", self.config.image()));
ctx.run_command(self.docker_pull())?;
if !self.check_image_exists() {
ctx.pb
.set_message(format!("pulling image `{}`...", self.config.image()));
ctx.run_command(self.docker_pull())?;
}

ctx.pb.set_message("starting...");
ctx.run_command(ctx.tmux_run(self.docker_run()?)?)?;
Expand Down

0 comments on commit 9a597ed

Please sign in to comment.