Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
See http://singularity.lbl.gov/ for more information on Singularity and see job_conf.xml.sample_advanced for information on setting up job runners to exploit singularity. The biggest current caveat is probably that currently these container images need to be setup manually by the admin and the paths hard-coded for each tool in job_conf.xml. There are people who do such manual setups for Docker (https://github.com/phnmnl/container-galaxy-k8s-runtime/blob/develop/config/job_conf.xml) - so it wouldn't be surprising if someone wanted to set this up for singularity as well. That said I'm sure this will be followed up by magic to fetch and convert Docker containers and leverage published singularity containers (such as mulled can now produce (galaxyproject/galaxy-lib#64).
- Loading branch information
Showing
3 changed files
with
192 additions
and
41 deletions.
There are no files selected for viewing
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
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,58 @@ | ||
from six.moves import shlex_quote | ||
|
||
|
||
DEFAULT_WORKING_DIRECTORY = None | ||
DEFAULT_SINGULARITY_COMMAND = "singularity" | ||
DEFAULT_SUDO = False | ||
DEFAULT_SUDO_COMMAND = "sudo" | ||
DEFAULT_RUN_EXTRA_ARGUMENTS = None | ||
|
||
|
||
def build_singularity_run_command( | ||
container_command, | ||
image, | ||
volumes=[], | ||
env=[], | ||
working_directory=DEFAULT_WORKING_DIRECTORY, | ||
singularity_cmd=DEFAULT_SINGULARITY_COMMAND, | ||
run_extra_arguments=DEFAULT_RUN_EXTRA_ARGUMENTS, | ||
sudo=DEFAULT_SUDO, | ||
sudo_cmd=DEFAULT_SUDO_COMMAND, | ||
): | ||
command_parts = [] | ||
# http://singularity.lbl.gov/docs-environment-metadata | ||
for (key, value) in env: | ||
command_parts.extend(["SINGULARITYENV_%s=%s" % (key, value)]) | ||
command_parts += _singularity_prefix( | ||
singularity_cmd=singularity_cmd, | ||
sudo=sudo, | ||
sudo_cmd=sudo_cmd, | ||
) | ||
command_parts.append("exec") | ||
for volume in volumes: | ||
command_parts.extend(["-B", shlex_quote(str(volume))]) | ||
if working_directory: | ||
command_parts.extend(["--pwd", shlex_quote(working_directory)]) | ||
if run_extra_arguments: | ||
command_parts.append(run_extra_arguments) | ||
full_image = image | ||
command_parts.append(shlex_quote(full_image)) | ||
command_parts.append(container_command) | ||
return " ".join(command_parts) | ||
|
||
|
||
def _singularity_prefix( | ||
singularity_cmd=DEFAULT_SINGULARITY_COMMAND, | ||
sudo=DEFAULT_SUDO, | ||
sudo_cmd=DEFAULT_SUDO_COMMAND, | ||
**kwds | ||
): | ||
"""Prefix to issue a singularity command.""" | ||
command_parts = [] | ||
if sudo: | ||
command_parts.append(sudo_cmd) | ||
command_parts.append(singularity_cmd) | ||
return command_parts | ||
|
||
|
||
__all__ = ("build_singularity_run_command",) |