Skip to content

Commit

Permalink
Fix Change work dir for Singularity [ci fast]
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Nov 6, 2023
1 parent 77bd6a4 commit dbbc8e6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,12 @@ class BashWrapperBuilder {
*/
if( containerBuilder ) {
String cmd = env ? 'eval $(nxf_container_env); ' + launcher : launcher
if( env && !containerConfig.entrypointOverride() ) {
if( containerBuilder instanceof SingularityBuilder )
// wrap the command with an extra bash invocation either :
// - to propagate the container environment or
// - to change in the task work directory as required by singularity
final needChangeTaskWorkDir = containerBuilder instanceof SingularityBuilder
if( (env || needChangeTaskWorkDir) && !containerConfig.entrypointOverride() ) {
if( needChangeTaskWorkDir )
cmd = 'cd $PWD; ' + cmd
cmd = "/bin/bash -c \"$cmd\""
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,20 @@ class BashWrapperBuilderTest extends Specification {
binding.kill_cmd == '[[ "$pid" ]] && nxf_kill $pid'
}

def 'should create wrapper with singularity and no env'() {
when:
def binding = newBashWrapperBuilder(
containerEnabled: true,
containerImage: 'docker://ubuntu:latest',
environment: [:],
containerConfig: [enabled: true, engine: 'singularity'] as ContainerConfig ).makeBinding()

then:
binding.launch_cmd == 'set +u; env - PATH="$PATH" ${TMP:+SINGULARITYENV_TMP="$TMP"} ${TMPDIR:+SINGULARITYENV_TMPDIR="$TMPDIR"} ${NXF_TASK_WORKDIR:+SINGULARITYENV_NXF_TASK_WORKDIR="$NXF_TASK_WORKDIR"} singularity exec --no-home --pid -B /work/dir docker://ubuntu:latest /bin/bash -c "cd $PWD; /bin/bash -ue /work/dir/.command.sh"'
binding.cleanup_cmd == ""
binding.kill_cmd == '[[ "$pid" ]] && nxf_kill $pid'
}

def 'should create wrapper with singularity legacy entry'() {
when:
def binding = newBashWrapperBuilder(
Expand Down

0 comments on commit dbbc8e6

Please sign in to comment.