1515import java .util .Arrays ;
1616import java .util .Collection ;
1717import java .util .Collections ;
18+ import java .util .HashMap ;
1819import java .util .HashSet ;
1920import java .util .List ;
21+ import java .util .Map ;
2022import java .util .Set ;
2123import java .util .stream .Collectors ;
2224
@@ -28,14 +30,13 @@ public class DockerWrapper extends AbstractCommandWrapper
2830 private String _entryPoint = null ;
2931 private boolean _runPrune = true ;
3032 private String _alternateUserHome = null ;
33+ private final Map <String , String > _dockerEnvironment = new HashMap <>();
3134
3235 public DockerWrapper (String containerName , Logger log , PipelineContext ctx )
3336 {
3437 super (log );
3538 _containerName = containerName ;
3639 _ctx = ctx ;
37-
38- _environment .clear ();
3940 }
4041
4142 public void setAlternateUserHome (String alternateUserHome )
@@ -75,7 +76,7 @@ public void executeWithDocker(List<String> containerArgs, File workDir, Pipeline
7576 {
7677 writer .println ("#!/bin/bash" );
7778 writer .println ("set -x" );
78- writer .println ("WD=`pwd` " );
79+ writer .println ("set -e " );
7980
8081 writer .println ("DOCKER='" + SequencePipelineService .get ().getDockerCommand () + "'" );
8182 writer .println ("$DOCKER pull " + _containerName );
@@ -100,12 +101,12 @@ public void executeWithDocker(List<String> containerArgs, File workDir, Pipeline
100101 _ctx .getLogger ().debug ("homeDir already present in docker volumes, will not re-add" );
101102 }
102103
103- _environment .put ("USER_HOME" , homeDir .getPath ());
104+ _dockerEnvironment .put ("USER_HOME" , homeDir .getPath ());
104105 }
105106
106107 if (_alternateUserHome != null )
107108 {
108- _environment .put ("HOME" , _alternateUserHome );
109+ _dockerEnvironment .put ("HOME" , _alternateUserHome );
109110 }
110111
111112 _ctx .getDockerVolumes ().forEach (v -> writer .println ("\t -v '" + v + "':'" + v + "' \\ " ));
@@ -126,7 +127,7 @@ public void executeWithDocker(List<String> containerArgs, File workDir, Pipeline
126127 _ctx .getLogger ().debug ("tmpDir already present in docker volumes, omitting" );
127128 }
128129
129- addToEnvironment ("TMPDIR" , _tmpDir .getPath ());
130+ addToDockerEnvironment ("TMPDIR" , _tmpDir .getPath ());
130131 }
131132
132133 if (_entryPoint != null )
@@ -135,7 +136,7 @@ public void executeWithDocker(List<String> containerArgs, File workDir, Pipeline
135136 }
136137
137138 writer .println ("\t -w " + workDir .getPath () + " \\ " );
138- addToEnvironment ("WORK_DIR" , workDir .getPath ());
139+ addToDockerEnvironment ("WORK_DIR" , workDir .getPath ());
139140
140141 Integer maxRam = SequencePipelineService .get ().getMaxRam ();
141142 if (maxRam != null )
@@ -144,9 +145,9 @@ public void executeWithDocker(List<String> containerArgs, File workDir, Pipeline
144145 writer .println ("\t --memory='" + maxRam + "g' \\ " );
145146 }
146147
147- for (String key : _environment .keySet ())
148+ for (String key : _dockerEnvironment .keySet ())
148149 {
149- writer .println ("\t -e " + key + "='" + _environment .get (key ) + "' \\ " );
150+ writer .println ("\t -e " + key + "='" + _dockerEnvironment .get (key ) + "' \\ " );
150151 }
151152 writer .println ("\t " + _containerName + " \\ " );
152153 writer .println ("\t /bin/bash " + dockerBashScript .getPath ());
@@ -171,6 +172,11 @@ public void executeWithDocker(List<String> containerArgs, File workDir, Pipeline
171172 execute (Arrays .asList ("/bin/bash" , localBashScript .getPath ()));
172173 }
173174
175+ public void addToDockerEnvironment (String key , String value )
176+ {
177+ _dockerEnvironment .put (key , value );
178+ }
179+
174180 private Collection <File > inspectInputFiles (Collection <File > inputFiles )
175181 {
176182 Set <File > toAdd = inputFiles .stream ().map (f -> f .isDirectory () ? f : f .getParentFile ()).filter (x -> _ctx .getDockerVolumes ().stream ().noneMatch (x .getPath ()::startsWith )).collect (Collectors .toSet ());
0 commit comments