1
Fork 0

Cycle containers on change

This commit is contained in:
Jake Howard 2020-10-05 21:23:04 +01:00
parent 02d51b8ebf
commit 4dd1db342b
Signed by: jake
GPG Key ID: 57AFB45680EDD477
2 changed files with 33 additions and 1 deletions

View File

@ -1,7 +1,7 @@
use std::collections::HashSet;
use std::fmt;
use std::path::{Path, PathBuf};
use std::process::Command;
use std::process::{Command, Stdio};
pub struct ComposeProject {
compose_file: PathBuf,
@ -39,6 +39,32 @@ impl ComposeProject {
let stdout = String::from_utf8(output.stdout).expect("Failed to parse output");
stdout.trim().split('\n').map(String::from).collect()
}
pub fn down(&self) -> bool {
match Command::new("docker-compose")
.stdout(Stdio::null())
.current_dir(self.working_directory())
.args(&["-f", &self.compose_file.to_string_lossy()])
.arg("down")
.status()
{
Ok(s) => s.success(),
Err(_) => false,
}
}
pub fn up(&self) -> bool {
match Command::new("docker-compose")
.stdout(Stdio::null())
.current_dir(self.working_directory())
.args(&["-f", &self.compose_file.to_string_lossy()])
.args(&["up", "-d"])
.status()
{
Ok(s) => s.success(),
Err(_) => false,
}
}
}
impl fmt::Display for ComposeProject {

View File

@ -46,6 +46,12 @@ fn do_update(compose_project: compose::ComposeProject) {
if post_images == pre_images {
info!("No change to images");
} else {
info!("Changes detected - Cycling container");
warn!("Stopping container");
compose_project.down();
warn!("Starting container");
compose_project.up();
}
}