1010from DIRAC import S_ERROR , gConfig , gLogger
1111from DIRAC .Core .Base .Script import Script
1212from DIRAC .Core .Security .Locations import getCAsLocation , getProxyLocation , getVOMSLocation
13+ from DIRAC .Core .Utilities .Os import safe_listdir
1314from DIRAC .Core .Utilities .Subprocess import systemCall
1415
1516
@@ -73,7 +74,7 @@ def main():
7374 cmd .extend (["--contain" ]) # use minimal /dev and empty other directories (e.g. /tmp and $HOME)
7475 cmd .extend (["--ipc" ]) # run container in a new IPC namespace
7576 cmd .extend (["--pid" ]) # run container in a new PID namespace
76- cmd .extend (["--bind" , f"{ os .getcwd ()} :/mnt " ]) # bind current directory for dirac_container.sh
77+ cmd .extend (["--bind" , f"{ os .getcwd ()} :/" ]) # bind current directory for dirac_container.sh
7778 if proxy_location :
7879 cmd .extend (["--bind" , f"{ proxy_location } :/etc/proxy" ]) # bind proxy file
7980 cmd .extend (["--bind" , f"{ getCAsLocation ()} :/etc/grid-security/certificates" ]) # X509_CERT_DIR
@@ -83,12 +84,18 @@ def main():
8384 cmd .extend (["--bind" , f"{ vomses_location } :/etc/grid-security/vomses" ]) # X509_VOMSES
8485 cmd .extend (["--bind" , "{0}:{0}:ro" .format (etc_dir )]) # etc dir for dirac.cfg
8586 cmd .extend (["--bind" , "{0}:{0}:ro" .format (os .path .join (os .path .realpath (sys .base_prefix )))]) # code dir
86- cmd .extend (["--cwd" , "/mnt" ]) # set working directory to /mnt
87+ # here bind optional paths
88+ for bind_path in gConfig .getValue ("/Resources/Computing/Singularity/BindPaths" , []):
89+ if safe_listdir (bind_path ):
90+ cmd .extend (["--bind" , f"{ bind_path } :{ bind_path } " ])
91+ else :
92+ gLogger .warning (f"Bind path { bind_path } does not exist, skipping" )
93+ cmd .extend (["--cwd" , "/" ]) # set working directory
8794
8895 rootImage = user_image or gConfig .getValue ("/Resources/Computing/Singularity/ContainerRoot" ) or CONTAINER_DEFROOT
8996
9097 if os .path .isdir (rootImage ) or os .path .isfile (rootImage ):
91- cmd .extend ([rootImage , "/mnt /dirac_container.sh" ])
98+ cmd .extend ([rootImage , ". /dirac_container.sh" ])
9299 else :
93100 # if we are here is because there's no image, or it is not accessible (e.g. not on CVMFS)
94101 gLogger .error ("Apptainer image to exec not found: " , rootImage )
0 commit comments