Skip to content

Commit 9259f02

Browse files
committed
Explicitly pull base images.
1 parent f6306b2 commit 9259f02

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

src/bin/integration_tests.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use clap::Parser;
2+
use std::collections::HashSet;
23
use std::fs;
34
use std::path::{Path, PathBuf};
45
use std::process::Command;
@@ -48,6 +49,20 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
4849
}
4950
println!();
5051

52+
// Collect all unique base images from test projects
53+
println!("--- Collecting base images from test projects ---");
54+
let base_images = collect_base_images(&test_dirs)?;
55+
println!("Found {} unique base image(s):", base_images.len());
56+
for image in &base_images {
57+
println!(" - {}", image);
58+
}
59+
println!();
60+
61+
// Pull all base images to ensure they are current
62+
println!("--- Pulling base images ---");
63+
pull_base_images(&base_images)?;
64+
println!();
65+
5166
// Clean up any leftover temporary directories from previous runs
5267
println!("--- Cleaning up leftover temporary directories ---");
5368
cleanup_leftover_temp_directories(&project_root)?;
@@ -106,6 +121,48 @@ fn find_test_directories(
106121
Ok(dirs)
107122
}
108123

124+
fn collect_base_images(test_dirs: &[PathBuf]) -> Result<Vec<String>, Box<dyn std::error::Error>> {
125+
let mut base_images = HashSet::new();
126+
127+
for test_dir in test_dirs {
128+
let config_path = test_dir.join("config.json");
129+
if config_path.exists() {
130+
let config_content = fs::read_to_string(&config_path)?;
131+
let config: TestConfig = serde_json::from_str(&config_content).map_err(|e| {
132+
format!(
133+
"Failed to parse config.json in {}: {}",
134+
test_dir.display(),
135+
e
136+
)
137+
})?;
138+
base_images.insert(config.base_image);
139+
}
140+
}
141+
142+
let mut images: Vec<String> = base_images.into_iter().collect();
143+
images.sort();
144+
Ok(images)
145+
}
146+
147+
fn pull_base_images(base_images: &[String]) -> Result<(), Box<dyn std::error::Error>> {
148+
for image in base_images {
149+
println!("Pulling base image: {}", image);
150+
let output = Command::new("docker")
151+
.args(["pull", image])
152+
.output()
153+
.map_err(|e| format!("Failed to run docker pull command for {}: {}", image, e))?;
154+
155+
if !output.status.success() {
156+
let stderr = String::from_utf8_lossy(&output.stderr);
157+
return Err(format!("Failed to pull base image {}: {}", image, stderr).into());
158+
}
159+
160+
println!("✓ Successfully pulled {}", image);
161+
}
162+
163+
Ok(())
164+
}
165+
109166
fn cleanup_leftover_temp_directories(
110167
project_root: &Path,
111168
) -> Result<(), Box<dyn std::error::Error>> {

0 commit comments

Comments
 (0)