Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion coman/.config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ srun --environment={{environment_file}} {{command}}

edf_file_template = """
image = "{{edf_image}}"
mounts = ["${SCRATCH}:/scratch"]
mounts = [{% for source, target in mount %}"{{source}}:{{target}}",{% endfor %}]
workdir = "{{container_workdir}}"

[env]
Expand Down
16 changes: 16 additions & 0 deletions coman/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ pub enum CscsCommands {
command: CscsSystemCommands,
},
}

#[allow(clippy::large_enum_variant)]
#[derive(Subcommand, Debug)]
pub enum CscsJobCommands {
#[clap(alias("ls"), about = "List all jobs [aliases: ls]")]
Expand All @@ -75,6 +77,8 @@ pub enum CscsJobCommands {
workdir: Option<String>,
#[clap(short='E', value_name="KEY=VALUE", value_parser=parse_key_val::<String,String>, help="Environment variables to set in the container")]
env: Vec<(String, String)>,
#[clap(short='M', value_name="PATH:CONTAINER_PATH", value_parser=parse_key_val_colon::<String,String>, help="Paths to mount inside container")]
mount: Vec<(String, String)>,
#[clap(short, long, help = "The docker image to use")]
image: Option<DockerImageUrl>,
#[clap(trailing_var_arg = true, help = "The command to run in the container")]
Expand Down Expand Up @@ -178,3 +182,15 @@ where
.ok_or_else(|| format!("invalid KEY=value: no `=` found in `{s}`"))?;
Ok((s[..pos].parse()?, s[pos + 1..].parse()?))
}
fn parse_key_val_colon<T, U>(s: &str) -> Result<(T, U), Box<dyn Error + Send + Sync + 'static>>
where
T: std::str::FromStr,
T::Err: Error + Send + Sync + 'static,
U: std::str::FromStr,
U::Err: Error + Send + Sync + 'static,
{
let pos = s
.find(':')
.ok_or_else(|| format!("invalid KEY:value: no `:` found in `{s}`"))?;
Ok((s[..pos].parse()?, s[pos + 1..].parse()?))
}
14 changes: 13 additions & 1 deletion coman/src/cscs/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,23 @@ pub(crate) async fn cli_cscs_job_start(
command: Option<Vec<String>>,
workdir: Option<String>,
env: Vec<(String, String)>,
mount: Vec<(String, String)>,
system: Option<String>,
platform: Option<ComputePlatform>,
account: Option<String>,
) -> Result<()> {
cscs_start_job(script_file, image, command, workdir, env, system, platform, account).await
cscs_start_job(
script_file,
image,
command,
workdir,
env,
mount,
system,
platform,
account,
)
.await
}

pub(crate) async fn cli_cscs_job_cancel(
Expand Down
6 changes: 5 additions & 1 deletion coman/src/cscs/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
use std::os::unix::fs::MetadataExt;
#[cfg(target_family = "windows")]
use std::os::windows::fs::MetadataExt;
use std::path::PathBuf;
use std::{collections::HashMap, path::PathBuf};

use color_eyre::{Result, eyre::eyre};
use reqwest::Url;
Expand Down Expand Up @@ -153,6 +153,7 @@ pub async fn cscs_start_job(
command: Option<Vec<String>>,
container_workdir: Option<String>,
env: Vec<(String, String)>,
mount: Vec<(String, String)>,
system: Option<String>,
platform: Option<ComputePlatform>,
account: Option<String>,
Expand Down Expand Up @@ -186,6 +187,8 @@ pub async fn cscs_start_job(

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

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

Expand Down Expand Up @@ -221,6 +224,7 @@ pub async fn cscs_start_job(
context.insert("edf_image", &docker_image.to_edf());
context.insert("container_workdir", &container_workdir);
context.insert("env", &envvars);
context.insert("mount", &mount);

let environment_file = tera.render("environment.toml", &context)?;
api_client.mkdir(current_system, base_path.clone()).await?;
Expand Down
14 changes: 13 additions & 1 deletion coman/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,20 @@ async fn main() -> Result<()> {
command,
workdir,
env,
mount,
} => {
cli_cscs_job_start(script_file, image, command, workdir, env, system, platform, account).await?
cli_cscs_job_start(
script_file,
image,
command,
workdir,
env,
mount,
system,
platform,
account,
)
.await?
}
cli::CscsJobCommands::Cancel { job_id } => cli_cscs_job_cancel(job_id, system, platform).await?,
},
Expand Down
7 changes: 7 additions & 0 deletions firecrest_client/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ fn main() -> Result<()> {
"default(Some(\"gzip\".to_string())",
"default(Some(\"gzip\".to_string().into())",
);
// remove source as it's a temporary file and we don't want to change it every time the build runs, even if
// there are no changes
let content = content
.lines()
.filter(|l| !l.starts_with("//! Source: "))
.collect::<Vec<&str>>()
.join("\n");
let content = format!(
"// @generated by oas3-gen
#![allow(clippy::all)]
Expand Down
1 change: 0 additions & 1 deletion firecrest_client/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
//! AUTO-GENERATED CODE - DO NOT EDIT!
//!
//! FirecREST
//! Source: /tmp/.tmpLCCr2S.json
//! Version: 2.4.1
//! Generated by `oas3-gen v0.21.1`
//!
Expand Down