feat(synapse): add deployment method virtualenv

This commit is contained in:
transcaffeine 2024-09-26 23:13:41 +02:00
parent 7764a1dd9f
commit d379c0469d
Signed by: transcaffeine
GPG Key ID: 03624C433676E465
7 changed files with 73 additions and 4 deletions

View File

@ -20,10 +20,7 @@ The following variables need to be populated:
- `docker`
- `podman`
- `venv` - Python virtual env supervised with `systemd`
Set `synapse_deployment_method` to one of the supported deployment methods.
The current default is `docker`.
### Planned deployment methods
- `venv` - Python virtual env supervised with `systemd`

View File

@ -11,6 +11,7 @@ synapse_data_path: "{{ synapse_base_path }}/data"
synapse_media_store_path: "{{ synapse_data_path }}/media_store"
synapse_log_path: "/var/log/synapse"
synapse_homeserver_log_path: "{{ synapse_log_path }}/homeserver.log"
synapse_venv_path: "{{ synapse_base_path }}/venv"
synapse_signing_key: ~
synapse_signing_key_file: >-

View File

@ -0,0 +1,8 @@
---
synapse_systemd_service_name: "synapse.service"
synapse_systemd_service_directory: /etc/systemd/system
synapse_systemd_service_file: >-2
{{ synapse_systemd_service_directory }}/{{ synapse_systemd_service_name }}
synapse_systemd_service_enabled: >-2
{{ (synapse_state == 'present') | bool }}

View File

@ -0,0 +1,6 @@
---
synapse_venv_package:
- synapse
synapse_venv_pip_dependencies:
- pip
- setuptools

View File

@ -14,3 +14,8 @@
state: "{{ synapse_container_state }}"
force_restart: true
when: synapse_deployment_method == 'podman'
- name: Ensure systemd units are reloaded
listen: systemd-daemon-reload
ansible.builtin.systemd:
daemon_reload: true

View File

@ -0,0 +1,51 @@
---
- name: Ensure directory for virtualenv is {{ synapse_state }}
ansible.builtin.file:
path: "{{ synapse_venv_path }}"
owner: >-2
{{ synapse_user_info.uid | default(synapse_user) }}
group: >-2
{{ synapse_user_info.group | default(synapse_user) }}
mode: "{{ synapse_venv_path_mode | default('0755') }}"
state: >-
{{ (synapse_state == 'present')
| ternary('directory', 'absent') }}
- name: Ensure virtual environment is {{ synapse_state }}
ansible.builtin.pip:
name: "{{ synapse_venv_pip_dependencies }}"
virtualenv: "{{ synapse_venv_path }}"
virtualenv_python: >-
{{ synapse_virtualenv_python_binary
| default(ansible_python_interpreter
| default(omit, true), true) }}
extra_args: "{{ synapse_venv_extra_args }}"
state: "{{ synapse_state }}"
- name: Ensure synapse is {{ synapse_state }}
ansible.builtin.pip:
name: "{{ synapse_venv_package }}"
version: "{{ synapse_version }}"
state: "{{ synapse_state }}"
virtualenv: "{{ synapse_venv_path }}"
notify:
- synapse-restart
- name: Ensure systemd unit is {{ synapse_state }}
ansible.builtin.template:
src: "synapse.service.j2"
dest: "{{ synapse_systemd_service_file }}"
notify:
- systemd-daemon-reload
- meta: flush_handlers
- name: Ensure systemd service is {{ synapse_state }}
ansible.builtin.systemd:
name: "{{ synapse_systemd_service_name }}"
state: "{{ synapse_state }}"
- name: Ensure systemd service is {{ synapse_systemd_service_enabled | ternary('enabled', 'disabled') }}
ansible.builtin.systemd:
name: "{{ synapse_systemd_service_name }}"
enabled: "{{ synapse_systemd_service_enabled }}"

View File

@ -6,6 +6,7 @@ synapse_states:
synapse_deployment_methods:
- docker
- podman
- venv
synapse_required_variables:
- synapse_domain