From 1a61a90ff6bd716b40c8f4b8618a2f99965d7d46 Mon Sep 17 00:00:00 2001 From: Okhin Date: Wed, 6 Mar 2019 18:25:28 +0100 Subject: [PATCH] Installation et configuration de la rp --- tasks/main.yml | 115 ++++++++++++++++++++++++++++++++++++++++ templates/env.py.j2 | 5 ++ templates/vassals-rp.j2 | 9 ++++ 3 files changed, 129 insertions(+) create mode 100644 tasks/main.yml create mode 100644 templates/env.py.j2 create mode 100644 templates/vassals-rp.j2 diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000..fac03d7 --- /dev/null +++ b/tasks/main.yml @@ -0,0 +1,115 @@ +--- +- name: create a rp user + user: + append: yes + groups: [gitlab-runner, www-data] + home: "{{ rp_path }}" + name: "{{ rp_unix_user }}" + state: present + system: yes + password: '*' + +- name: install required nodejs packages + npm: + global: yes + production: "{% if rp_debug %}false{% else %}true{% endif %}" + name: "{{ item }}" + state: latest + loop: "{{ npm_packages }}" + +- name: install uwsgi (emperor) packages + package: + name: "{{ item }}" + state: latest + loop: + - uwsgi-emperor + - uwsgi-plugin-python3 + - libapache2-mod-uwsgi + +- name: enable uwsgi (emperor) on start + service: + name: uwsgi-emperor + enabled: yes + state: started + +- name: create /run/ directory + file: + state: directory + path: /run/uwsgi/app/rp/ + owner: "{{ rp_unix_user }}" + group: www-data + mode: 0775 +- block: + - name: create the directory for code and environment + file: + path: "{{ rp_path }}" + state: directory + group: gitlab-runner + + - name: unzip the rp code + unarchive: + src: "{{ rp_download_url }}" + dest: "{{ rp_path }}" + keep_newer: yes + remote_src: yes + mode: g+rw + owner: "{{ rp_unix_user }}" + group: gitlab-runner + + - name: install python requirement + pip: + requirements: "{{ rp_source_path }}/requirements.txt" + virtualenv: "{{ rp_path }}/env" + virtualenv_python: python3 + + - name: install python dev requirements + pip: + requirements: "{{ rp_source_path }}/requirements-dev.txt" + virtualenv: "{{ rp_path }}/env" + virtualenv_python: python3 + when: rp_debug + + - name: yarn install the application + yarn: + path: "{{ rp_source_path }}/" + state: latest + register: yarn_out + changed_when: '"Already up-to-date." not in yarn_out.out' + + - name: webpack the css + command: webpack + args: + chdir: "{{ rp_source_path }}/" + changed_when: false + + - name: create the local env settings for django + template: + src: templates/env.py.j2 + dest: "{{ rp_source_path }}/project/settings/env.py" + + - name: migrate the database + django_manage: + command: migrate + virtualenv: "{{ rp_path }}/env/" + pythonpath: "{{ rp_source_path }}/project" + settings: project.settings + app_path: "{{ rp_source_path }}" + + - name: collect static file for django + django_manage: + command: collectstatic + link: true + virtualenv: "{{ rp_path }}/env/" + pythonpath: "{{ rp_source_path }}/project" + settings: project.settings + app_path: "{{ rp_source_path }}" + + become: yes + become_user: "{{ rp_unix_user }}" + +- name: adds a vassal for rp + template: + src: templates/vassals-rp.j2 + dest: /etc/uwsgi-emperor/vassals/rp.ini + + diff --git a/templates/env.py.j2 b/templates/env.py.j2 new file mode 100644 index 0000000..bc68600 --- /dev/null +++ b/templates/env.py.j2 @@ -0,0 +1,5 @@ +{% if rp_debug %} +DEBUG = True +{% endif %} +SITE_ID = {{ rp_site_id }} +SECRET_KEY = '{{ rp_secret_key | replace('\n', '') }}' diff --git a/templates/vassals-rp.j2 b/templates/vassals-rp.j2 new file mode 100644 index 0000000..63cd584 --- /dev/null +++ b/templates/vassals-rp.j2 @@ -0,0 +1,9 @@ +[uwsgi] +plugins = python3 + +module = project.wsgi:application +env = DJANGO_SETTINGS_MODULE=project.settings +chdir = {{ rp_source_path }} +home = {{ rp_path }}/env +socket = /run/uwsgi/app/rp/socket +pidfile = /run/uwsgi/app/rp/pid -- GitLab