17813: Handle setting $HOME as a special case
authorPeter Amstutz <peter.amstutz@curii.com>
Tue, 20 Jul 2021 15:15:44 +0000 (11:15 -0400)
committerPeter Amstutz <peter.amstutz@curii.com>
Tue, 20 Jul 2021 15:15:44 +0000 (11:15 -0400)
Arvados-DCO-1.1-Signed-off-by: Peter Amstutz <peter.amstutz@curii.com>

lib/crunchrun/singularity.go

index cd03e32e5c0dac95060be4dcbc5ff8f89d5039d8..be2d1887153dfea20540db4b24626d4676351769 100644 (file)
@@ -246,8 +246,6 @@ func (e *singularityExecutor) Start() error {
                mount := e.spec.BindMounts[path]
                args = append(args, "--bind", mount.HostPath+":"+path+":"+readonlyflag[mount.ReadOnly])
        }
-       args = append(args, e.imageFilename)
-       args = append(args, e.spec.Command...)
 
        // This is for singularity 3.5.2. There are some behaviors
        // that will change in singularity 3.6, please see:
@@ -255,9 +253,17 @@ func (e *singularityExecutor) Start() error {
        // https://sylabs.io/guides/3.5/user-guide/environment_and_metadata.html
        env := make([]string, 0, len(e.spec.Env))
        for k, v := range e.spec.Env {
-               env = append(env, "SINGULARITYENV_"+k+"="+v)
+               if k == "HOME" {
+                       // $HOME is a special case
+                       args = append(args, "--home="+v)
+               } else {
+                       env = append(env, "SINGULARITYENV_"+k+"="+v)
+               }
        }
 
+       args = append(args, e.imageFilename)
+       args = append(args, e.spec.Command...)
+
        path, err := exec.LookPath(args[0])
        if err != nil {
                return err