Skip to content

Commit

Permalink
feat: Map GitLab Runner Docker Parameters (#28)
Browse files Browse the repository at this point in the history
We are currently only exposing a minimal set of adjustable parameters to
the REST API of runnrs. In an effort to prepare for advanced use-cases
this PR maps all available Docker Executor parameters of the GitLab
documentation to the glrcfg.

[GitLab Runners Docker
Section](https://archives.docs.gitlab.com/15.11/runner/configuration/advanced-configuration.html#the-runnersdocker-section)

We implement all types according to the specifications in the
documentation. For parameters whose default is explicitly specified, it
is taken over.

---------

Co-authored-by: Florian Eich <[email protected]>
  • Loading branch information
fabitosh and cdbrkfxrpt authored Jul 21, 2024
1 parent 5a4dca3 commit f795ea0
Show file tree
Hide file tree
Showing 8 changed files with 600 additions and 205 deletions.
356 changes: 169 additions & 187 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ chrono = { version = "0.4.38", features = [
"now",
"std",
], default-features = false }
glrcfg = { version = "0.1.0", path = "glrcfg", features = ["tracing", "sqlx"] }
glrcfg = { version = "0.2.0", path = "glrcfg", features = ["tracing", "sqlx"] }
jsonwebtoken = "9.2.0"
miette = { version = "7.2.0", features = ["fancy"] }
mime = "0.3.17"
Expand Down
8 changes: 6 additions & 2 deletions glrcfg/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,18 @@ name = "glrcfg"
description = "A Rust implementation of the GitLab Runner Advanced Configuration file format"
readme = "README.md"

version = "0.1.0"
version = "0.2.0"
edition = "2021"

license = "Apache-2.0"
repository.workspace = true
keywords = ["gitlab", "runner", "runners", "configuration", "config"]
exclude = [".github"]

authors = ["Florian Eich <[email protected]>"]
authors = [
"Florian Eich <[email protected]>",
"Fabio Meier <[email protected]>",
]

[dependencies]
chrono = { version = "0.4.38", default-features = false, features = [
Expand All @@ -37,5 +40,6 @@ sqlx = ["dep:sqlx"]
indoc = "2.0.5"
pretty_assertions = "1.4.0"
proptest = "1.5.0"
serde_json = "1.0.120"
test-strategy = "0.4.0"
toml = "0.8.12"
11 changes: 6 additions & 5 deletions glrcfg/src/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use url::Url;
static GOLANG_DURATION_REGEX_STR: &str = r"([+-]?(\d+(h|m|s|ms|us|µs|ns))+|0)";
static GOLANG_DURATION_REGEX: Lazy<Regex> = Lazy::new(|| {
Regex::new(&format!(r"^{GOLANG_DURATION_REGEX_STR}$"))
.expect("unable to instantiate GOLANG_DURATION_REGEX from given static string")
.expect("instantiating GOLANG_DURATION_REGEX from given static string must not fail")
});

/// Defines the log level. Options are `debug`, `info`, `warn`, `error`, `fatal`, and `panic`. This
Expand Down Expand Up @@ -59,6 +59,7 @@ pub struct GolangDurationParseError;
/// # use glrcfg::GolangDuration;
/// let duration = GolangDuration::parse("15m").unwrap();
/// assert_eq!(duration.as_str(), "15m");
/// assert!(GolangDuration::parse("42hours").is_err());
/// ```
#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
#[serde(transparent)]
Expand Down Expand Up @@ -163,14 +164,14 @@ mod test {
}

#[proptest]
fn parse_valid_golang_durations(#[strategy(GOLANG_DURATION_REGEX_STR)] token: String) {
assert_eq!(token, GolangDuration::parse(&token).unwrap().as_str());
fn parse_valid_golang_durations(#[strategy(GOLANG_DURATION_REGEX_STR)] duration: String) {
assert_eq!(duration, GolangDuration::parse(&duration).unwrap().as_str());
}

#[proptest]
fn parse_invalid_golang_durations(
#[filter(|t| !GOLANG_DURATION_REGEX.is_match(t))] token: String,
#[filter(|s| !GOLANG_DURATION_REGEX.is_match(s))] duration: String,
) {
assert!(GolangDuration::parse(token).is_err());
assert!(GolangDuration::parse(duration).is_err());
}
}
Loading

0 comments on commit f795ea0

Please sign in to comment.