From aa1240bb35e56ba07aa44ff003aa46c607d6fdc1 Mon Sep 17 00:00:00 2001 From: Tobias Ribizel Date: Fri, 8 Nov 2024 00:16:39 +0100 Subject: [PATCH] make more options variable-expanded --- README.md | 4 ++-- src/config.rs | 6 +++--- src/template.rs | 14 ++++++++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 4ecc7e8..65a27c0 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ interval = 30 # - Any variables defined in runners..config_variables # - Any environment variables provided by gitlab-runner to this custom executor [launch] -# Executable name or path, will NOT be variable-expanded +# Executable name or path, will be variable-expanded executable = "sbatch" # Arguments to pass to the executable, they will be variable-expanded args = [] @@ -91,7 +91,7 @@ image_cache_dir = "$HOME/image_cache" image_tmp_dir = "$HOME/image_tmp" # Pull policy to use for images, will NOT be variable-expanded pull_policy = "if-not-present" -# Path to the apptainer executable (may be relative to workdir or $PATH), will NOT be variable-expanded +# Path to the apptainer executable (may be relative to workdir or $PATH), will be variable-expanded apptainer_executable = "apptainer" # Mount AMD GPU devices, will be variable-expanded gpu_amd = false diff --git a/src/config.rs b/src/config.rs index 9328ea1..d4ebc0a 100755 --- a/src/config.rs +++ b/src/config.rs @@ -110,7 +110,7 @@ pub struct GitLabRunnerInstance { #[derive(Debug, DocumentedFields, FieldNamesAsArray, Deserialize, Serialize)] pub struct GitLabLaunchConfig { - /// Executable name or path, will NOT be variable-expanded + /// Executable name or path, will be variable-expanded pub executable: String, /// Arguments to pass to the executable, they will be variable-expanded pub args: Vec, @@ -150,8 +150,8 @@ pub struct GitLabCustomExecutorConfigTemplate { pub image_tmp_dir: Option, /// Pull policy to use for images, will NOT be variable-expanded pub pull_policy: GitLabExecutorPullPolicy, - /// Path to the apptainer executable (may be relative to workdir or $PATH), will NOT be variable-expanded - pub apptainer_executable: PathBuf, + /// Path to the apptainer executable (may be relative to workdir or $PATH), will be variable-expanded + pub apptainer_executable: String, #[serde(default = "false_bool_or_string")] /// Mount AMD GPU devices, will be variable-expanded pub gpu_amd: BoolOrString, diff --git a/src/template.rs b/src/template.rs index fe04986..458745f 100644 --- a/src/template.rs +++ b/src/template.rs @@ -75,7 +75,8 @@ pub fn expand_runner_config_template( .environment .as_ref() .map(|m| m.iter().map(|v| string_expand(v)).collect()) - .transpose()?, + .transpose() + .context("environment")?, executor: match &config.executor { Executor::Custom { custom: @@ -143,14 +144,17 @@ pub fn expand_executor_config_template( .transpose() .context("image_tmp_dir")?, pull_policy: executor.pull_policy, - apptainer_executable: executor.apptainer_executable.clone(), + apptainer_executable: string_expand(&executor.apptainer_executable) + .context("apptainer_executable")? + .into(), gpu_amd: expand_to_bool(&executor.gpu_amd).context("gpu_amd")?, gpu_nvidia: expand_to_bool(&executor.gpu_nvidia).context("gpu_nvidia")?, mount: executor .mount .iter() .map(|v| string_expand(v)) - .collect::>>()?, + .collect::>>() + .context("mount")?, builds_dir: string_expand( executor .builds_dir @@ -195,7 +199,9 @@ pub fn expand_launch_config_template( v.into_iter().map(|s| string_expand(s)).collect() }; Ok(GitLabLaunchConfig { - executable: launch.executable.clone(), + executable: string_expand(&launch.executable) + .context("executable")? + .into(), args: string_array_expand(&launch.args).context("args")?, workdir: optional_string_expand(&launch.workdir).context("workdir")?, stdin: optional_string_expand(&launch.stdin).context("stdin")?,