Compare commits
No commits in common. "2809459d8ba9f689bd4cdd6a6b1db32948a6362c" and "c0830ebc4a14d45716baef3ad2345db76d13ab7c" have entirely different histories.
2809459d8b
...
c0830ebc4a
7 changed files with 28 additions and 27 deletions
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
This is Gregory. Gregory controls repos. Gregory keeps track of updating repos, trying to be simple and elegant, but enough.
|
This is Gregory. Gregory controls repos. Gregory keeps track of updating repos, trying to be simple and elegant, but enough.
|
||||||
|
|
||||||
|
## THIS IS A PROTOTYPE
|
||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
|
|
||||||
Go look at [`docs/`](/docs/)
|
Go look at [`docs/`](/docs/)
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
# How commands are run
|
# How commands are run
|
||||||
|
|
||||||
I was unable to find a way to directly run *multiple* commands via Docker/Podman. Instead of doing that, greg puts all the commands in a temporary script, mounts it inside, and then runs it with `shell`.
|
I was unable to find a way to directly run *multiple* commands via Docker/Podman. Instead of doing that, greg puts all the commands in a temporary script, mounts it inside, and then run it with
|
||||||
|
|
|
@ -23,7 +23,7 @@ i.e. with `total_threads` as the number of threads the CPU(s) has:
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
Alternative algorithm I tried:
|
Alternative algorithms I tried:
|
||||||
|
|
||||||
```rs
|
```rs
|
||||||
if total_threads >= 32 {
|
if total_threads >= 32 {
|
||||||
|
|
|
@ -28,6 +28,9 @@ Note: This primarily uses LibreWolf and Fedora as examples of packages and distr
|
||||||
|
|
||||||
## Job config
|
## Job config
|
||||||
|
|
||||||
|
- `id` (string): An ID to identify the job, such as the compilation of a program **(highly recommended)**
|
||||||
|
- Default is `-1` for unassigned
|
||||||
|
- If you just want to run stuff, you don't need this, but it's *highly* recommended as it allows you to filter your logs.
|
||||||
- `revision` (string): A revision id for the job, such as a version number for a compilation script
|
- `revision` (string): A revision id for the job, such as a version number for a compilation script
|
||||||
- Default is `1`
|
- Default is `1`
|
||||||
- `threads` (float): The maximum number of vCPUs/threads to dedicate to a job; this can be a fractional number
|
- `threads` (float): The maximum number of vCPUs/threads to dedicate to a job; this can be a fractional number
|
||||||
|
@ -53,9 +56,9 @@ Example:
|
||||||
[packages.librewolf]
|
[packages.librewolf]
|
||||||
|
|
||||||
dependencies = ["some-librewolf-dependency"]
|
dependencies = ["some-librewolf-dependency"]
|
||||||
version_check = ["check-version --whenever-you-feel-like-it-please"]
|
|
||||||
|
|
||||||
[packages.librewolf.compilation]
|
[packages.librewolf.compilation]
|
||||||
|
id = "1"
|
||||||
revision = "2"
|
revision = "2"
|
||||||
threads = 8
|
threads = 8
|
||||||
image = "docker.io/library/debian"
|
image = "docker.io/library/debian"
|
||||||
|
@ -72,11 +75,7 @@ Example:
|
||||||
volumes = ["librewolf"]
|
volumes = ["librewolf"]
|
||||||
```
|
```
|
||||||
|
|
||||||
`packages` contains the following fields:
|
Aside from just the jobs, `packages` also contains the `dependencies` field, which lists dependencies for this package which gregory manages - don't list external dependencies in that field.
|
||||||
|
|
||||||
- `dependencies` (array): Lists dependencies for this package which gregory manages - don't list external dependencies in that field. This isn't required, but will ensure that gregory doesn't have to be run multiple times to get a package up-to-date.
|
|
||||||
- Note that the repo will be updated (`[update-repo]`) after any dependency it updated
|
|
||||||
- `version-check` (array): Commands to be run to check the version of the package; what's printed to `stdout` will be counted as the version, and if anything is printed to `stderr`, the package will be ignored and an error will be logged. Additionally, if the package version seems to have decreased, then a warning will be logged.
|
|
||||||
|
|
||||||
### Compilation (optional)
|
### Compilation (optional)
|
||||||
|
|
||||||
|
@ -90,6 +89,7 @@ It's defined in this format:
|
||||||
[packages.librewolf]
|
[packages.librewolf]
|
||||||
|
|
||||||
[packages.librewolf.compilation]
|
[packages.librewolf.compilation]
|
||||||
|
id = "1"
|
||||||
revision = "2"
|
revision = "2"
|
||||||
threads = 8
|
threads = 8
|
||||||
image = "docker.io/library/debian"
|
image = "docker.io/library/debian"
|
||||||
|
|
|
@ -6,9 +6,9 @@ max-threads = 10
|
||||||
[packages.librewolf]
|
[packages.librewolf]
|
||||||
|
|
||||||
dependencies = ["some-librewolf-dependency"]
|
dependencies = ["some-librewolf-dependency"]
|
||||||
version_check = ["check-version --whenever-you-feel-like-it-please"]
|
|
||||||
|
|
||||||
[packages.librewolf.compilation]
|
[packages.librewolf.compilation]
|
||||||
|
id = "1"
|
||||||
revision = "2"
|
revision = "2"
|
||||||
threads = 6
|
threads = 6
|
||||||
image = "docker.io/library/debian"
|
image = "docker.io/library/debian"
|
||||||
|
@ -27,6 +27,7 @@ max-threads = 10
|
||||||
[packages.some-librewolf-dependency]
|
[packages.some-librewolf-dependency]
|
||||||
|
|
||||||
[packages.some-librewolf-dependency.compilation]
|
[packages.some-librewolf-dependency.compilation]
|
||||||
|
id = "2"
|
||||||
revision = "4"
|
revision = "4"
|
||||||
threads = 2
|
threads = 2
|
||||||
image = "docker.io/library/debian"
|
image = "docker.io/library/debian"
|
||||||
|
@ -34,6 +35,7 @@ max-threads = 10
|
||||||
volumes = ["other-workspace"]
|
volumes = ["other-workspace"]
|
||||||
|
|
||||||
[packages.some-librewolf-dependency.packaging.fedora]
|
[packages.some-librewolf-dependency.packaging.fedora]
|
||||||
|
id = "3"
|
||||||
revision = "2"
|
revision = "2"
|
||||||
threads = 2
|
threads = 2
|
||||||
image = "docker.io/library/fedora"
|
image = "docker.io/library/fedora"
|
||||||
|
|
|
@ -35,7 +35,9 @@ pub(crate) struct Config {
|
||||||
/// Holds the data for a job
|
/// Holds the data for a job
|
||||||
#[derive(Debug, Clone, Deserialize)]
|
#[derive(Debug, Clone, Deserialize)]
|
||||||
pub(crate) struct Job {
|
pub(crate) struct Job {
|
||||||
/// What revision of the job config, temporary until better revision tracking is added
|
/// An ID to identify the job, such as the compilation of a program
|
||||||
|
#[serde(default = "id")]
|
||||||
|
pub(crate) id: String,
|
||||||
#[serde(default = "revision")]
|
#[serde(default = "revision")]
|
||||||
pub(crate) revision: String,
|
pub(crate) revision: String,
|
||||||
/// How many threads to limit this job to; recommended to set it to the max threads the job will use
|
/// How many threads to limit this job to; recommended to set it to the max threads the job will use
|
||||||
|
|
31
src/main.rs
31
src/main.rs
|
@ -3,7 +3,6 @@ use crate::data::*;
|
||||||
use better_commands;
|
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::collections::HashMap;
|
|
||||||
use std::fs::create_dir_all;
|
use std::fs::create_dir_all;
|
||||||
use std::fs::remove_dir_all;
|
use std::fs::remove_dir_all;
|
||||||
use std::fs::write;
|
use std::fs::write;
|
||||||
|
@ -53,40 +52,38 @@ fn main() {
|
||||||
fn run(config_path: String) {
|
fn run(config_path: String) {
|
||||||
let config = config_from_file(config_path).unwrap();
|
let config = config_from_file(config_path).unwrap();
|
||||||
|
|
||||||
let mut jobs: HashMap<String, Job> = HashMap::new();
|
let mut jobs: Vec<Job> = Vec::new();
|
||||||
|
|
||||||
for (package_name, package) in config.clone().packages {
|
|
||||||
|
|
||||||
|
for (_, package) in config.clone().packages {
|
||||||
match package.compilation {
|
match package.compilation {
|
||||||
Some(tmp) => {
|
Some(tmp) => {
|
||||||
jobs.insert(format!("packages.{}.compilation", package_name), tmp);
|
jobs.push(tmp);
|
||||||
}
|
}
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (packaging_name, job) in package.packaging {
|
for (_, job) in package.packaging {
|
||||||
jobs.insert(format!("packages.{}.{}", package_name, packaging_name), job);
|
jobs.push(job);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (repo, job) in config.clone().update_repo {
|
for (_, job) in config.clone().update_repo {
|
||||||
jobs.insert(format!("update-repo.{}", repo), job);
|
jobs.push(job);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (job_name, job) in jobs {
|
for job in jobs {
|
||||||
println!("{:#?}", run_job(config.clone(), job_name, job));
|
println!("{:#?}", run_job(config.clone(), job));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
fn run_job(conf: Config, job: Job) -> JobExitStatus {
|
||||||
|
|
||||||
fn run_job(conf: Config, job_name: String, job: Job) -> JobExitStatus {
|
|
||||||
// limit threads to max_threads in the config
|
// limit threads to max_threads in the config
|
||||||
let mut threads = job.threads;
|
let mut threads = job.threads;
|
||||||
if job.threads > conf.max_threads {
|
if job.threads > conf.max_threads {
|
||||||
threads = conf.max_threads;
|
threads = conf.max_threads;
|
||||||
}
|
}
|
||||||
|
|
||||||
let container_name: String = format!("gregory-{}-{}-{}", job_name, job.revision, Uuid::now_v7());
|
let container_name: String = format!("gregory-{}-{}-{}", job.id, job.revision, Uuid::now_v7());
|
||||||
|
|
||||||
// do job log setup
|
// do job log setup
|
||||||
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
|
||||||
|
@ -111,7 +108,6 @@ fn run_job(conf: Config, job_name: String, job: Job) -> JobExitStatus {
|
||||||
.permissions();
|
.permissions();
|
||||||
PermissionsExt::set_mode(&mut perms, 0o755);
|
PermissionsExt::set_mode(&mut perms, 0o755);
|
||||||
|
|
||||||
// run the job
|
|
||||||
let mut cmd_args: Vec<String> = vec![
|
let mut cmd_args: Vec<String> = vec![
|
||||||
"run".to_string(),
|
"run".to_string(),
|
||||||
format!("--name={container_name}"),
|
format!("--name={container_name}"),
|
||||||
|
@ -154,8 +150,7 @@ fn run_job(conf: Config, job_name: String, job: Job) -> JobExitStatus {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
// remove tmp dir
|
||||||
// remove tmp dir/clean up
|
|
||||||
remove_dir_all(script_dir).unwrap();
|
remove_dir_all(script_dir).unwrap();
|
||||||
|
|
||||||
println!("{:?}", cmd_output);
|
println!("{:?}", cmd_output);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue