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,
|
ffi::OsStr,
|
||||||
fmt::Display,
|
fmt::Display,
|
||||||
fs::{File, OpenOptions},
|
fs::{File, OpenOptions},
|
||||||
|
os::unix::process::CommandExt,
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
process::{Command, Stdio},
|
process::{Child, Command, Stdio},
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::debug_println;
|
use crate::debug_println;
|
||||||
|
@ -81,6 +82,10 @@ impl CommandBuilder {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn spawn(mut self) -> Result<(Child)> {
|
||||||
|
Ok(self.build()?.spawn()?)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn exec_redirect_stdout(mut self, stdio: Stdio) -> Result<()> {
|
pub fn exec_redirect_stdout(mut self, stdio: Stdio) -> Result<()> {
|
||||||
self.build()?.stdout(stdio).spawn()?.wait()?;
|
self.build()?.stdout(stdio).spawn()?.wait()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -30,7 +30,7 @@ pub fn ps() -> Result<()> {
|
||||||
/// `docker compose --env-file ./.env -f docker/local/docker-compose.yaml up start`
|
/// `docker compose --env-file ./.env -f docker/local/docker-compose.yaml up start`
|
||||||
pub fn start(containers: Option<&str>) -> Result<()> {
|
pub fn start(containers: Option<&str>) -> Result<()> {
|
||||||
let args = format!("start {}", containers.unwrap_or(""));
|
let args = format!("start {}", containers.unwrap_or(""));
|
||||||
CommandBuilder::docker_compose().args("start").exec()
|
CommandBuilder::docker_compose().args(&args).exec()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stop() -> Result<()> {
|
pub fn stop() -> Result<()> {
|
||||||
|
|
|
@ -3,6 +3,8 @@ use std::{
|
||||||
fs::File,
|
fs::File,
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
process::Stdio,
|
process::Stdio,
|
||||||
|
thread,
|
||||||
|
time::Duration,
|
||||||
};
|
};
|
||||||
|
|
||||||
use super::docker_compose;
|
use super::docker_compose;
|
||||||
|
@ -42,7 +44,7 @@ pub fn import(file: &Path) -> Result<()> {
|
||||||
docker_compose::stop()?;
|
docker_compose::stop()?;
|
||||||
|
|
||||||
println!("starting db container");
|
println!("starting db container");
|
||||||
docker_compose::start(Some(&db_container))?;
|
docker_compose::start(Some("postgresdb"))?;
|
||||||
|
|
||||||
println!("restoring database");
|
println!("restoring database");
|
||||||
let commands = [
|
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} createdb -U db -E utf8 -T template0 db"),
|
||||||
format!("exec {db_container} pg_restore -U db --dbname=db /tmp/dbdump"),
|
format!("exec {db_container} pg_restore -U db --dbname=db /tmp/dbdump"),
|
||||||
];
|
];
|
||||||
|
|
||||||
for command in commands {
|
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");
|
println!("restarting containers");
|
||||||
|
|
Loading…
Reference in New Issue