feat: pg_isready in postgres import
Fixed issue where arguments passed to `compose stop` weren't passed to the underlying command. Added pg_isready call between each command call in restore script.
This commit is contained in:
@@ -3,6 +3,8 @@ use std::{
|
||||
fs::File,
|
||||
path::{Path, PathBuf},
|
||||
process::Stdio,
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use super::docker_compose;
|
||||
@@ -42,7 +44,7 @@ pub fn import(file: &Path) -> Result<()> {
|
||||
docker_compose::stop()?;
|
||||
|
||||
println!("starting db container");
|
||||
docker_compose::start(Some(&db_container))?;
|
||||
docker_compose::start(Some("postgresdb"))?;
|
||||
|
||||
println!("restoring database");
|
||||
let commands = [
|
||||
@@ -51,8 +53,20 @@ pub fn import(file: &Path) -> Result<()> {
|
||||
format!("exec {db_container} createdb -U db -E utf8 -T template0 db"),
|
||||
format!("exec {db_container} pg_restore -U db --dbname=db /tmp/dbdump"),
|
||||
];
|
||||
|
||||
for command in commands {
|
||||
CommandBuilder::docker().args(&command).exec()?;
|
||||
println!("waiting until pg_isready");
|
||||
while !CommandBuilder::docker()
|
||||
.args(&format!(
|
||||
"exec {db_container} pg_isready -h postgresdb -p 5432 -U db",
|
||||
))
|
||||
.spawn()?
|
||||
.wait()?
|
||||
.success()
|
||||
{
|
||||
thread::sleep(Duration::from_secs(1));
|
||||
CommandBuilder::docker().args(&command).exec()?;
|
||||
}
|
||||
}
|
||||
|
||||
println!("restarting containers");
|
||||
|
||||
Reference in New Issue
Block a user