From 42ee4dbb5ebdc60eda83179c3d3b3951dcaf9b0f Mon Sep 17 00:00:00 2001 From: Yohann D'ANELLO Date: Fri, 19 Mar 2021 18:09:49 +0100 Subject: [PATCH] [constellation] Deploy frontend Signed-off-by: Yohann D'ANELLO --- group_vars/constellation.yml | 30 +++++++++++++++++++ plays/constellation.yml | 3 ++ roles/constellation-front/handlers/main.yml | 10 +++++++ roles/constellation-front/tasks/main.yml | 30 +++++++++++++++++++ .../uwsgi/apps-available/constellation.ini.j2 | 23 ++++++++++++++ roles/constellation/tasks/main.yml | 6 ++++ 6 files changed, 102 insertions(+) create mode 100644 roles/constellation-front/handlers/main.yml create mode 100644 roles/constellation-front/tasks/main.yml create mode 100644 roles/constellation-front/templates/uwsgi/apps-available/constellation.ini.j2 diff --git a/group_vars/constellation.yml b/group_vars/constellation.yml index a9c30bde..97741be9 100644 --- a/group_vars/constellation.yml +++ b/group_vars/constellation.yml @@ -29,3 +29,33 @@ glob_constellation: version: master settings_local_owner: www-data settings_local_group: nounou + +loc_nginx: + service_name: constellation + ssl: [] + servers: + - ssl: false + default: true + server_name: + - "constellation.crans.org" + - "intranet.crans.org" + locations: + - filter: "/static" + params: + - "alias /var/local/constellation/static/" + + - filter: "/javascript" + params: + - "alias /usr/share/javascript/" + + - filter: "/media" + params: + - "alias /var/local/constellation/media/" + + - filter: "/" + params: + - "uwsgi_pass constellation" + - "include /etc/nginx/uwsgi_params" + upstreams: + - name: 'constellation' + server: 'unix:///var/run/uwsgi/app/constellation/constellation.sock' diff --git a/plays/constellation.yml b/plays/constellation.yml index cb18e246..068395c6 100755 --- a/plays/constellation.yml +++ b/plays/constellation.yml @@ -3,5 +3,8 @@ - hosts: constellation vars: constellation: "{{ glob_constellation | combine(loc_constellation | default({})) }}" + nginx: "{{ glob_nginx | combine(loc_nginx | default({})) }}" roles: - constellation + - nginx + - constellation-front diff --git a/roles/constellation-front/handlers/main.yml b/roles/constellation-front/handlers/main.yml new file mode 100644 index 00000000..bc651bf9 --- /dev/null +++ b/roles/constellation-front/handlers/main.yml @@ -0,0 +1,10 @@ +--- +- name: Reload NGINX + systemd: + name: nginx + state: reloaded + +- name: Reload uWSGI + systemd: + name: uwsgi + state: reloaded diff --git a/roles/constellation-front/tasks/main.yml b/roles/constellation-front/tasks/main.yml new file mode 100644 index 00000000..def0444c --- /dev/null +++ b/roles/constellation-front/tasks/main.yml @@ -0,0 +1,30 @@ +--- +- name: Install uWSGI + apt: + install_recommends: false + update_cache: true + name: + - uwsgi + - uwsgi-plugin-python3 + register: apt_result + retries: 3 + until: apt_result is succeeded + +- name: Copy constellation uWSGI app + template: + src: "uwsgi/apps-available/constellation.ini.j2" + dest: "/etc/uwsgi/apps-available/constellation.ini" + owner: root + group: root + mode: 0644 + notify: Reload uWSGI + +- name: Activate constellation uWSGI app + file: + src: "../apps-available/constellation.ini" + dest: "/etc/uwsgi/apps-enabled/constellation.ini" + owner: root + group: root + state: link + ignore_errors: "{{ ansible_check_mode }}" + notify: Reload uWSGI diff --git a/roles/constellation-front/templates/uwsgi/apps-available/constellation.ini.j2 b/roles/constellation-front/templates/uwsgi/apps-available/constellation.ini.j2 new file mode 100644 index 00000000..89906f3a --- /dev/null +++ b/roles/constellation-front/templates/uwsgi/apps-available/constellation.ini.j2 @@ -0,0 +1,23 @@ +{{ ansible_header | comment }} + +[uwsgi] +uid = www-data +gid = www-data +# Django-related settings +# the base directory (full path) +chdir = /var/local/constellation +wsgi-file = /var/local/constellation/constellation/wsgi.py +plugin = python3 +# process-related settings +# master +master = true +# maximum number of worker processes +processes = 10 +# the socket (use the full path to be safe +socket = /var/run/uwsgi/app/constellation/constellation.sock +# ... with appropriate permissions - may be needed +chmod-socket = 664 +# clear environment on exit +vacuum = true +# Touch reload +touch-reload = /var/local/constellation/constellation/settings.py diff --git a/roles/constellation/tasks/main.yml b/roles/constellation/tasks/main.yml index 1d7f58a8..871944d1 100644 --- a/roles/constellation/tasks/main.yml +++ b/roles/constellation/tasks/main.yml @@ -4,6 +4,7 @@ update_cache: true install_recommends: false name: + - gettext - python3-django - python3-django-crispy-forms - python3-django-extensions @@ -68,3 +69,8 @@ mode: 0660 owner: "{{ constellation.settings_local_owner }}" group: "{{ constellation.settings_local_group }}" + +- name: Compile messages + django_manage: + command: compilemessages + project_path: "/var/local/constellation"