From 34cac050947e0b7cf70e95f7fb51ee86d44e5629 Mon Sep 17 00:00:00 2001 From: "Mikhail f. Shiryaev" Date: Fri, 17 Apr 2026 19:46:07 +0200 Subject: [PATCH] Add retry for dists docker image build --- tests/harness/mod.rs | 46 +++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/tests/harness/mod.rs b/tests/harness/mod.rs index f7574a9eb5..654e8d98bd 100644 --- a/tests/harness/mod.rs +++ b/tests/harness/mod.rs @@ -258,22 +258,36 @@ pub struct DistSystem { #[cfg(feature = "dist-server")] impl DistSystem { pub fn new(sccache_dist: &Path, tmpdir: &Path) -> Self { - // Make sure the docker image is available, building it if necessary - let mut child = Command::new("docker") - .args(["build", "-q", "-t", DIST_IMAGE, "-"]) - .stdin(Stdio::piped()) - .stdout(Stdio::piped()) - .stderr(Stdio::piped()) - .spawn() - .unwrap(); - child - .stdin - .as_mut() - .unwrap() - .write_all(DIST_DOCKERFILE.as_bytes()) - .unwrap(); - let output = child.wait_with_output().unwrap(); - check_output(&output); + // Make sure the docker image is available, building it if necessary. + // Retry up to 3 times to handle transient apt-get failures in CI. + let mut last_output = None; + for attempt in 1..=3 { + let mut child = Command::new("docker") + .args(["build", "-q", "-t", DIST_IMAGE, "-"]) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .unwrap(); + child + .stdin + .as_mut() + .unwrap() + .write_all(DIST_DOCKERFILE.as_bytes()) + .unwrap(); + let output = child.wait_with_output().unwrap(); + if output.status.success() { + last_output = Some(output); + break; + } + eprintln!( + "docker build attempt {}/3 failed (exit {}), retrying...", + attempt, output.status + ); + last_output = Some(output); + std::thread::sleep(Duration::from_secs(5 * attempt as u64)); + } + check_output(&last_output.unwrap()); let tmpdir = tmpdir.join("distsystem"); fs::create_dir(&tmpdir).unwrap();