devfund-website/playbooks/tasks/deploy.yaml
Anna Sirota ce08b404dd Playbooks: switch to Python 3.10
Upgrading to Python 3.10 lead to the following changes:

    * Python's builtin `venv` is used instead of `virtualenv`:
        `python3-virtualenv` is packaged incorrectly making it impossible to
        use with Python binaries from ppa:deadsnakes,
        see https://github.com/pre-commit/pre-commit/issues/2211#issuecomment-1013954780

    * uWSGI is installed in the venv, the OS-wide uWSGI is no longer used
2024-01-09 10:26:29 +01:00

96 lines
2.8 KiB
YAML

---
- name: Pulling latest branch "{{ branch }}"
ansible.builtin.git:
repo: "{{ source_url }}"
dest: "{{ dir.source }}"
accept_hostkey: true
version: "{{ branch }}"
tags:
- git
- name: Copying error pages
ansible.builtin.template:
src: templates/nginx/errors/503-service-unavailable.html
dest: "{{ dir.errors }}/503-service-unavailable.html"
mode: 0644
- name: Deleting {{ dir.source }}/.venv if it exists
ansible.builtin.file:
path: "{{ dir.source }}/.venv"
state: absent
when: delete_venv
- name: Installing uWSGI {{ uwsgi_version }} in {{ dir.source }}/.venv
ansible.builtin.pip:
name: uwsgi
version: "{{ uwsgi_version }}"
virtualenv: "{{ dir.source }}/.venv"
virtualenv_command: python{{ python_version }} -m venv
chdir: "{{ dir.source }}"
- name: Installing Poetry in {{ dir.source }}/.venv
ansible.builtin.pip:
name: poetry
version: "{{ poetry_version }}"
virtualenv: "{{ dir.source }}/.venv"
virtualenv_command: python{{ python_version }} -m venv
chdir: "{{ dir.source }}"
tags:
- pip
- name: Installing remaining Python dependencies in {{ dir.source }}/.venv
environment:
CRYPTOGRAPHY_DONT_BUILD_RUST: "1"
loop:
- "{{ dir.source }}/.venv/bin/poetry install --no-dev"
- "{{ dir.source }}/.venv/bin/poetry config virtualenvs.create false"
- "{{ dir.source }}/.venv/bin/poetry config virtualenvs.in-project true"
ansible.builtin.command: "{{ item }}"
args:
chdir: "{{ dir.source }}"
changed_when: false
tags:
- pip
- name: Preparing to run database migrations
tags:
- migrate
block:
- name: Displaying database migrations
import_tasks: managepy.yaml
vars:
command: migrate --plan
- name: Displaying database migrations
ansible.builtin.debug:
var: management_command_output.stdout
- name: Confirming database migrations
when:
- management_command_output.stdout | length > 0
- ('No planned migration operations' not in management_command_output.stdout)
ansible.builtin.pause:
prompt: Press return to continue. Press Ctrl+c and then "a" to abort.
- name: Running database migrations
when:
- management_command_output.stdout | length > 0
- ('No planned migration operations' not in management_command_output.stdout)
import_tasks: managepy.yaml
vars:
command: migrate
changed_when:
- management_command_output.stdout | length > 0
- ('No planned migration operations' not in management_command_output.stdout)
- name: Collecting static files
ansible.builtin.command: "{{ dir.source }}/.venv/bin/python {{ dir.source }}/manage.py collectstatic --noinput"
args:
chdir: "{{ dir.source }}"
changed_when: true
tags:
- collectstatic
notify:
- restart service
- test nginx
- reload nginx