Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add readOnlyInputs option for CharliecloudBuilder #3590

Merged
merged 8 commits into from
Feb 2, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import groovy.util.logging.Slf4j
*
* @author Paolo Di Tommaso <[email protected]>
* @author Patrick Hüther <[email protected]>
* @author Laurent Modolo <[email protected]>
*/
@CompileStatic
@Slf4j
Expand All @@ -46,6 +47,9 @@ class CharliecloudBuilder extends ContainerBuilder<CharliecloudBuilder> {
if( params.containsKey('runOptions') )
addRunOptions(params.runOptions.toString())

if( params.containsKey('readOnlyInputs') )
this.readOnlyInputs = params.readOnlyInputs?.toString() == 'true'

return this
}

Expand All @@ -58,7 +62,9 @@ class CharliecloudBuilder extends ContainerBuilder<CharliecloudBuilder> {
CharliecloudBuilder build(StringBuilder result) {
assert image

result << 'ch-run --unset-env="*" -c "$PWD" -w --no-home --set-env '
result << 'ch-run --unset-env="*" -c "$PWD" --no-home --set-env '
if (!readOnlyInputs)
result << '-w '

appendEnv(result)

Expand All @@ -78,9 +84,23 @@ class CharliecloudBuilder extends ContainerBuilder<CharliecloudBuilder> {
return this
}

protected String getRoot(String path) {
def rootPath = path.split("/")

if (rootPath.size() >= 1)
rootPath = "/${rootPath[1]}"
pditommaso marked this conversation as resolved.
Show resolved Hide resolved
else
throw new IllegalArgumentException("Not a valid working directory value: ${path}")

return rootPath
}

@Override
protected String composeVolumePath(String path, boolean readOnly = false) {
return "-b ${escape(path)}"
protected String composeVolumePath(String path, boolean readOnlyInputs = false) {
def mountCmd = "-b ${escape(path)}"
if (readOnlyInputs)
mountCmd = "-b ${getRoot(escape(path))}"
return mountCmd
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,8 @@ class CharliecloudCache {
return localPath
}

final file = new File("${localPath.parent.parent.parent}/.${localPath.name}.lock")
// final file = new File("${localPath.parent.parent.parent}/.${localPath.name}.lock")
final file = new File("${localPath.parent.parent.parent}/.ch-pulling.lock")
final wait = "Another Nextflow instance is pulling the image $imageUrl with Charliecloud -- please wait until the download completes"
final err = "Unable to acquire exclusive lock after $pullTimeout on file: $file"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import spock.lang.Unroll
*
* @author Paolo Di Tommaso <[email protected]>
* @author Patrick Hüther <[email protected]>
* @author Laurent Modolo <[email protected]>
*/
class CharliecloudBuilderTest extends Specification {

Expand All @@ -38,52 +39,62 @@ class CharliecloudBuilderTest extends Specification {
expect:
new CharliecloudBuilder('busybox')
.build()
.runCommand == 'ch-run --unset-env="*" -c "$PWD" -w --no-home --set-env -b "$PWD" busybox --'
.runCommand == 'ch-run --unset-env="*" -c "$PWD" --no-home --set-env -w -b "$PWD" busybox --'

new CharliecloudBuilder('busybox')
.params(runOptions: '-j')
.build()
.runCommand == 'ch-run --unset-env="*" -c "$PWD" -w --no-home --set-env -b "$PWD" -j busybox --'
.runCommand == 'ch-run --unset-env="*" -c "$PWD" --no-home --set-env -w -b "$PWD" -j busybox --'

new CharliecloudBuilder('busybox')
.params(temp: '/foo')
.build()
.runCommand == 'ch-run --unset-env="*" -c "$PWD" -w --no-home --set-env -b /foo:/tmp -b "$PWD" busybox --'
.runCommand == 'ch-run --unset-env="*" -c "$PWD" --no-home --set-env -w -b /foo:/tmp -b "$PWD" busybox --'

new CharliecloudBuilder('busybox')
.addEnv('X=1')
.addEnv(ALPHA:'aaa', BETA: 'bbb')
.build()
.runCommand == 'ch-run --unset-env="*" -c "$PWD" -w --no-home --set-env --set-env=X=1 --set-env=ALPHA=aaa --set-env=BETA=bbb -b "$PWD" busybox --'
.runCommand == 'ch-run --unset-env="*" -c "$PWD" --no-home --set-env -w --set-env=X=1 --set-env=ALPHA=aaa --set-env=BETA=bbb -b "$PWD" busybox --'

new CharliecloudBuilder('ubuntu')
.addMount(path1)
.build()
.runCommand == 'ch-run --unset-env="*" -c "$PWD" -w --no-home --set-env -b /foo/data/file1 -b "$PWD" ubuntu --'
.runCommand == 'ch-run --unset-env="*" -c "$PWD" --no-home --set-env -w -b /foo/data/file1 -b "$PWD" ubuntu --'

new CharliecloudBuilder('ubuntu')
.addMount(path1)
.addMount(path2)
.build()
.runCommand == 'ch-run --unset-env="*" -c "$PWD" -w --no-home --set-env -b /foo/data/file1 -b /bar/data/file2 -b "$PWD" ubuntu --'
.runCommand == 'ch-run --unset-env="*" -c "$PWD" --no-home --set-env -w -b /foo/data/file1 -b /bar/data/file2 -b "$PWD" ubuntu --'
}

def 'should get run command' () {

when:
def cmd = new CharliecloudBuilder('ubuntu').build().getRunCommand()
then:
cmd == 'ch-run --unset-env="*" -c "$PWD" -w --no-home --set-env -b "$PWD" ubuntu --'
cmd == 'ch-run --unset-env="*" -c "$PWD" --no-home --set-env -w -b "$PWD" ubuntu --'

when:
cmd = new CharliecloudBuilder('ubuntu').build().getRunCommand('bwa --this --that file.fastq')
then:
cmd == 'ch-run --unset-env="*" -c "$PWD" -w --no-home --set-env -b "$PWD" ubuntu -- bwa --this --that file.fastq'
cmd == 'ch-run --unset-env="*" -c "$PWD" --no-home --set-env -w -b "$PWD" ubuntu -- bwa --this --that file.fastq'

when:
cmd = new CharliecloudBuilder('ubuntu').params(entry:'/bin/sh').build().getRunCommand('bwa --this --that file.fastq')
then:
cmd == 'ch-run --unset-env="*" -c "$PWD" -w --no-home --set-env -b "$PWD" ubuntu -- /bin/sh -c "bwa --this --that file.fastq"'
cmd == 'ch-run --unset-env="*" -c "$PWD" --no-home --set-env -w -b "$PWD" ubuntu -- /bin/sh -c "bwa --this --that file.fastq"'

when:
cmd = new CharliecloudBuilder('ubuntu').params(entry:'/bin/sh').params(readOnlyInputs: 'true').build().getRunCommand('bwa --this --that file.fastq')
then:
cmd == 'ch-run --unset-env="*" -c "$PWD" --no-home --set-env -b "$PWD" ubuntu -- /bin/sh -c "bwa --this --that file.fastq"'

when:
cmd = new CharliecloudBuilder('ubuntu').params(entry:'/bin/sh').params(readOnlyInputs: 'false').build().getRunCommand('bwa --this --that file.fastq')
then:
cmd == 'ch-run --unset-env="*" -c "$PWD" --no-home --set-env -w -b "$PWD" ubuntu -- /bin/sh -c "bwa --this --that file.fastq"'
}

@Unroll
Expand Down