From a096eafb45c3aba23573ef3d8689d634c59da876 Mon Sep 17 00:00:00 2001 From: Horvath Gergely Date: Mon, 17 Feb 2020 21:48:48 +0100 Subject: [PATCH] add possibility to install synapse on raspberry pi --- group_vars/matrix_servers | 16 ++++++++++++++++ roles/matrix-base/defaults/main.yml | 2 ++ roles/matrix-base/tasks/sanity_check.yml | 7 +++++++ roles/matrix-base/tasks/server_base/setup.yml | 4 ++-- roles/matrix-base/tasks/setup_matrix_base.yml | 2 ++ .../tasks/synapse/setup_install.yml | 19 +++++++++++++++++++ 6 files changed, 48 insertions(+), 2 deletions(-) diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index 1c7ac23fd..148382fa7 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -678,3 +678,19 @@ matrix_synapse_systemd_wanted_services_list: | # /matrix-synapse # ###################################################################### + + + +###################################################################### +# +# raspberry pi +# +###################################################################### + +matrix_raspberry_pi: "false" + +###################################################################### +# +# /raspberry pi +# +###################################################################### diff --git a/roles/matrix-base/defaults/main.yml b/roles/matrix-base/defaults/main.yml index b4fef1dd7..b5897d0d1 100644 --- a/roles/matrix-base/defaults/main.yml +++ b/roles/matrix-base/defaults/main.yml @@ -26,6 +26,8 @@ matrix_base_data_path: "/matrix" matrix_base_data_path_mode: "750" matrix_static_files_base_path: "{{ matrix_base_data_path }}/static-files" +matrix_docker_src_files_path: "{{ matrix_base_data_path }}/docker-src" +matrix_docker_synapse_src_files_path: "{{ matrix_docker_src_files_path }}/synapse" matrix_homeserver_url: "https://{{ matrix_server_fqn_matrix }}" diff --git a/roles/matrix-base/tasks/sanity_check.yml b/roles/matrix-base/tasks/sanity_check.yml index b2d8c249e..a0a92a227 100644 --- a/roles/matrix-base/tasks/sanity_check.yml +++ b/roles/matrix-base/tasks/sanity_check.yml @@ -44,3 +44,10 @@ - "{{ matrix_server_fqn_matrix }}" - "{{ matrix_server_fqn_riot }}" when: "item != item|lower" + +# ansible lower than 2.8, does not support docker_image build parameters +# for Raspberry pi it is explicitly needed, so we rather fail here +- name: Fail if running on Ansible lower than 2.8 and targeting Raspberry pi + fail: + msg: "To target Raspberry pi, you should usa ansible 2.8 or higher. E.g. pip contains such packages." + when: "ansible_version.major == 2 and ansible_version.minor < 8 and matrix_raspberry_pi" diff --git a/roles/matrix-base/tasks/server_base/setup.yml b/roles/matrix-base/tasks/server_base/setup.yml index 7cb716a93..bd52a0e74 100644 --- a/roles/matrix-base/tasks/server_base/setup.yml +++ b/roles/matrix-base/tasks/server_base/setup.yml @@ -4,10 +4,10 @@ when: ansible_distribution == 'CentOS' - include_tasks: "{{ role_path }}/tasks/server_base/setup_debian.yml" - when: (ansible_os_family == 'Debian') and (ansible_lsb.id != 'Raspbian') + when: (ansible_os_family == 'Debian') and (ansible_lsb.id != 'Raspbian') - include_tasks: "{{ role_path }}/tasks/server_base/setup_raspbian.yml" - when: (ansible_os_family == 'Debian') and (ansible_lsb.id == 'Raspbian') + when: "matrix_raspberry_pi" - name: Ensure Docker is started and autoruns service: diff --git a/roles/matrix-base/tasks/setup_matrix_base.yml b/roles/matrix-base/tasks/setup_matrix_base.yml index b4aa92b9a..952a37a5d 100644 --- a/roles/matrix-base/tasks/setup_matrix_base.yml +++ b/roles/matrix-base/tasks/setup_matrix_base.yml @@ -22,6 +22,8 @@ group: "{{ matrix_user_username }}" with_items: - "{{ matrix_base_data_path }}" + - "{{ matrix_docker_src_files_path }}" + - "{{ matrix_docker_synapse_src_files_path }}" # `docker_network` doesn't work as expected when the given network # is a substring of a network that already exists. diff --git a/roles/matrix-synapse/tasks/synapse/setup_install.yml b/roles/matrix-synapse/tasks/synapse/setup_install.yml index 88fb0049c..33f04a288 100644 --- a/roles/matrix-synapse/tasks/synapse/setup_install.yml +++ b/roles/matrix-synapse/tasks/synapse/setup_install.yml @@ -18,12 +18,31 @@ group: "{{ matrix_user_username }}" when: "not local_path_media_store_stat.failed and not local_path_media_store_stat.stat.exists" +- name: Ensure Synapse repository is present on Raspberry pi + git: + repo: https://github.com/matrix-org/synapse.git + dest: "{{ matrix_docker_synapse_src_files_path }}" + version: "{{ matrix_synapse_docker_image.split(':')[1] }}" + force: "yes" + when: "matrix_raspberry_pi" + +- name: Ensure Synapse Docker image is build (Raspberry pi) + docker_image: + name: "{{ matrix_synapse_docker_image }}" + source: build + build: + dockerfile: docker/Dockerfile + path: "{{ matrix_docker_synapse_src_files_path }}" + pull: yes + when: "matrix_raspberry_pi" + - name: Ensure Synapse Docker image is pulled docker_image: name: "{{ matrix_synapse_docker_image }}" source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_synapse_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}" force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_synapse_docker_image_force_pull }}" + when: "not matrix_raspberry_pi" - name: Check if a Synapse signing key exists stat: