Skip to content

Commit 703d49b

Browse files
committed
add support for downloading coman squash if no squash specified
1 parent 37974f2 commit 703d49b

File tree

3 files changed

+46
-4
lines changed

3 files changed

+46
-4
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coman/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "coman"
3-
version = "0.4.0"
3+
version = "0.5.0"
44
edition = "2024"
55
description = "Compute Manager for managing HPC compute"
66
authors = ["Ralf Grubenmann <[email protected]>"]

coman/src/cscs/handlers.rs

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@ use std::{
1111
use base64::prelude::*;
1212
use color_eyre::{Result, eyre::eyre};
1313
use eyre::Context;
14+
use futures::StreamExt;
1415
use iroh::SecretKey;
1516
use itertools::Itertools;
1617
use reqwest::Url;
18+
use tokio::{fs::File, io::AsyncWriteExt};
1719

1820
use super::api_client::client::{EdfSpec, ScriptSpec};
1921
use crate::{
@@ -219,7 +221,47 @@ async fn inject_coman_squash(
219221
let config = Config::new().unwrap();
220222
let local_squash_path = match config.values.coman_squash_path.clone() {
221223
Some(path) => path,
222-
None => todo!(), //download from github for architecture
224+
None => {
225+
//download from github for architecture
226+
let system = config
227+
.values
228+
.cscs
229+
.systems
230+
.get(current_system)
231+
.ok_or(eyre!("couldn't find architecture for system {}", current_system))?;
232+
let architecture = system
233+
.architecture
234+
.first()
235+
.ok_or(eyre!("no architecture set for {}", current_system))?;
236+
let target_path = get_data_dir().join(format!("coman_{}.sqsh", architecture));
237+
if !target_path.exists() {
238+
let url = match architecture.as_str() {
239+
"arm64" => {
240+
"https://github.com/SwissDataScienceCenter/coman/releases/latest/download/coman_Linux-aarch64.sqsh"
241+
}
242+
"amd64" => {
243+
"https://github.com/SwissDataScienceCenter/coman/releases/latest/download/coman_Linux-x86_64.sqsh"
244+
}
245+
_ => {
246+
return Err(eyre!("unsupported architecture {}", architecture));
247+
}
248+
};
249+
let mut out = File::create(target_path.clone()).await?;
250+
let resp = reqwest::get(url).await?;
251+
match resp.error_for_status() {
252+
Ok(resp) => {
253+
let mut stream = resp.bytes_stream();
254+
while let Some(chunk_result) = stream.next().await {
255+
let chunk = chunk_result?;
256+
out.write_all(&chunk).await?;
257+
}
258+
out.flush().await?;
259+
}
260+
Err(e) => return Err(eyre!("couldn't download coman squash file: {}", e)),
261+
}
262+
}
263+
target_path
264+
}
223265
};
224266
let target = base_path.join("coman.sqsh");
225267
let file_meta = std::fs::metadata(local_squash_path.clone())?;
@@ -409,7 +451,7 @@ pub async fn cscs_job_start(
409451
match get_access_token().await {
410452
Ok(access_token) => {
411453
let api_client = CscsApi::new(access_token.0, platform).unwrap();
412-
let config = Config::new().unwrap();
454+
let config = Config::new()?;
413455
let current_system = &system.unwrap_or(config.values.cscs.current_system);
414456
let account = account.or(config.values.cscs.account);
415457
let user_info = api_client.get_userinfo(current_system).await?;

0 commit comments

Comments
 (0)