feat: Enhance PostgreSQL installation with image pulling
Some checks failed
Rhai Tests / Run Rhai Tests (pull_request) Has been cancelled
Some checks failed
Rhai Tests / Run Rhai Tests (pull_request) Has been cancelled
- Pull the PostgreSQL image before installation to ensure the latest version is used. This improves reliability and reduces the chance of using outdated images. Improves the robustness of the installation process. - Added comprehensive unit tests for `PostgresInstallerConfig`, `PostgresInstallerError`, `install_postgres`, `create_database`, `execute_sql`, and `is_postgres_running` functions to ensure correctness and handle potential errors effectively. Improves code quality and reduces the risk of regressions.
This commit is contained in:
@@ -168,6 +168,20 @@ pub fn install_postgres(
|
||||
// Build the image name
|
||||
let image = format!("postgres:{}", config.version);
|
||||
|
||||
// Pull the PostgreSQL image to ensure we have the latest version
|
||||
println!("Pulling PostgreSQL image: {}...", image);
|
||||
let pull_result = Command::new("nerdctl")
|
||||
.args(&["pull", &image])
|
||||
.output()
|
||||
.map_err(|e| PostgresInstallerError::IoError(e))?;
|
||||
|
||||
if !pull_result.status.success() {
|
||||
return Err(PostgresInstallerError::NerdctlError(format!(
|
||||
"Failed to pull PostgreSQL image: {}",
|
||||
String::from_utf8_lossy(&pull_result.stderr)
|
||||
)));
|
||||
}
|
||||
|
||||
// Create the container
|
||||
let mut container = Container::new(&config.container_name).map_err(|e| {
|
||||
PostgresInstallerError::NerdctlError(format!("Failed to create container: {}", e))
|
||||
|
Reference in New Issue
Block a user