1
Fork 0

Allow containers to be pulled

This commit is contained in:
Jake Howard 2020-10-05 19:57:56 +01:00
parent 790d163de0
commit 394d7ac3e1
Signed by: jake
GPG Key ID: 57AFB45680EDD477
2 changed files with 18 additions and 13 deletions

View File

@ -1,6 +1,5 @@
use std::io::Result;
use std::path::{Path, PathBuf};
use std::process::{Command, Output};
use std::process::Command;
pub struct ComposeProject {
compose_file: PathBuf,
@ -19,16 +18,12 @@ impl ComposeProject {
.expect("Failed to get parent of compose file")
}
fn execute_in_dir(&self, command: &str, arguments: &[&str]) -> Result<Output> {
Command::new(command)
pub fn pull(&self) -> bool {
Command::new("docker-compose")
.current_dir(self.working_directory())
.args(arguments)
.output()
}
fn docker_compose(&self, arguments: &[&str])-> Result<Output> {
let mut compose_arguments = vec!["-f", self.compose_file.to_str().expect("Path parse failed")];
compose_arguments.extend_from_slice(arguments);
self.execute_in_dir("docker-compose", compose_arguments.as_slice())
.args(&["-f", &self.compose_file.to_string_lossy()])
.arg("pull")
.status()
.is_ok()
}
}

View File

@ -22,7 +22,9 @@ fn get_files(files: &[String]) -> Option<Vec<PathBuf>> {
for file in files {
for path in glob(&file).ok()?.filter_map(Result::ok) {
if path.is_file() {
all_files.push(path);
if let Ok(canonical_path) = path.canonicalize() {
all_files.push(canonical_path);
}
}
}
}
@ -30,6 +32,10 @@ fn get_files(files: &[String]) -> Option<Vec<PathBuf>> {
Some(all_files)
}
fn do_update(compose_project: compose::ComposeProject) {
compose_project.pull();
}
fn main() {
let opts = Opt::from_args();
env_logger::builder()
@ -59,4 +65,8 @@ fn main() {
.collect();
info!("Found {} projects", compose_projects.len());
for compose_project in compose_projects {
do_update(compose_project);
}
}