add privileged parameter for jobs and improve docs

also pretty print config
This commit is contained in:
askiiart 2024-12-26 19:55:49 -06:00
parent eaab82e6c5
commit c098e3bf7e
Signed by untrusted user who does not match committer: askiiart
GPG key ID: EA85979611654C30
3 changed files with 37 additions and 12 deletions

View file

@ -1,33 +1,36 @@
# Config Reference
- Config location: `gregory.yml`
- Default config location: `gregory.yml`
- Example: see [`gregory.example.yml`](/gregory.example.yml)
Note: This primarily uses LibreWolf and Fedora as examples of packages and distros. Also note that rather than separating by what distro, you can instead use those field to define which repo.
## Top-level config
- `log-level`: Log level `0`-`3` (error, warning, info, or debug)
- `log-level` (integer): Log level `0`-`3` (error, warning, info, or debug)
- Default: 1 - warning
- `max-threads`: The maximum number of threads to be used
- `max-threads` (integer): The maximum number of threads to be used
- **See also**: [`threads`](#job-config)
- Default is CPU's threads - 2
- `max-jobs`: The maximum number of jobs to be run at once
- `max-jobs` (integer): The maximum number of jobs to be run at once
- Default is 1
**Multithreading notes (IMPORTANT)**: Gregory will first run compilation jobs, then packaging jobs for whatever programs are done, then run the `update-repo` for whichever distros are finished. For this reason, the distro names listed under `packaging` and `update-repo` *must* match.
**Multithreading/multiple jobs is not implemented yet**
## Job config
- `threads`: The maximum number of vCPUs/threads to dedicate to a job; this can be a fractional number
- `threads` (integer): The maximum number of vCPUs/threads to dedicate to a job; this can be a fractional number
- Set this as less than or equal to the max number of threads the thing you're running will use
- See `--cpus` in the [`podman run` docs](https://docs.podman.io/en/latest/markdown/podman-run.1.html#cpus)
- *Root may be required for this argument*
- If not specified, it will fall back to `max-threads`
- `image`: The Docker image to run the job in *(required)*
- `commands`: The commands to run *(required)*
- `image` (string): The Docker image to run the job in *(required)*
- `commands` (sequence): The commands to run *(required)*
- TODO: Add command file/bash script instead
- `volumes`: Names of volumes as defined in [`volumes` (top level)](#volumes)
- `volumes` (sequence): Names of volumes as defined in [`volumes` (top level)](#volumes)
- `privileged` (bool): Whether the job's container should be privileged
## Packages (`packages`)
@ -106,7 +109,7 @@ update-repo:
## Volumes
Lists a volume in Docker's volume format, to be used in [job configs](#job-config)
Lists a volume in Docker/Podman's volume format, to be used in [job configs](#job-config)
```yml
volumes:

View file

@ -22,31 +22,46 @@ pub(crate) struct Config {
max_threads: u32,
/// Holds the packages, including their compilation and packaging
///
/// Format: { "librewolf": Package { compilation, packaging } }
/// Format: `{ "librewolf": Package { compilation, packaging } }`
///
/// See [`Package`] for details
packages: HashMap<String, Package>,
/// The jobs for updating the repo, organized by distro/repo name
#[serde(rename = "update-repo")]
update_repo: HashMap<String, Job>,
/// All volumes, organized like this:
///
/// Format: `{ "librewolf": "./data/librewolf:/librewolf" }` - like Docker/Podman formatting
#[serde(default = "volumes")]
volumes: HashMap<String, String>,
}
#[derive(Debug, Clone, Deserialize)]
pub(crate) struct Job {
#[serde(default = "job_threads")]
/// How many threads to limit this job to; recommended to set it to the max threads the job will use
///
/// If `threads` isn't specified, it will fall back to `max_threads` (from [`Config`]); the same behavior applies if `threads` is greater than `max_threads`
#[serde(default = "job_threads")]
threads: u32,
/// The OCi image to run it in
///
/// For example, `docker.io/library/debian:latest`
image: String,
///
commands: Vec<String>,
volumes: Option<Vec<String>>,
/// Whether the job should be privileged
///
/// Defauolt: false
#[serde(default = "privileged")]
privileged: bool,
}
#[derive(Debug, Clone, Deserialize)]
pub(crate) struct Package {
/// The compilation [`Job`] - optional
compilation: Option<Job>,
/// The packaging [`Job`]s, organized by the distro/repo name
packaging: HashMap<String, Job>,
}
@ -89,3 +104,8 @@ pub(crate) fn volumes() -> HashMap<String, String> {
pub(crate) fn job_threads() -> u32 {
return max_threads();
}
/// Default (false) for whether a job should be privileged
pub(crate) fn privileged() -> bool {
return false;
}

View file

@ -40,5 +40,7 @@ fn main() {
fn run(config_path: String) {
let config = config_from_file(config_path);
println!("{:?}", config);
println!("{:#?}", config);
}
fn run_job() {}