123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164openCore_kernelopenBistro_internalstypeinsert=|PathofWorkflow.path|Path_listof{elts:Workflow.pathlist;sep:string;quote:charoption;}|Stringofstringtypet={db:Db.t;allowed_containers:[`Docker|`Singularity]list;tmp_dir:string;(* host all execution *)dest:string;(* expected path for the target *)tmp:string;(* temp dir for the process *)stdout:string;stderr:string;dep:Workflow.path->string;file_dump:insertTemplate.t->string;np:int;mem:int;uid:int;}letmake~db~allowed_containers~np~mem~id=lettmp_dir=Db.tmpdbidinletfile_dumptoks=Filename.concattmp_dir(Misc.digesttoks)in{db;tmp_dir;allowed_containers;tmp=Filename.concattmp_dir"tmp";dest=Filename.concattmp_dir"dest";stdout=Db.stdoutdbid;stderr=Db.stderrdbid;file_dump;dep=(Db.pathdb);np;mem;uid=Unix.getuid();}letdocker_cache_dir="/bistro/data"typecontainer_mount={mount_host_location:string;mount_container_location:string;file_container_location:string;}letcontainer_mount:Db.t->Workflow.path->container_mount=fundbpath->matchpathwith|Cache_idid->{mount_host_location=Db.cache_dirdb;mount_container_location=docker_cache_dir;file_container_location=Filename.concatdocker_cache_dirid}|FS_pathpath->letid=Misc.digestpathinletcontainer_path=Filename.concatdocker_cache_diridin{mount_host_location=path;mount_container_location=container_path;file_container_location=container_path;}|Cd(Cache_idid,sel)->{mount_host_location=Db.cache_dirdb;mount_container_location=docker_cache_dir;file_container_location=List.reduce_exn~f:Filename.concat[docker_cache_dir;id;Path.to_stringsel]}|Cd(FS_pathpath,sel)->letid=Misc.digestpathin{mount_host_location=path;mount_container_location=Filename.concatdocker_cache_dirid;file_container_location=List.reduce_exn~f:Filename.concat[docker_cache_dir;id;Path.to_stringsel]}|Cd(Cd_,_)->assertfalseletdockerizeenv={db=env.db;tmp_dir="/bistro";allowed_containers=[];dest="/bistro/dest";tmp="/bistro/tmp";file_dump=(funtoks->Filename.concatdocker_cache_dir(Misc.digesttoks));dep=(funu->(container_mountenv.dbu).file_container_location);np=env.np;mem=env.mem;stdout=env.stdout;stderr=env.stderr;uid=env.uid;}letallows_dockerenv=List.mem~equal:Poly.equalenv.allowed_containers`Dockerletsingularizeenv={envwithallowed_containers=[];}letfind_docker_imageenv=List.find_mapenv~f:Command.(function|Docker_imagei->Somei|Singularity_image_->None)letfind_singularity_imageenv=List.find_mapenv~f:Command.(function|Docker_image_->None|Singularity_imagei->Somei)letrecchoose_containerallowed_containersimages=matchallowed_containerswith|[]->`Plain|`Docker::others->((* docker only accepts docker images *)matchfind_docker_imageimageswith|Somei->`Docker_containeri|None->choose_containerothersimages)|`Singularity::others->(matchfind_singularity_imageimageswith|Somei->`Singularity_container(Command.Singularity_imagei)|None->matchfind_docker_imageimageswith|Somei->`Singularity_container(Command.Docker_imagei)|None->choose_containerothersimages)letrecimages_for_singularityallowed_containers=function|Command.Simple_command_->[]|And_listxs|Or_listxs|Pipe_listxs->images_for_singularity_auxallowed_containersxs|Within_container(img,_)->matchchoose_containerallowed_containersimgwith|`Plain|`Docker_container_->[]|`Singularity_containerimg->[img]andimages_for_singularity_auxallowed_containersxs=List.concat_mapxs~f:(images_for_singularityallowed_containers)