@@ -276,6 +276,51 @@ impl UserContext for RealUserContext {
276276 }
277277}
278278
279+ /// Context for pulling images with Podman, essentially equivalent to native Podman configuration
280+ fn build_pull_ctx ( config : & Config ) -> PodmanCtx {
281+ PodmanCtx {
282+ podman_path : PathBuf :: from ( & config. podman_path ) ,
283+ module : None ,
284+ graphroot : None ,
285+ runroot : None ,
286+ parallax_mount_program : None ,
287+ ro_store : None ,
288+ podman_env : None ,
289+ }
290+ }
291+
292+ /// Seed context for Parallax image-related operations (e.g. ls, migrate, rmi).
293+ /// Intended to have default graphroot and Parallax imagestore as read-only additionalimagestore.
294+ /// Functions using this should complete the context by resolving the default graphroot at runtime and setting it explicitly,
295+ /// because Parallax requires the graphroot to be passed as a CLI argument.
296+ pub fn build_parallax_seed_ctx ( config : & Config ) -> PodmanCtx {
297+ PodmanCtx {
298+ podman_path : PathBuf :: from ( & config. podman_path ) ,
299+ module : None ,
300+ graphroot : None ,
301+ runroot : None ,
302+ parallax_mount_program : None ,
303+ ro_store : Some ( PathBuf :: from ( & config. parallax_imagestore ) ) ,
304+ podman_env : None ,
305+ }
306+ }
307+
308+ /// Context which uses the Parallax imagestore (normally a read-only additionalimagestore location) as graphroot.
309+ /// This should be used only for read actions, since the Parallax store is not intended to be manipulated directly by Podman.
310+ /// This context is mostly useful to check if an image exists in the Parallax store (and therefore if it needs pulling or not)
311+ /// without using the run_ctx, which would trigger creation of custom Podman rootdirs and require cleanup in case of errors before run.
312+ pub fn build_readonly_ctx ( config : & Config ) -> PodmanCtx {
313+ PodmanCtx {
314+ podman_path : PathBuf :: from ( & config. podman_path ) ,
315+ module : None ,
316+ graphroot : Some ( PathBuf :: from ( & config. parallax_imagestore ) ) ,
317+ runroot : None ,
318+ parallax_mount_program : None ,
319+ ro_store : None ,
320+ podman_env : None ,
321+ }
322+ }
323+
279324/// Context for running containers. Fully custom Sarus Suite parameters (Podman module, Parallax imagestore, etc.).
280325/// Uses sarusctl-specific graphroot and runroot to not tamper with default podman rootdirs
281326pub fn build_run_ctx ( config : & Config , user : & CurrentUser ) -> PodmanCtx {
@@ -374,35 +419,6 @@ fn describe_dir_entries(path: &Path) -> String {
374419 }
375420}
376421
377- /// Seed context for Parallax image-related operations (e.g. ls, migrate, rmi).
378- /// Intended to have default graphroot and Parallax imagestore as read-only additionalimagestore.
379- /// Functions using this should complete the context by resolving the default graphroot at runtime and setting it explicitly,
380- /// because Parallax requires the graphroot to be passed as a CLI argument.
381- pub fn build_parallax_seed_ctx ( config : & Config ) -> PodmanCtx {
382- PodmanCtx {
383- podman_path : PathBuf :: from ( & config. podman_path ) ,
384- module : None ,
385- graphroot : None ,
386- runroot : None ,
387- parallax_mount_program : None ,
388- ro_store : Some ( PathBuf :: from ( & config. parallax_imagestore ) ) ,
389- podman_env : None ,
390- }
391- }
392-
393- /// Context for pulling images with Podman, essentially equivalent to native Podman configuration
394- fn build_pull_ctx ( config : & Config ) -> PodmanCtx {
395- PodmanCtx {
396- podman_path : PathBuf :: from ( & config. podman_path ) ,
397- module : None ,
398- graphroot : None ,
399- runroot : None ,
400- parallax_mount_program : None ,
401- ro_store : None ,
402- podman_env : None ,
403- }
404- }
405-
406422pub fn extract_images_from_yaml_str ( contents : & str ) -> Result < Vec < String > , AppError > {
407423 let manifest = yaml_serde:: from_str :: < yaml_serde:: Value > ( contents)
408424 . map_err ( |e| AppError :: Yaml ( e. to_string ( ) ) ) ?;
@@ -600,11 +616,11 @@ fn run_edf_command(
600616 deps : & AppDeps < ' _ > ,
601617) -> Result < AppOutput , AppError > {
602618 let user = deps. user . current_user ( ) ?;
619+ let ro_ctx = build_readonly_ctx ( config) ;
603620 let run_ctx = build_run_ctx ( config, & user) ;
604621 let mut output = AppOutput :: success ( "" ) ;
605622
606- // TODO checking image existence with the run_ctx means that sarusctl custom rootdirs will be created right here. Ensure proper cleanup of graphroot/runroot and parent in case of failure
607- if !deps. runtime . image_exists ( & edf. image , & run_ctx) ? {
623+ if !deps. runtime . image_exists ( & edf. image , & ro_ctx) ? {
608624 merge_output ( & mut output, pull_command ( & edf. image , config, deps) ?) ;
609625 }
610626
@@ -645,15 +661,15 @@ fn run_yaml_command(
645661 deps : & AppDeps < ' _ > ,
646662) -> Result < AppOutput , AppError > {
647663 let user = deps. user . current_user ( ) ?;
664+ let ro_ctx = build_readonly_ctx ( config) ;
648665 let mut run_ctx = build_run_ctx ( config, & user) ;
649666 run_ctx. module = None ;
650667
651668 let images = extract_images_from_yaml_manifest ( Path :: new ( filepath) ) ?;
652669 let mut output = AppOutput :: success ( "" ) ;
653670
654671 for image in images {
655- // TODO checking image existence with the run_ctx means that sarusctl custom rootdirs will be created right here. Ensure proper cleanup of graphroot/runroot and parent in case of failure
656- if !deps. runtime . image_exists ( & image, & run_ctx) ? {
672+ if !deps. runtime . image_exists ( & image, & ro_ctx) ? {
657673 merge_output ( & mut output, pull_command ( & image, config, deps) ?) ;
658674 }
659675 }
@@ -1016,7 +1032,25 @@ spec:
10161032 gid : 4321 ,
10171033 } ;
10181034
1035+ let pull = build_pull_ctx ( & config) ;
1036+ assert_eq ! ( pull. podman_path, PathBuf :: from( "/usr/bin/podman" ) ) ;
1037+
1038+ let seed = build_parallax_seed_ctx ( & config) ;
1039+ assert_eq ! ( seed. podman_path, PathBuf :: from( "/usr/bin/podman" ) ) ;
1040+ assert_eq ! (
1041+ seed. ro_store,
1042+ Some ( PathBuf :: from( "/scratch/user/parallax/store" ) )
1043+ ) ;
1044+
1045+ let ro = build_readonly_ctx ( & config) ;
1046+ assert_eq ! ( ro. podman_path, PathBuf :: from( "/usr/bin/podman" ) ) ;
1047+ assert_eq ! (
1048+ ro. graphroot,
1049+ Some ( PathBuf :: from( "/scratch/user/parallax/store" ) )
1050+ ) ;
1051+
10191052 let run = build_run_ctx ( & config, & user) ;
1053+ assert_eq ! ( run. podman_path, PathBuf :: from( "/usr/bin/podman" ) ) ;
10201054 assert_eq ! ( run. module, Some ( String :: from( "hpc" ) ) ) ;
10211055 assert_eq ! (
10221056 run. graphroot,
@@ -1026,6 +1060,10 @@ spec:
10261060 run. runroot,
10271061 Some ( PathBuf :: from( "/dev/shm/sarusctl-1234/runroot" ) )
10281062 ) ;
1063+ assert_eq ! (
1064+ seed. ro_store,
1065+ Some ( PathBuf :: from( "/scratch/user/parallax/store" ) )
1066+ ) ;
10291067 let env = run. podman_env . expect ( "missing env" ) ;
10301068 assert_eq ! ( env. get( OsStr :: new( "PARALLAX_MP_UID" ) ) . unwrap( ) , "1234" ) ;
10311069 assert_eq ! ( env. get( OsStr :: new( "PARALLAX_MP_GID" ) ) . unwrap( ) , "4321" ) ;
0 commit comments