Skip to content

Commit

Permalink
optionally wrap singularity entry point with shell (#273)
Browse files Browse the repository at this point in the history
  • Loading branch information
wpbonelli committed Feb 1, 2022
1 parent c99be69 commit d64a8f3
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 21 deletions.
39 changes: 20 additions & 19 deletions plantit/front_end/src/components/workflows/workflow.vue
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,9 @@
undefined
"
>
<b-col>
<b-col
md="auto"
>
<b-link
v-if="
typeof getWorkflow
Expand Down Expand Up @@ -446,30 +448,31 @@
.doi
}}</b-link
>
<b-list-group
<div
v-else
>
<b-list-group-item
:variant="
profile.darkMode
? 'dark'
: 'light'
"
<b-row
v-for="doi in getWorkflow
.config
.doi"
v-bind:key="
doi
"
><b-link
class="text-dark"
:href="`https://doi.org/${doi}`"
>{{
doi
}}</b-link
></b-list-group-item
><b-col
><b-link
:class="
profile.darkMode
? 'text-light'
: 'text-dark'
"
:href="`https://doi.org/${doi}`"
>{{
doi
}}</b-link
></b-col
></b-row
>
</b-list-group>
</div>
</b-col>
</b-row>
</b-col>
Expand Down Expand Up @@ -4665,9 +4668,7 @@ export default {
// return true;
},
agentValid() {
return (
this.selectedAgent !== null && this.selectedAgent !== ''
);
return this.selectedAgent !== null && this.selectedAgent !== '';
},
canSubmit() {
return (
Expand Down
11 changes: 11 additions & 0 deletions plantit/plantit/task_lifecycle.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,9 @@ def parse_task_cli_options(task: Task) -> (List[str], TaskOptions):
config['output']['exclude']['names'].append("template_task_slurm.sh")
output = config['output']

# from here on, make sure we have no configuration errors
errors = []

image = None
if not isinstance(config['image'], str):
errors.append('Attribute \'image\' must not be a str')
Expand Down Expand Up @@ -626,6 +628,14 @@ def parse_task_cli_options(task: Task) -> (List[str], TaskOptions):
if 'extra' in jobqueue and not all(extra is str for extra in jobqueue['extra']):
errors.append('Section \'jobqueue\'.\'extra\' must be a list of str')

shell = None
if 'shell' in config:
shell = config['shell']
if not isinstance(shell, str):
errors.append('Attribute \'shell\' must be a str')
elif shell != 'sh' and shell != 'bash' and shell != 'zsh': # TODO: do we need to support any others?
errors.append('Attribute \'shell\' must be \'sh\', \'bash\', or \'zsh\'')

options = TaskOptions(
workdir=work_dir,
image=image,
Expand All @@ -641,5 +651,6 @@ def parse_task_cli_options(task: Task) -> (List[str], TaskOptions):
if jobqueue is not None: options['jobqueue'] = jobqueue
if no_cache is not None: options['no_cache'] = no_cache
if gpu is not None: options['gpus'] = task.agent.gpus
if shell is not None: options['shell'] = shell

return errors, options
10 changes: 9 additions & 1 deletion plantit/plantit/task_scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ def compose_task_singularity_command(
parameters: List[Parameter] = None,
no_cache: bool = False,
gpus: int = 0,
shell_wrapper: str = None,
docker_username: str = None,
docker_password: str = None,
index: int = None) -> str:
Expand Down Expand Up @@ -240,7 +241,10 @@ def compose_task_singularity_command(
if gpus: cmd += ' --nv'

# append the command
cmd += f" {image} sh -c '{command}'" # is `sh -c '[the command to run]'` always available/safe?
if shell_wrapper is not None:
cmd += f" {image} {shell_wrapper} -c '{command}'" # is `sh -c '[the command to run]'` always available/safe?
else:
cmd += f" {image} {command}" # is `sh -c '[the command to run]'` always available/safe?

# don't want to reveal secrets, so log the command before prepending secret env vars
logger.debug(f"Using command: '{cmd}'")
Expand Down Expand Up @@ -321,6 +325,7 @@ def compose_task_launcher_script(task: Task, options: TaskOptions) -> List[str]:
'bind_mounts' in options and isinstance(options['bind_mounts'], list)) else [],
no_cache=options['no_cache'] if 'no_cache' in options else False,
gpus=gpus,
shell_wrapper=options['shell'],
docker_username=docker_username,
docker_password=docker_password,
index=i)
Expand All @@ -339,6 +344,7 @@ def compose_task_launcher_script(task: Task, options: TaskOptions) -> List[str]:
list) else [],
no_cache=options['no_cache'] if 'no_cache' in options else False,
gpus=gpus,
shell_wrapper=options['shell'],
docker_username=docker_username,
docker_password=docker_password)
lines.append(command)
Expand All @@ -357,6 +363,7 @@ def compose_task_launcher_script(task: Task, options: TaskOptions) -> List[str]:
list) else [],
no_cache=options['no_cache'] if 'no_cache' in options else False,
gpus=gpus,
shell_wrapper=options['shell'],
docker_username=docker_username,
docker_password=docker_password)
lines.append(command)
Expand All @@ -372,6 +379,7 @@ def compose_task_launcher_script(task: Task, options: TaskOptions) -> List[str]:
bind_mounts=options['bind_mounts'] if 'bind_mounts' in options else None,
no_cache=options['no_cache'] if 'no_cache' in options else False,
gpus=gpus,
shell_wrapper=options['shell'],
docker_username=docker_username,
docker_password=docker_password)
lines.append(command)
Expand Down
3 changes: 2 additions & 1 deletion plantit/plantit/tasks/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,5 @@ class TaskOptions(TypedDict, total=False):
log_file: str
jobqueue: dict
no_cache: bool
gpu: bool
gpus: bool
shell: str

0 comments on commit d64a8f3

Please sign in to comment.