diff --git a/tasks/main.yml b/tasks/main.yml new file mode 100644 index 0000000000000000000000000000000000000000..fac03d79b65aaa643d15c55447790e3ce96d5b73 --- /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 0000000000000000000000000000000000000000..bc686003c2f3e08f9b7ecf5d15921e24fa9f6bab --- /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 0000000000000000000000000000000000000000..63cd5843551682cfbf6b52ba81b73128c47fdca9 --- /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