@@ -11,9 +11,11 @@ use std::{
1111use base64:: prelude:: * ;
1212use color_eyre:: { Result , eyre:: eyre} ;
1313use eyre:: Context ;
14+ use futures:: StreamExt ;
1415use iroh:: SecretKey ;
1516use itertools:: Itertools ;
1617use reqwest:: Url ;
18+ use tokio:: { fs:: File , io:: AsyncWriteExt } ;
1719
1820use super :: api_client:: client:: { EdfSpec , ScriptSpec } ;
1921use 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