nextflow.container.UdockerBuilder.groovy Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nextflow Show documentation
Show all versions of nextflow Show documentation
A DSL modelled around the UNIX pipe concept, that simplifies writing parallel and scalable pipelines in a portable manner
/*
* Copyright 2013-2024, Seqera Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package nextflow.container
import groovy.transform.PackageScope
/**
* Wrap a task execution in a Udocker container
*
* See https://github.com/indigo-dc/udocker
*
* @author Paolo Di Tommaso
*/
class UdockerBuilder extends ContainerBuilder {
private String temp
private boolean remove = true
UdockerBuilder( String image ) {
this.image = image
if( !this.image.contains(":") )
this.image += ':latest'
}
@Override
UdockerBuilder params(Map params) {
if( !params ) return this
if( params.containsKey('temp') )
this.temp = params.temp
if( params.containsKey('runOptions') )
addRunOptions(params.runOptions.toString())
if ( params.containsKey('remove') )
this.remove = params.remove?.toString() == 'true'
if( params.containsKey('entry') )
this.entryPoint = params.entry
return this
}
@Override
UdockerBuilder build(StringBuilder result) {
assert image, 'Missing container image'
result << 'udocker.py '
result << 'run '
if( remove ) {
result << '--rm '
}
if( cpuset ) {
result << "--cpuset-cpus=$cpuset "
}
// add the environment
appendEnv(result)
if( temp )
result << "-v $temp:/tmp "
// mount the input folders
result << makeVolumes(mounts)
result << '-w "$NXF_TASK_WORKDIR" --bindhome '
if( runOptions )
result << runOptions.join(' ') << ' '
// the ID of the container to run
result << "\$(udocker.py create \"$image\")"
this.runCommand = result.toString()
return this
}
@Override
String getRunCommand() {
def run = super.getRunCommand()
def result = "((udocker.py images | grep -E -o \"^$image\\s\") || udocker.py pull \"$image\")>/dev/null\n"
result += "[[ \$? != 0 ]] && echo \"Udocker failed while pulling container \\`$image\\`\" >&2 && exit 1\n"
result += run
return result
}
@PackageScope String getRunCommandRaw() {
super.getRunCommand()
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy