Skip to content

Commit

Permalink
fix config and copy
Browse files Browse the repository at this point in the history
  • Loading branch information
mira-miracoli committed Nov 21, 2023
1 parent d5d94b1 commit d9e9b71
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 31 deletions.
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,11 @@ The handler should "listen" to the topic `"restart galaxy"`.
[gravity]: https://github.com/galaxyproject/gravity

From release 22.01 Galaxy can serve different static content per host (e.g. subdomain) and you can set [themes][themes] per host.
By setting `galaxy_manage_static: yes` you enable the creation of static directories and configuration per host and by setting `galaxy_manage_themes: yes` the role will append your themes_config.yml file specified under `galaxy_themes_conf_path` to your themes files after coping them over to your galaxy server and create the respective configuration.
In order to use this features, you need to create the following directory structure under files/ (cusomizable with the `galaxy_themes_ansible_ansible_file_path` variable):

By setting `galaxy_manage_subdomain_static: yes` you enable the creation of static directories and configuration per host and by setting `galaxy_manage_themes: yes` the role will append your themes_config.yml file specified under `galaxy_themes_conf_path` to your themes files after coping them over to your galaxy server and create the respective configuration.

In order to use this feature, you need to create the following directory structure under files/ (customizable with the `galaxy_themes_ansible_file_path` variable):

~~~bash
files/galaxy/static
├──<subdomain-name-1>
Expand All @@ -126,10 +129,11 @@ files/galaxy/static
│   │   │   └── more-static-content-2.svg
│   │   └── welcome.html
│   └── themes
│   └── <subdomain-name-1>.yml
│   └── <subdomain-name-2>.yml
... (and many more subdomains)
~~~
Were the <subdomain-name-1> should exactly match your subdomain's name. The subdirectories `static` and `themes` are mandatory, as well as the correctly named theme file (if you enabled `galaxy_manage_themes`), while all subdirectories in `static` are optional.

Where the <subdomain-name-1> should exactly match your subdomain's name. The subdirectories `static` and `themes` are mandatory, as well as the correctly named theme file (if you enabled `galaxy_manage_themes`), while all subdirectories in `static` are optional.
Which subdirectories and files are copied is managed by the `static_galaxy_themes_keys` variable.

Also make sure that you set `galaxy_themes_welcome_url_prefix`, so your welcome pages are templated correctly.
Expand Down
18 changes: 9 additions & 9 deletions defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,47 +299,47 @@ galaxy_app_config_default:
visualization_plugins_directory: "config/plugins/visualizations"

# Static and themes configuration, will only be added if galaxy_manage_themes
enable_static: "{{ galaxy_manage_subdomain_static }}"
static_enabled: "{{ galaxy_manage_subdomain_static }}"
static_dir_by_host: >
{ {% if galaxy_manage_subdomain_static %}
{% for subdomain in galaxy_themes_subdomains %}
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}/'
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}/',
{% endfor %}
{% endif %} }
static_images_dir_by_host: >
{ {% if galaxy_manage_subdomain_static %}
{% for subdomain in galaxy_themes_subdomains %}
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}/images'
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}/images',
{% endfor %}
{% endif %} }
static_welcome_html_by_host: >
{ {% if galaxy_manage_subdomain_static %}
{% for subdomain in galaxy_themes_subdomains %}
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}/welcome.html'
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}/welcome.html',
{% endfor %}
{% endif %} }
static_scripts_dir_by_host: >
{ {% if galaxy_manage_subdomain_static %}
{% for subdomain in galaxy_themes_subdomains %}
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}/scripts'
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}/scripts',
{% endfor %}
{% endif %} }
static_favicon_dir_by_host: >
{ {% if galaxy_manage_subdomain_static %}
{% for subdomain in galaxy_themes_subdomains %}
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}/favicon.ico'
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}',
{% endfor %}
{% endif %} }
static_robots_txt_by_host: >
{ {% if galaxy_manage_subdomain_static %}
{% for subdomain in galaxy_themes_subdomains %}
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}/robots.txt'
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}',
{% endfor %}
{% endif %} }
themes_dir_by_host: >
themes_config_file_by_host: >
{ {% if galaxy_manage_themes %}
{% for subdomain in galaxy_themes_subdomains %}
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': {{ subdomain.name }}.yml
'{{ subdomain.name }}.{{ galaxy_themes_instance_domain}}': '{{ subdomain.name }}.yml',
{% endfor %}
{% endif %} }
# Need to set galaxy_config_default[galaxy_app_config_section] dynamically but Ansible/Jinja2 does not make this easy
Expand Down
21 changes: 20 additions & 1 deletion tasks/copy_static_files.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
- name: Copy static files
- name: Copy subdomain static files
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}/{{ object.value }}"
Expand All @@ -16,3 +16,22 @@
owner: "{{ __galaxy_privsep_user_name }}"
group: "{{ __galaxy_privsep_user_group }}"
with_fileglob: "{{ galaxy_themes_ansible_file_path }}/{{ subdomain.name }}/static/dist/*"

