update config file formatting (add dependencies, remove log-level)

This commit is contained in:
askiiart 2025-01-17 17:48:10 -06:00
parent add254d996
commit ecd637af9c
Signed by untrusted user who does not match committer: askiiart
GPG key ID: 6A32977DAF31746A
4 changed files with 43 additions and 26 deletions

View file

@ -14,8 +14,6 @@ Note: This primarily uses LibreWolf and Fedora as examples of packages and distr
## Top-level config
- `log-level` (integer): Log level `0`-`3` (error, warning, info, or debug)
- Default: 1 - warning
- `max-threads` (float): The maximum number of threads to be used
- **See also**: [`threads`](#job-config)
- Default is CPU's threads - 2
@ -48,8 +46,6 @@ Note: This primarily uses LibreWolf and Fedora as examples of packages and distr
- `shell` (string): The shell to run the commands in
- Default: `/bin/sh`
Note: `id` and `revision` are *not* for the package version, they are for
## Packages (`packages`)
Example:
@ -59,6 +55,8 @@ Example:
[packages.librewolf]
dependencies = ["some-librewolf-dependency"]
[packages.librewolf.compilation]
id = "1"
revision = "2"
@ -77,6 +75,8 @@ Example:
volumes = ["librewolf"]
```
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.
### Compilation (optional)
Defines the compilation of a program, if applicable. Stuff like Python scripts can skip this.

View file

@ -1,27 +1,46 @@
max-jobs = 4
max-threads = 10
log-level = 0
[packages]
[packages.librewolf]
dependencies = ["some-librewolf-dependency"]
[packages.librewolf.compilation]
id = "1"
revision = "2"
threads = 8
threads = 6
image = "docker.io/library/debian"
commands = ["echo hi", "echo helloooooooooo"]
volumes = ["librewolf"]
[packages.librewolf.packaging.fedora]
threads = 8
threads = 2
image = "docker.io/library/fedora"
commands = [
"echo did you ever hear the tragedy of darth plageuis the wise?",
"echo it\\'s not a story the jedi would tell you",
]
volumes = ["librewolf"]
volumes = ["librewolf", "fedora-repo"]
[packages.some-librewolf-dependency]
[packages.some-librewolf-dependency.compilation]
id = "1"
revision = "2"
threads = 2
image = "docker.io/library/debian"
commands = ["echo hi", "echo helloooooooooo"]
volumes = ["other-workspace"]
[packages.some-librewolf-dependency.packaging.fedora]
id = "1"
revision = "2"
threads = 2
image = "docker.io/library/fedora"
commands = ["echo hello worldddddddd"]
volumes = ["other-workspace", "fedora-repo"]
[update-repo]
@ -33,3 +52,5 @@ log-level = 0
[volumes]
librewolf = "./data/librewolf:/librewolf"
other-workspace = "./data/other-workspace:/workspace"
fedora-repo = "./data/fedora-repo:/fedora-repo"

View file

@ -8,15 +8,6 @@ use std::{collections::HashMap, fs, thread};
/// The config for gregory
#[derive(Debug, Clone, Deserialize)]
pub(crate) struct Config {
/// What level to log at
///
/// - 0: Error
/// - 1: Warning
/// - 2: Info
/// - 3: Debug
#[serde(default = "log_level", rename = "log-level")]
// the rename lets it use `log-level` instead in the toml file - this is not an alias, `log_level` in the toml will *not* work
pub(crate) log_level: u8,
/// Maximum number of jobs to run simultaneously
#[serde(default = "max_jobs", rename = "max-jobs")]
pub(crate) max_jobs: u32,
@ -27,7 +18,7 @@ pub(crate) struct Config {
pub(crate) data_dir: String,
/// Holds the packages, including their compilation and packaging
///
/// Format: `{ "librewolf": Package { compilation, packaging } }`
/// See config reference in the docs for details.
///
/// See [`Package`] for details
pub(crate) packages: HashMap<String, Package>,
@ -36,11 +27,12 @@ pub(crate) struct Config {
pub(crate) update_repo: HashMap<String, Job>,
/// All volumes, organized like this:
///
/// Format: `{ "librewolf": "./data/librewolf:/librewolf" }` - like Docker/Podman formatting
/// Format: `librewolf = "./data/librewolf:/librewolf"` - like Docker/Podman formatting
#[serde(default = "volumes")]
pub(crate) volumes: HashMap<String, String>,
}
/// Holds the data for a job
#[derive(Debug, Clone, Deserialize)]
pub(crate) struct Job {
/// An ID to identify the job, such as the compilation of a program
@ -73,6 +65,9 @@ pub(crate) struct Job {
/// Holds the data for a certain package's config
#[derive(Debug, Clone, Deserialize)]
pub(crate) struct Package {
/// What other packages gregory handles which this depends on
#[serde(default = "dependencies")]
pub(crate) dependencies: Vec<String>,
/// The compilation [`Job`] - optional
pub(crate) compilation: Option<Job>,
/// The packaging [`Job`]s, organized by the distro/repo name
@ -118,11 +113,6 @@ pub(crate) fn config_from_file(filename: String) -> Result<Config, Error> {
// === ===
// ==========================
/// Returns the default log level (1 - warning)
pub(crate) fn log_level() -> u8 {
return 1;
}
/// Returns the default number of max threads.
pub(crate) fn max_threads() -> f32 {
let total_threads = thread::available_parallelism().unwrap().get() as f32;
@ -175,3 +165,7 @@ pub(crate) fn revision() -> String {
pub(crate) fn data() -> String {
return "./data".to_string();
}
pub(crate) fn dependencies() -> Vec<String> {
return Vec::new();
}

View file

@ -2,10 +2,12 @@ use crate::data;
#[cfg(test)]
use alphanumeric_sort::sort_str_slice;
// FIXME: config entries are returned in a random order, so disabling this test for now
/*
#[test]
fn test_config() {
// It's a pain to make the config manually so I'm just doing this lol
let conf = "Config { log_level: 0, max_jobs: 4, max_threads: 10, data_dir: \"./data\", packages: {\"librewolf\": Package { compilation: Some(Job { id: \"1\", revision: \"2\", threads: 8, image: \"docker.io/library/debian\", commands: [\"echo hi\", \"echo helloooooooooo\"], volumes: Some([\"librewolf\"]), privileged: false, shell: \"/bin/sh\" }), packaging: {\"fedora\": Job { id: \"-1\", revision: \"1\", threads: 8, image: \"docker.io/library/fedora\", commands: [\"echo did you ever hear the tragedy of darth plageuis the wise?\", \"echo it\\\\'s not a story the jedi would tell you\"], volumes: Some([\"librewolf\"]), privileged: false, shell: \"/bin/sh\" }} }}, update_repo: {\"fedora\": Job { id: \"-1\", revision: \"1\", threads: 4, image: \"docker.io/library/fedora\", commands: [\"echo hai\"], volumes: Some([\"librewolf\"]), privileged: false, shell: \"/bin/sh\" }}, volumes: {\"librewolf\": \"./data/librewolf:/librewolf\"} }";
let conf = "Config { max_jobs: 4, max_threads: 10, data_dir: \"./data\", packages: {\"librewolf\": Package { compilation: Some(Job { id: \"1\", revision: \"2\", threads: 8, image: \"docker.io/library/debian\", commands: [\"echo hi\", \"echo helloooooooooo\"], volumes: Some([\"librewolf\"]), privileged: false, shell: \"/bin/sh\" }), packaging: {\"fedora\": Job { id: \"-1\", revision: \"1\", threads: 8, image: \"docker.io/library/fedora\", commands: [\"echo did you ever hear the tragedy of darth plageuis the wise?\", \"echo it\\\\'s not a story the jedi would tell you\"], volumes: Some([\"librewolf\"]), privileged: false, shell: \"/bin/sh\" }} }}, update_repo: {\"fedora\": Job { id: \"-1\", revision: \"1\", threads: 4, image: \"docker.io/library/fedora\", commands: [\"echo hai\"], volumes: Some([\"librewolf\"]), privileged: false, shell: \"/bin/sh\" }}, volumes: {\"librewolf\": \"./data/librewolf:/librewolf\"} }";
assert_eq!(
format!(
"{:?}",
@ -13,7 +15,7 @@ fn test_config() {
),
conf
);
}
} */
#[test]
/// There sorting tests aren't to test the program, more to test the crate works how I want, especially if I switch crates