Skip to content

Commit 70d7361

Browse files
committed
Separate docker and process environments
1 parent 97a71bb commit 70d7361

File tree

5 files changed

+19
-13
lines changed

5 files changed

+19
-13
lines changed

SequenceAnalysis/api-src/org/labkey/api/sequenceanalysis/run/AbstractCommandWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ abstract public class AbstractCommandWrapper implements CommandWrapper
4848
private boolean _warnNonZeroExits = true;
4949
private boolean _throwNonZeroExits = true;
5050
private Integer _lastReturnCode = null;
51-
protected final Map<String, String> _environment = new HashMap<>();
51+
private final Map<String, String> _environment = new HashMap<>();
5252
private final List<String> _commandsExecuted = new ArrayList<>();
5353

5454
public AbstractCommandWrapper(@Nullable Logger logger)

SequenceAnalysis/api-src/org/labkey/api/sequenceanalysis/run/DockerWrapper.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
import java.util.Arrays;
1616
import java.util.Collection;
1717
import java.util.Collections;
18+
import java.util.HashMap;
1819
import java.util.HashSet;
1920
import java.util.List;
21+
import java.util.Map;
2022
import java.util.Set;
2123
import 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());

singlecell/api-src/org/labkey/api/singlecell/pipeline/AbstractSingleCellPipelineStep.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ public static void executeR(SequenceOutputHandler.JobContext ctx, String dockerC
326326
seuratThreads = maxThreads;
327327
}
328328

329-
wrapper.addToEnvironment("SEURAT_MAX_THREADS", seuratThreads.toString());
329+
wrapper.addToDockerEnvironment("SEURAT_MAX_THREADS", seuratThreads.toString());
330330
}
331331

332332
File tmpDir = new File(SequencePipelineService.get().getJavaTempDir());

singlecell/src/org/labkey/singlecell/CellHashingServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1253,7 +1253,7 @@ public File generateCellHashingCalls(File citeSeqCountOutDir, File outputDir, St
12531253
}
12541254

12551255
DockerWrapper wrapper = new DockerWrapper("ghcr.io/bimberlab/cellhashr:latest", ctx.getLogger(), ctx);
1256-
wrapper.addToEnvironment("CELLHASHR_DEBUG", "1");
1256+
wrapper.addToDockerEnvironment("CELLHASHR_DEBUG", "1");
12571257

12581258
PipelineStepOutput output = new DefaultPipelineStepOutput();
12591259
wrapper.executeWithDocker(Arrays.asList("Rscript", "--vanilla", localRScript.getPath()), ctx.getWorkingDirectory(), output, inputFiles);

singlecell/src/org/labkey/singlecell/run/NimbleHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ private static boolean runUsingDocker(List<String> nimbleArgs, PipelineStepOutpu
573573

574574
wrapper.setTmpDir(null);
575575

576-
wrapper.addToEnvironment("RUST_BACKTRACE", "1");
576+
wrapper.addToDockerEnvironment("RUST_BACKTRACE", "1");
577577

578578
File doneFile = null;
579579
if (resumeString != null)

0 commit comments

Comments
 (0)