- name: Copy files from dist
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}/dist/"
mode: '0644'
owner: "{{ __galaxy_privsep_user_name }}"
group: "{{ __galaxy_privsep_user_group }}"
with_fileglob: "{{ galaxy_themes_ansible_file_path }}/{{ subdomain.name }}/static/dist/*"

- name: Copy custom welcome.html
ansible.builtin.copy:
src: "{{ item }}"
dest: "{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}/welcome.html/index.html"
mode: '0644'
owner: "{{ __galaxy_privsep_user_name }}"
group: "{{ __galaxy_privsep_user_group }}"
with_fileglob: "{{ galaxy_themes_ansible_file_path }}/{{ subdomain.name }}/static/welcome.html"
when: custom_welcome.stat.exists
12 changes: 12 additions & 0 deletions tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@
tags:
- galaxy_manage_cleanup

- name: Zip static directory
community.general.archive:
path: "{{ galaxy_themes_static_path }}/static/"
dest: "{{ galaxy_themes_static_path }}/static.gz"
when: galaxy_manage_subdomain_static

- name: Include create subdomain static dirs and copy static files
ansible.builtin.include_tasks: setup_static_dirs.yml
# fail only if enabled but dictionary is empty
Expand All @@ -172,6 +178,12 @@
tags:
- galaxy_manage_subdomain_static

- name: Remove static archive
ansible.builtin.file:
path: "{{ galaxy_themes_static_path }}/static.gz"
state: absent
when: galaxy_manage_subdomain_static

- name: Include copy themes files
ansible.builtin.include_tasks: themes.yml
# fail only if enabled but dictionary is empty
Expand Down
29 changes: 12 additions & 17 deletions tasks/setup_static_dirs.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
---
- name: Create static dirs
- name: Create subdomain static dirs
ansible.builtin.file:
state: directory
mode: '0755'
owner: "{{ __galaxy_privsep_user_name }}"
group: "{{ __galaxy_privsep_user_group }}"
path: "{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}"

- name: Move all contents from static to parent directory
ansible.builtin.copy:
src: "{{ galaxy_themes_static_dir }}"
dest: "{{ galaxy_themes_static_path }}/static-{{ \
subdomain.name }}"
owner: "{{ __galaxy_privsep_user_name }}"
group: "{{ __galaxy_privsep_user_group }}"
directory_mode: true
changed_when: false
- name: Add generic static files to subdomain static dir
ansible.builtin.unarchive:
src: "{{ galaxy_themes_static_path }}/static.gz"
dest: "{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}"
remote_src: yes

- name: Remove static dirs
ansible.builtin.file:
state: absent
mode: '0755'
owner: "{{ __galaxy_privsep_user_name }}"
group: "{{ __galaxy_privsep_user_group }}"
path: "{{ galaxy_themes_static_path }}/static-{{ subdomain.name }}/static"
- name: Check if welcome.html is present in files
ansible.builtin.stat:
path: "{{ galaxy_themes_ansible_file_path }}/{{ subdomain.name }}/static/welcome.html"
register: custom_welcome

- name: Create welcome.html directory
ansible.builtin.file:
Expand All @@ -39,6 +32,7 @@
return_content: true
register: iframe
failed_when: false
when: not custom_welcome.stat.exists

- name: Template welcome.html for subdomains
ansible.builtin.template:
Expand All @@ -47,6 +41,7 @@
owner: "{{ __galaxy_privsep_user_name }}"
group: "{{ __galaxy_privsep_user_group }}"
mode: '0644'
when: not custom_welcome.stat.exists

- name: Copy static files
ansible.builtin.include_tasks: copy_static_files.yml
Expand Down

0 comments on commit d9e9b71

Please sign in to comment.