-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #285 from BimberLab/24.3_fb_merge
Merge discvr-23.11 to discvr-24.3
- Loading branch information
Showing
3 changed files
with
139 additions
and
17 deletions.
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
SequenceAnalysis/api-src/org/labkey/api/sequenceanalysis/run/DockerWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package org.labkey.api.sequenceanalysis.run; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.apache.commons.lang3.StringUtils; | ||
import org.apache.logging.log4j.Logger; | ||
import org.labkey.api.pipeline.PipelineJobException; | ||
import org.labkey.api.sequenceanalysis.pipeline.PipelineOutputTracker; | ||
import org.labkey.api.sequenceanalysis.pipeline.SequencePipelineService; | ||
import org.labkey.api.writer.PrintWriters; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.io.PrintWriter; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class DockerWrapper extends AbstractCommandWrapper | ||
{ | ||
private final String _containerName; | ||
private File _tmpDir = null; | ||
|
||
public DockerWrapper(String containerName, Logger log) | ||
{ | ||
super(log); | ||
_containerName = containerName; | ||
} | ||
|
||
public void setTmpDir(File tmpDir) | ||
{ | ||
_tmpDir = tmpDir; | ||
} | ||
|
||
public void executeWithDocker(List<String> containerArgs, File workDir, PipelineOutputTracker tracker) throws PipelineJobException | ||
{ | ||
File localBashScript = new File(workDir, "docker.sh"); | ||
File dockerBashScript = new File(workDir, "dockerRun.sh"); | ||
tracker.addIntermediateFile(localBashScript); | ||
tracker.addIntermediateFile(dockerBashScript); | ||
|
||
setWorkingDir(workDir); | ||
try (PrintWriter writer = PrintWriters.getPrintWriter(localBashScript); PrintWriter dockerWriter = PrintWriters.getPrintWriter(dockerBashScript)) | ||
{ | ||
writer.println("#!/bin/bash"); | ||
writer.println("set -x"); | ||
writer.println("WD=`pwd`"); | ||
writer.println("HOME=`echo ~/`"); | ||
writer.println("DOCKER='" + SequencePipelineService.get().getDockerCommand() + "'"); | ||
writer.println("sudo $DOCKER pull " + _containerName); | ||
writer.println("sudo $DOCKER run --rm=true \\"); | ||
writer.println("\t-v \"${WD}:/work\" \\"); | ||
writer.println("\t-v \"${HOME}:/homeDir\" \\"); | ||
if (_tmpDir != null) | ||
{ | ||
writer.println("\t-v \"" + _tmpDir.getPath() + ":/tmp\" \\"); | ||
} | ||
writer.println("\t--entrypoint /bin/bash \\"); | ||
writer.println("\t-w /work \\"); | ||
Integer maxRam = SequencePipelineService.get().getMaxRam(); | ||
if (maxRam != null) | ||
{ | ||
writer.println("\t-e SEQUENCEANALYSIS_MAX_RAM=" + maxRam + " \\"); | ||
writer.println("\t--memory='" + maxRam + "g' \\"); | ||
} | ||
writer.println("\t" + _containerName + " \\"); | ||
writer.println("\t/work/" + dockerBashScript.getName()); | ||
writer.println("EXIT_CODE=$?"); | ||
writer.println("echo 'Docker run exit code: '$EXIT_CODE"); | ||
writer.println("exit $EXIT_CODE"); | ||
|
||
dockerWriter.println("#!/bin/bash"); | ||
dockerWriter.println("set -x"); | ||
dockerWriter.println(StringUtils.join(containerArgs, " ")); | ||
dockerWriter.println("EXIT_CODE=$?"); | ||
dockerWriter.println("echo 'Exit code: '$?"); | ||
dockerWriter.println("exit $EXIT_CODE"); | ||
} | ||
catch (IOException e) | ||
{ | ||
throw new PipelineJobException(e); | ||
} | ||
|
||
execute(Arrays.asList("/bin/bash", localBashScript.getPath())); | ||
} | ||
|
||
public File ensureLocalCopy(File input, File workingDirectory, PipelineOutputTracker output) throws PipelineJobException | ||
{ | ||
try | ||
{ | ||
if (workingDirectory.equals(input.getParentFile())) | ||
{ | ||
return input; | ||
} | ||
|
||
File local = new File(workingDirectory, input.getName()); | ||
if (!local.exists()) | ||
{ | ||
getLogger().debug("Copying file locally: " + input.getPath()); | ||
FileUtils.copyFile(input, local); | ||
} | ||
|
||
output.addIntermediateFile(local); | ||
|
||
return local; | ||
} | ||
catch (IOException e) | ||
{ | ||
throw new PipelineJobException(e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters