Skip to content

Commit 4cd05f8

Browse files
committed
allow setting custom mount dirs in jobs
1 parent ad6f4e0 commit 4cd05f8

7 files changed

Lines changed: 55 additions & 5 deletions

File tree

coman/.config/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ srun --environment={{environment_file}} {{command}}
1616

1717
edf_file_template = """
1818
image = "{{edf_image}}"
19-
mounts = ["${SCRATCH}:/scratch"]
19+
mounts = [{% for source, target in mount %}"{{source}}:{{target}}",{% endfor %}]
2020
workdir = "{{container_workdir}}"
2121
2222
[env]

coman/src/cli.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ pub enum CscsCommands {
5454
command: CscsSystemCommands,
5555
},
5656
}
57+
58+
#[allow(clippy::large_enum_variant)]
5759
#[derive(Subcommand, Debug)]
5860
pub enum CscsJobCommands {
5961
#[clap(alias("ls"), about = "List all jobs [aliases: ls]")]
@@ -75,6 +77,8 @@ pub enum CscsJobCommands {
7577
workdir: Option<String>,
7678
#[clap(short='E', value_name="KEY=VALUE", value_parser=parse_key_val::<String,String>, help="Environment variables to set in the container")]
7779
env: Vec<(String, String)>,
80+
#[clap(short='M', value_name="PATH:CONTAINER_PATH", value_parser=parse_key_val_colon::<String,String>, help="Paths to mount inside container")]
81+
mount: Vec<(String, String)>,
7882
#[clap(short, long, help = "The docker image to use")]
7983
image: Option<DockerImageUrl>,
8084
#[clap(trailing_var_arg = true, help = "The command to run in the container")]
@@ -178,3 +182,15 @@ where
178182
.ok_or_else(|| format!("invalid KEY=value: no `=` found in `{s}`"))?;
179183
Ok((s[..pos].parse()?, s[pos + 1..].parse()?))
180184
}
185+
fn parse_key_val_colon<T, U>(s: &str) -> Result<(T, U), Box<dyn Error + Send + Sync + 'static>>
186+
where
187+
T: std::str::FromStr,
188+
T::Err: Error + Send + Sync + 'static,
189+
U: std::str::FromStr,
190+
U::Err: Error + Send + Sync + 'static,
191+
{
192+
let pos = s
193+
.find(':')
194+
.ok_or_else(|| format!("invalid KEY:value: no `:` found in `{s}`"))?;
195+
Ok((s[..pos].parse()?, s[pos + 1..].parse()?))
196+
}

coman/src/cscs/cli.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,23 @@ pub(crate) async fn cli_cscs_job_start(
106106
command: Option<Vec<String>>,
107107
workdir: Option<String>,
108108
env: Vec<(String, String)>,
109+
mount: Vec<(String, String)>,
109110
system: Option<String>,
110111
platform: Option<ComputePlatform>,
111112
account: Option<String>,
112113
) -> Result<()> {
113-
cscs_start_job(script_file, image, command, workdir, env, system, platform, account).await
114+
cscs_start_job(
115+
script_file,
116+
image,
117+
command,
118+
workdir,
119+
env,
120+
mount,
121+
system,
122+
platform,
123+
account,
124+
)
125+
.await
114126
}
115127

116128
pub(crate) async fn cli_cscs_job_cancel(

coman/src/cscs/handlers.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
use std::os::unix::fs::MetadataExt;
33
#[cfg(target_family = "windows")]
44
use std::os::windows::fs::MetadataExt;
5-
use std::path::PathBuf;
5+
use std::{collections::HashMap, path::PathBuf};
66

77
use color_eyre::{Result, eyre::eyre};
88
use reqwest::Url;
@@ -153,6 +153,7 @@ pub async fn cscs_start_job(
153153
command: Option<Vec<String>>,
154154
container_workdir: Option<String>,
155155
env: Vec<(String, String)>,
156+
mount: Vec<(String, String)>,
156157
system: Option<String>,
157158
platform: Option<ComputePlatform>,
158159
account: Option<String>,
@@ -186,6 +187,8 @@ pub async fn cscs_start_job(
186187

187188
let mut envvars = config.cscs.env.clone();
188189
envvars.extend(env);
190+
let mut mount: HashMap<String, String> = mount.into_iter().collect();
191+
mount.entry("${SCRATCH}".to_owned()).or_insert("/scratch".to_owned());
189192

190193
let mut tera = tera::Tera::default();
191194

@@ -221,6 +224,7 @@ pub async fn cscs_start_job(
221224
context.insert("edf_image", &docker_image.to_edf());
222225
context.insert("container_workdir", &container_workdir);
223226
context.insert("env", &envvars);
227+
context.insert("mount", &mount);
224228

225229
let environment_file = tera.render("environment.toml", &context)?;
226230
api_client.mkdir(current_system, base_path.clone()).await?;

coman/src/main.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,20 @@ async fn main() -> Result<()> {
7070
command,
7171
workdir,
7272
env,
73+
mount,
7374
} => {
74-
cli_cscs_job_start(script_file, image, command, workdir, env, system, platform, account).await?
75+
cli_cscs_job_start(
76+
script_file,
77+
image,
78+
command,
79+
workdir,
80+
env,
81+
mount,
82+
system,
83+
platform,
84+
account,
85+
)
86+
.await?
7587
}
7688
cli::CscsJobCommands::Cancel { job_id } => cli_cscs_job_cancel(job_id, system, platform).await?,
7789
},

firecrest_client/build.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ fn main() -> Result<()> {
2828
"default(Some(\"gzip\".to_string())",
2929
"default(Some(\"gzip\".to_string().into())",
3030
);
31+
// remove source as it's a temporary file and we don't want to change it every time the build runs, even if
32+
// there are no changes
33+
let content = content
34+
.lines()
35+
.filter(|l| !l.starts_with("//! Source: "))
36+
.collect::<Vec<&str>>()
37+
.join("\n");
3138
let content = format!(
3239
"// @generated by oas3-gen
3340
#![allow(clippy::all)]

firecrest_client/src/types.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
//! AUTO-GENERATED CODE - DO NOT EDIT!
1010
//!
1111
//! FirecREST
12-
//! Source: /tmp/.tmpLCCr2S.json
1312
//! Version: 2.4.1
1413
//! Generated by `oas3-gen v0.21.1`
1514
//!

0 commit comments

Comments
 (0)