From a6b5a25f25492b13ff9c2ec3347bcad475201104 Mon Sep 17 00:00:00 2001 From: Dawa Ometto Date: Tue, 22 Oct 2024 14:42:09 +0200 Subject: [PATCH] Dispatch only interactive tools to docker by default --- README.md | 4 ++-- galaxysrv.yml | 2 +- tasks/interactive_tools.yml | 5 +++++ tasks/set_config.yml | 7 +++++++ templates/default_dispatch.py.j2 | 8 ++++++++ templates/galaxy/config/job_conf.yml.j2 | 14 +++++++------- vars/internal_vars.yml | 2 ++ vars/src_galaxy_vars.yml | 3 ++- 8 files changed, 34 insertions(+), 11 deletions(-) create mode 100644 templates/default_dispatch.py.j2 diff --git a/README.md b/README.md index f8cbd3f..6939b62 100644 --- a/README.md +++ b/README.md @@ -34,8 +34,8 @@ The component takes the following parameters: * `src_galaxy_version`: String. Set to e.g. `23.2` (default) to control the version of Galaxy that will be installed. * `src_galaxy_api_exposed`: Boolean. if `true` (default), the `/api` route does not require authentication via Single Sign-On. * `src_ibridges`: Boolean (default: `true`). Whether to enable support for the [iBridges](https://github.com/UtrechtUniversity/galaxy-tools-ibridges) tool for connecting to Yoda and iRODS instances. Implies `src_galaxy_bootstrap`, and adds iBridges to the list of tools to be installed automatically. -* `src_galaxy_jobs_docker`: Boolean. Enables Galaxy support for running jobs in Docker containers. Any jobs that *can* be run in a docker container will be---jobs that cannot will be run in the default manner (in a `conda` env). Runnings jobs in a container may be slower than running them locally, so consider turning this feature off if not needed. -* `src_galaxy_interactive_tools`: if `true` (default), support for [interactive tools](https://docs.galaxyproject.org/en/master/admin/special_topics/interactivetools.html) is enabled. **Note**: this implies *src_galaxy_jobs_docker*, and the accompanying performance hits. +* `src_galaxy_jobs_default`: String. What runner to use for jobs by default. Valid values: `singularity`, `docker`, `local`. +* `src_galaxy_interactive_tools`: if `true` (default), support for [interactive tools](https://docs.galaxyproject.org/en/master/admin/special_topics/interactivetools.html) is enabled. * `src_galaxy_co_admin_group`: String group corresponding to an SRAM group. Members of this SRAM group will be made Galaxy admin users. * `src_galaxy_bootstrap`: if `true` (default), will attempt to install workflows, dataproviders and tools as configured by the following options: * `src_galaxy_tool_files`: String of comma-separated paths to YAML files (in this repo) containing tool specifications. diff --git a/galaxysrv.yml b/galaxysrv.yml index 7b83d19..0694050 100644 --- a/galaxysrv.yml +++ b/galaxysrv.yml @@ -26,7 +26,7 @@ roles: - role: geerlingguy.docker - when: not _molecule_active and _galaxy_jobs_docker + when: not _molecule_active and _galaxy_enable_docker - role: uusrc.general.nginx_reverse_proxy vars: nginx_reverse_proxy_locations: "{{ galaxy_nginx_vhost_config }}" diff --git a/tasks/interactive_tools.yml b/tasks/interactive_tools.yml index f65bf48..8555398 100644 --- a/tasks/interactive_tools.yml +++ b/tasks/interactive_tools.yml @@ -14,3 +14,8 @@ path: "{{ galaxy_config_dir }}/tool_conf.xml" regexp: '\s*' replace: '\n \1' + +- name: Copy script to dynamically determine if a job should use Docker + ansible.builtin.template: + src: default_dispatch.py.j2 + dest: "{{ galaxy_server_dir }}/lib/galaxy/jobs/rules/{{ _galaxy_default_dispatcher }}.py" diff --git a/tasks/set_config.yml b/tasks/set_config.yml index 4b0fe57..15e8462 100644 --- a/tasks/set_config.yml +++ b/tasks/set_config.yml @@ -5,6 +5,13 @@ - name: Load component variables ansible.builtin.include_vars: vars/src_galaxy_vars.yml +- name: Sanity check + block: + - name: Assert default handler is valid + ansible.builtin.assert: + that: + - "['singularity', 'docker', 'local'] is contains(_galaxy_jobs_default)" + - name: Load interactive tools variables ansible.builtin.include_vars: vars/interactive_tools_vars.yml diff --git a/templates/default_dispatch.py.j2 b/templates/default_dispatch.py.j2 new file mode 100644 index 0000000..992466e --- /dev/null +++ b/templates/default_dispatch.py.j2 @@ -0,0 +1,8 @@ +from galaxy.jobs import JobDestination +import os + +def {{ _galaxy_default_dispatcher }}(tool): + if tool.tool_type == 'interactive': + return 'docker' + else: + return '{{ _galaxy_jobs_default }}' diff --git a/templates/galaxy/config/job_conf.yml.j2 b/templates/galaxy/config/job_conf.yml.j2 index c510035..2283b97 100644 --- a/templates/galaxy/config/job_conf.yml.j2 +++ b/templates/galaxy/config/job_conf.yml.j2 @@ -4,23 +4,23 @@ runners: workers: 4 execution: - default: docker_dispatch + default: {{ _galaxy_default_dispatcher if _galaxy_use_interactive_tools else _galaxy_jobs_default }} environments: local: runner: local - docker_local: + docker: runner: local docker_enabled: true docker_set_user: docker_sudo: false - docker_dispatch: +{% if _galaxy_use_interactive_tools %} + {{ _galaxy_default_dispatcher }}: runner: dynamic - type: docker_dispatch - docker_destination_id: docker_local - default_destination_id: local - + type: python + function: {{ _galaxy_default_dispatcher }} +{% endif %} tools: - class: local # these special tools that aren't parameterized for remote execution - expression tools, upload, etc environment: local diff --git a/vars/internal_vars.yml b/vars/internal_vars.yml index ab9bd53..52c8704 100644 --- a/vars/internal_vars.yml +++ b/vars/internal_vars.yml @@ -20,6 +20,8 @@ _galaxy_local_address: localhost:8080 galaxy_src_documentation: https://github.com/UtrechtUniversity/vre-docs +_galaxy_default_dispatcher: default_dispatcher # function and file name for the dynamic job handler used by interactive tools + # Variables for the docker role docker_install_compose: false diff --git a/vars/src_galaxy_vars.yml b/vars/src_galaxy_vars.yml index ae05c1d..18b7ddb 100644 --- a/vars/src_galaxy_vars.yml +++ b/vars/src_galaxy_vars.yml @@ -12,7 +12,8 @@ _galaxy_custom_repo_branch: "{{ src_galaxy_custom_repo_branch | default('main', _galaxy_api_exposed: "{{ src_galaxy_api_exposed | default(true, true) }}" _galaxy_use_interactive_tools: "{{ src_galaxy_interactive_tools | default(true, true) | bool }}" _galaxy_server_fqdn: "{{ workspace_fqdn | default('localhost', true) }}" -_galaxy_jobs_docker: "{{ _galaxy_use_interactive_tools or (src_galaxy_jobs_docker | default(true, false) | bool ) }}" +_galaxy_jobs_default: "{{ src_galaxy_jobs_default | default('local', true) }}" +_galaxy_enable_docker: "{{ _galaxy_use_interactive_tools or (_galaxy_jobs_default == 'docker' ) }}" # Build the final lists of tool and workflow installation files _galaxy_tool_files: "{{ src_galaxy_tool_files | default('', true) | split(',') | select() + _galaxy_default_tool_files_list }}" # select() necessary because split on the default '' yields ['']