Compare commits
No commits in common. "c900d1d9d77ad5b23638227e29d0bdf44b0f0d34" and "870e63646ece5f34d0bdcf225b8cc035c1f50f62" have entirely different histories.
c900d1d9d7
...
870e63646e
3 changed files with 33 additions and 121 deletions
|
@ -27,15 +27,15 @@ max-threads = 10
|
||||||
[packages.some-librewolf-dependency]
|
[packages.some-librewolf-dependency]
|
||||||
|
|
||||||
[packages.some-librewolf-dependency.compilation]
|
[packages.some-librewolf-dependency.compilation]
|
||||||
id = "2"
|
id = "1"
|
||||||
revision = "4"
|
revision = "2"
|
||||||
threads = 2
|
threads = 2
|
||||||
image = "docker.io/library/debian"
|
image = "docker.io/library/debian"
|
||||||
commands = ["echo hi", "echo helloooooooooo >&2"]
|
commands = ["echo hi", "echo helloooooooooo"]
|
||||||
volumes = ["other-workspace"]
|
volumes = ["other-workspace"]
|
||||||
|
|
||||||
[packages.some-librewolf-dependency.packaging.fedora]
|
[packages.some-librewolf-dependency.packaging.fedora]
|
||||||
id = "3"
|
id = "1"
|
||||||
revision = "2"
|
revision = "2"
|
||||||
threads = 2
|
threads = 2
|
||||||
image = "docker.io/library/fedora"
|
image = "docker.io/library/fedora"
|
||||||
|
|
|
@ -1,84 +0,0 @@
|
||||||
use crate::errors::Error;
|
|
||||||
use std::io::Write;
|
|
||||||
use std::sync::{Arc, Mutex};
|
|
||||||
use std::{
|
|
||||||
fs::{File, OpenOptions},
|
|
||||||
os::unix::fs::FileExt,
|
|
||||||
};
|
|
||||||
|
|
||||||
/// The logger for gregory itself - NOT for jobs
|
|
||||||
pub(crate) struct Logger {
|
|
||||||
log_file: File,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Logger {
|
|
||||||
pub(crate) fn new(path: String) -> Result<Logger, Error> {
|
|
||||||
match OpenOptions::new().append(true).open(path) {
|
|
||||||
Ok(f) => return Ok(Logger { log_file: f }),
|
|
||||||
Err(e) => {
|
|
||||||
return Err(Error::IOError(e));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Log a warning
|
|
||||||
///
|
|
||||||
/// Fun gregory lore: I originally typo'd this as "Strign" and the linter didn't catch it for some reason
|
|
||||||
pub(crate) fn warning(&mut self, text: String) -> Result<(), Error> {
|
|
||||||
match writeln!(&mut self.log_file, "[WARNING] {}", text) {
|
|
||||||
Ok(_) => return Ok(()),
|
|
||||||
Err(e) => {
|
|
||||||
return Err(Error::IOError(e));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Log an error
|
|
||||||
pub(crate) fn error(&mut self, text: String) -> Result<(), Error> {
|
|
||||||
match writeln!(&mut self.log_file, "[ERROR] {}", text) {
|
|
||||||
Ok(_) => return Ok(()),
|
|
||||||
Err(e) => {
|
|
||||||
return Err(Error::IOError(e));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Logging for a [`Job`]
|
|
||||||
pub(crate) struct JobLogger {
|
|
||||||
log_file: File,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl JobLogger {
|
|
||||||
pub(crate) fn new(path: String) -> Result<JobLogger, Error> {
|
|
||||||
match OpenOptions::new().create_new(true).append(true).open(path) {
|
|
||||||
Ok(f) => return Ok(JobLogger { log_file: f }),
|
|
||||||
Err(e) => {
|
|
||||||
return Err(Error::IOError(e));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Log something printed to stdout
|
|
||||||
///
|
|
||||||
/// Fun gregory lore: I originally typo'd this as "Strign" and the linter didn't catch it for some reason
|
|
||||||
pub(crate) fn stdout(&mut self, text: String) -> Result<(), Error> {
|
|
||||||
match writeln!(&mut self.log_file, "[stdout] {}", text) {
|
|
||||||
Ok(_) => return Ok(()),
|
|
||||||
Err(e) => {
|
|
||||||
return Err(Error::IOError(e));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Log something printed to stderr
|
|
||||||
pub(crate) fn stderr(&mut self, text: String) -> Result<(), Error> {
|
|
||||||
match writeln!(&mut self.log_file, "[stderr] {}", text) {
|
|
||||||
Ok(_) => return Ok(()),
|
|
||||||
Err(e) => {
|
|
||||||
return Err(Error::IOError(e));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
50
src/main.rs
50
src/main.rs
|
@ -1,7 +1,6 @@
|
||||||
use crate::cli::*;
|
use crate::cli::*;
|
||||||
use crate::data::*;
|
use crate::data::*;
|
||||||
use alphanumeric_sort::sort_str_slice;
|
use alphanumeric_sort::sort_str_slice;
|
||||||
use better_commands;
|
|
||||||
use clap::{CommandFactory, Parser};
|
use clap::{CommandFactory, Parser};
|
||||||
use clap_complete::aot::{generate, Bash, Elvish, Fish, PowerShell, Zsh};
|
use clap_complete::aot::{generate, Bash, Elvish, Fish, PowerShell, Zsh};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
@ -13,15 +12,13 @@ use std::io::stdout;
|
||||||
use std::os::unix::fs::PermissionsExt;
|
use std::os::unix::fs::PermissionsExt;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::sync::Arc;
|
|
||||||
use std::sync::Mutex;
|
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
use better_commands;
|
||||||
|
|
||||||
mod cli;
|
mod cli;
|
||||||
mod data;
|
mod data;
|
||||||
mod errors;
|
mod errors;
|
||||||
mod logging;
|
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -88,21 +85,28 @@ fn run_job(conf: Config, job: Job) -> JobExitStatus {
|
||||||
|
|
||||||
let container_name: String = format!("gregory-{}-{}-{}", job.id, job.revision, Uuid::now_v7());
|
let container_name: String = format!("gregory-{}-{}-{}", job.id, job.revision, Uuid::now_v7());
|
||||||
|
|
||||||
// do job log setup
|
// create log path
|
||||||
let log_path = &format!("{}/logs/{container_name}", conf.data_dir); // can't select fields in the format!() {} thing, have to do this
|
let log_path = &format!("{}/logs/{container_name}", conf.data_dir); // can't select fields in the format!() {} thing, have to do this
|
||||||
let log_dir: &Path = Path::new(log_path).parent().unwrap();
|
let log_dir: &Path = Path::new(log_path).parent().unwrap();
|
||||||
create_dir_all(log_dir).unwrap();
|
create_dir_all(log_dir).unwrap();
|
||||||
|
|
||||||
let job_logger = Arc::new(Mutex::new(
|
|
||||||
logging::JobLogger::new(log_path.clone()).unwrap(),
|
|
||||||
));
|
|
||||||
|
|
||||||
|
|
||||||
// write the script
|
// write the script
|
||||||
let script_path = &format!("{}/tmp/{container_name}.sh", conf.data_dir); // can't select fields in the format!() {} thing, have to do this
|
let script_path = &format!("{}/tmp/{container_name}.sh", conf.data_dir); // can't select fields in the format!() {} thing, have to do this
|
||||||
let script_dir: &Path = Path::new(script_path).parent().unwrap(); // create dir for the script
|
// create dir for the script
|
||||||
|
let script_dir: &Path = Path::new(script_path).parent().unwrap();
|
||||||
create_dir_all(script_dir).unwrap();
|
create_dir_all(script_dir).unwrap();
|
||||||
write(script_path, job.commands.join("\n")).unwrap();
|
write(
|
||||||
|
script_path,
|
||||||
|
job.commands
|
||||||
|
//.iter()
|
||||||
|
//.map(|item| {
|
||||||
|
// // TODO: FIGURE OUT HOW TO HANDLE IT ESCAPING IT OR WHATEVER AAAAAAAAAAAAA
|
||||||
|
// // update: i have no idea what i was talking about previously
|
||||||
|
//})
|
||||||
|
//.collect::<Vec<String>>()
|
||||||
|
.join("\n"),
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
|
||||||
// set permissions - *unix specific*
|
// set permissions - *unix specific*
|
||||||
let mut perms = File::open(script_path)
|
let mut perms = File::open(script_path)
|
||||||
|
@ -134,26 +138,19 @@ fn run_job(conf: Config, job: Job) -> JobExitStatus {
|
||||||
&job.shell
|
&job.shell
|
||||||
));
|
));
|
||||||
cmd_args.push(job.clone().image);
|
cmd_args.push(job.clone().image);
|
||||||
|
// TODO: TEMPORARY - update to actually write it in the future
|
||||||
let cmd_output = better_commands::run_funcs(
|
let cmd_output = better_commands::run_funcs(Command::new("podman").args(cmd_args), {
|
||||||
Command::new("podman").args(cmd_args),
|
|stdout_lines|
|
||||||
{
|
|
||||||
let logger_clone = Arc::clone(&job_logger);
|
|
||||||
move |stdout_lines| {
|
|
||||||
for line in stdout_lines {
|
for line in stdout_lines {
|
||||||
let _ = logger_clone.lock().unwrap().stdout(line.unwrap());
|
println!("[stdout] {}", line.unwrap());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
let logger_clone = Arc::clone(&job_logger);
|
|stderr_lines|
|
||||||
move |stderr_lines| {
|
|
||||||
for line in stderr_lines {
|
for line in stderr_lines {
|
||||||
let _ = logger_clone.lock().unwrap().stderr(line.unwrap());
|
println!("[stderr] {}", line.unwrap());
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
},
|
|
||||||
);
|
|
||||||
// remove tmp dir
|
// remove tmp dir
|
||||||
remove_dir_all(script_dir).unwrap();
|
remove_dir_all(script_dir).unwrap();
|
||||||
|
|
||||||
|
@ -167,4 +164,3 @@ fn run_job(conf: Config, job: Job) -> JobExitStatus {
|
||||||
log_path: log_path.clone(),
|
log_path: log_path.clone(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
// .
|
|
Loading…
Add table
Add a link
Reference in a new issue