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:
parent
2754a3bb30
commit
98f02c1c08
|
@ -4,8 +4,9 @@ use std::{
|
|||
ffi::OsStr,
|
||||
fmt::Display,
|
||||
fs::{File, OpenOptions},
|
||||
os::unix::process::CommandExt,
|
||||
path::PathBuf,
|
||||
process::{Command, Stdio},
|
||||
process::{Child, Command, Stdio},
|
||||
};
|
||||
|
||||
use crate::debug_println;
|
||||
|
@ -81,6 +82,10 @@ impl CommandBuilder {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub fn spawn(mut self) -> Result<(Child)> {
|
||||
Ok(self.build()?.spawn()?)
|
||||
}
|
||||
|
||||
pub fn exec_redirect_stdout(mut self, stdio: Stdio) -> Result<()> {
|
||||
self.build()?.stdout(stdio).spawn()?.wait()?;
|
||||
Ok(())
|
||||
|
|
|
@ -30,7 +30,7 @@ pub fn ps() -> Result<()> {
|
|||
/// `docker compose --env-file ./.env -f docker/local/docker-compose.yaml up start`
|
||||
pub fn start(containers: Option<&str>) -> Result<()> {
|
||||
let args = format!("start {}", containers.unwrap_or(""));
|
||||
CommandBuilder::docker_compose().args("start").exec()
|
||||
CommandBuilder::docker_compose().args(&args).exec()
|
||||
}
|
||||
|
||||
pub fn stop() -> Result<()> {
|
||||
|
|
|
@ -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,9 +53,21 @@ 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 {
|
||||
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");
|
||||
docker_compose::stop()?;
|
||||
|
|
Loading…
Reference in New Issue