mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-24 02:04:04 +08:00
Merged downstream galaxy-lib mulled enhancement and fixes.
- Singularity support for building mulled containers https://github.com/galaxyproject/galaxy-lib/pull/64 - Hack to fix previous mulled v2 changes for single requirement tools https://github.com/galaxyproject/galaxy-lib/pull/65.
This commit is contained in:
@@ -45,6 +45,13 @@ if conda_image == '' then
|
||||
conda_image = 'continuumio/miniconda:latest'
|
||||
end
|
||||
|
||||
|
||||
local singularity_image = VAR.SINGULARITY_IMAGE
|
||||
if singularity_image == '' then
|
||||
singularity_image = 'quay.io/biocontainers/singularity:2.3--0'
|
||||
end
|
||||
|
||||
|
||||
local destination_base_image = VAR.DEST_BASE_IMAGE
|
||||
if destination_base_image == '' then
|
||||
destination_base_image = 'bgruening/busybox-bash:0.1'
|
||||
@@ -84,9 +91,25 @@ inv.task('build')
|
||||
.at('/usr/local')
|
||||
.inImage(destination_base_image)
|
||||
.as(repo)
|
||||
|
||||
if VAR.SINGULARITY ~= '' then
|
||||
inv.task('singularity')
|
||||
.using(singularity_image)
|
||||
.withHostConfig({binds = {"build:/data","singularity_import:/import"}, privileged = true})
|
||||
.withConfig({entrypoint = {'/bin/sh', '-c'}})
|
||||
-- this will create a container that is the size of our conda dependencies + 20MiB
|
||||
-- The 20 MiB can be improved at some point, but this seems to work for now.
|
||||
.run("du -sc /data/dist/ | tail -n 1 | cut -f 1 | awk '{print int($1/1024)+20}'")
|
||||
.run("singularity create --size `du -sc /data/dist/ | tail -n 1 | cut -f 1 | awk '{print int($1/1024)+20}'` /import/" .. VAR.SINGULARITY_IMAGE_NAME)
|
||||
.run('mkdir -p /usr/local/var/singularity/mnt/container && singularity bootstrap /import/' .. VAR.SINGULARITY_IMAGE_NAME .. ' /import/Singularity')
|
||||
.run('chown ' .. VAR.USER_ID .. ' /import/' .. VAR.SINGULARITY_IMAGE_NAME)
|
||||
end
|
||||
|
||||
inv.task('cleanup')
|
||||
.using(conda_image)
|
||||
.withHostConfig({binds = {"build:/data"}})
|
||||
.run('rm', '-rf', '/data/dist')
|
||||
.withHostConfig({binds = {"build:/data"}})
|
||||
.run('rm', '-rf', '/data/dist')
|
||||
|
||||
|
||||
if VAR.TEST_BINDS == '' then
|
||||
inv.task('test')
|
||||
@@ -106,9 +129,14 @@ inv.task('push')
|
||||
|
||||
inv.task('build-and-test')
|
||||
.runTask('build')
|
||||
.runTask('singularity')
|
||||
.runTask('cleanup')
|
||||
.runTask('test')
|
||||
|
||||
|
||||
inv.task('all')
|
||||
.runTask('build')
|
||||
.runTask('singularity')
|
||||
.runTask('cleanup')
|
||||
.runTask('test')
|
||||
.runTask('push')
|
||||
|
||||
@@ -47,6 +47,23 @@ IS_OS_X = _platform == "darwin"
|
||||
INVOLUCRO_VERSION = "1.1.2"
|
||||
DEST_BASE_IMAGE = os.environ.get('DEST_BASE_IMAGE', None)
|
||||
|
||||
SINGULARITY_TEMPLATE = """Bootstrap: docker
|
||||
From: bgruening/busybox-bash:0.1
|
||||
|
||||
%%setup
|
||||
|
||||
echo "Copying conda environment"
|
||||
mkdir -p /tmp/conda
|
||||
cp -r /data/dist/* /tmp/conda/
|
||||
|
||||
%%post
|
||||
mkdir -p /usr/local
|
||||
cp -R /tmp/conda/* /usr/local/
|
||||
|
||||
%%test
|
||||
%(container_test)s
|
||||
"""
|
||||
|
||||
|
||||
def involucro_link():
|
||||
if IS_OS_X:
|
||||
@@ -134,17 +151,21 @@ def mull_targets(
|
||||
test='true', test_files=None, image_build=None, name_override=None,
|
||||
repository_template=DEFAULT_REPOSITORY_TEMPLATE, dry_run=False,
|
||||
conda_version=None, verbose=False, binds=DEFAULT_BINDS, rebuild=True,
|
||||
oauth_token=None, hash_func="v2",
|
||||
oauth_token=None, hash_func="v2", singularity=False,
|
||||
):
|
||||
targets = list(targets)
|
||||
if involucro_context is None:
|
||||
involucro_context = InvolucroContext()
|
||||
|
||||
image_function = v1_image_name if hash_func == "v1" else v2_image_name
|
||||
if len(targets) > 2 and image_build is None:
|
||||
# Force an image build in this case - this seems hacky probably
|
||||
# shouldn't work this way but single case broken else wise.
|
||||
image_build = "0"
|
||||
|
||||
repo_template_kwds = {
|
||||
"namespace": namespace,
|
||||
"image": image_function(targets, image_build=image_build or '0', name_override=name_override)
|
||||
"image": image_function(targets, image_build=image_build, name_override=name_override)
|
||||
}
|
||||
repo = string.Template(repository_template).safe_substitute(repo_template_kwds)
|
||||
|
||||
@@ -187,6 +208,11 @@ def mull_targets(
|
||||
involucro_args.extend(["-set", "DEST_BASE_IMAGE='%s'" % DEST_BASE_IMAGE])
|
||||
if verbose:
|
||||
involucro_args.extend(["-set", "VERBOSE='1'"])
|
||||
if singularity:
|
||||
singularity_image_name = repo_template_kwds['image']
|
||||
involucro_args.extend(["-set", "SINGULARITY='1'"])
|
||||
involucro_args.extend(["-set", "SINGULARITY_IMAGE_NAME='%s'" % singularity_image_name])
|
||||
involucro_args.extend(["-set", "USER_ID='%s:%s'" % (os.getuid(), os.getgid() )])
|
||||
if conda_version is not None:
|
||||
verbose = "--verbose" if verbose else "--quiet"
|
||||
involucro_args.extend(["-set", "PREINSTALL='conda install %s --yes conda=%s'" % (verbose, conda_version)])
|
||||
@@ -206,7 +232,18 @@ def mull_targets(
|
||||
print(" ".join(involucro_context.build_command(involucro_args)))
|
||||
if not dry_run:
|
||||
ensure_installed(involucro_context, True)
|
||||
return involucro_context.exec_command(involucro_args)
|
||||
if singularity:
|
||||
if not os.path.exists('./singularity_import'):
|
||||
os.mkdir('./singularity_import')
|
||||
with open('./singularity_import/Singularity', 'w+') as sin_def:
|
||||
fill_template = SINGULARITY_TEMPLATE % {'container_test': test}
|
||||
sin_def.write(fill_template)
|
||||
ret = involucro_context.exec_command(involucro_args)
|
||||
if singularity:
|
||||
# we can not remove this folder as it contains the image wich is owned by root
|
||||
pass
|
||||
# shutil.rmtree('./singularity_import')
|
||||
return ret
|
||||
return 0
|
||||
|
||||
|
||||
@@ -275,6 +312,8 @@ def add_build_arguments(parser):
|
||||
help='Just print commands instead of executing them.')
|
||||
parser.add_argument('--verbose', dest='verbose', action="store_true",
|
||||
help='Cause process to be verbose.')
|
||||
parser.add_argument('--singularity', action="store_true",
|
||||
help='Additionally build a singularity image.')
|
||||
parser.add_argument('-n', '--namespace', dest='namespace', default="biocontainers",
|
||||
help='quay.io namespace.')
|
||||
parser.add_argument('-r', '--repository_template', dest='repository_template', default=DEFAULT_REPOSITORY_TEMPLATE,
|
||||
@@ -324,6 +363,8 @@ def args_to_mull_targets_kwds(args):
|
||||
kwds["namespace"] = args.namespace
|
||||
if hasattr(args, "dry_run"):
|
||||
kwds["dry_run"] = args.dry_run
|
||||
if hasattr(args, "singularity"):
|
||||
kwds["singularity"] = args.singularity
|
||||
if hasattr(args, "test"):
|
||||
kwds["test"] = args.test
|
||||
if hasattr(args, "test_files"):
|
||||
|
||||
Reference in New Issue
Block a user