From ab32f6adf6a7473cb0fc835bce720e23bc139a4d Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Mon, 8 Jun 2020 09:52:34 +0300 Subject: [PATCH] Add self-building support to matrix-mailer (exim-relay) --- docs/alternative-architectures.md | 6 ++--- docs/self-building.md | 1 + group_vars/matrix_servers | 4 ++- roles/matrix-mailer/defaults/main.yml | 5 ++++ roles/matrix-mailer/tasks/setup_mailer.yml | 29 +++++++++++++++++++--- 5 files changed, 37 insertions(+), 8 deletions(-) diff --git a/docs/alternative-architectures.md b/docs/alternative-architectures.md index 07510d8a..43c14b67 100644 --- a/docs/alternative-architectures.md +++ b/docs/alternative-architectures.md @@ -19,6 +19,6 @@ matrix_architecture: "arm32" This subsection is used for a reminder, how the different roles implement architecture differenes. This is **not** aimed at the users, so one does not have to do anything based on this subsection. On most roles [self-building](self-building.md) is used if the architecture is not `amd64`, however there are some special cases: -- matrix-bridge-mautrix-facebook: there is built docker image for arm64 as well, -- matrix-bridge-mautrix-hangouts: there is built docker image for arm64 as well, -- matrix-nginx-proxy: Certbot has docker image for both arm32 and arm64, however tagging is used, which requires special handling. +- `matrix-bridge-mautrix-facebook`: there is a pre-built Docker image for `arm64` as well +- `matrix-bridge-mautrix-hangouts`: there is a pre-built Docker image for `arm64` as well +- `matrix-nginx-proxy`: Certbot has a pre-built Docker image for both `arm32` and `arm64`, however tagging is used, which requires special handling. diff --git a/docs/self-building.md b/docs/self-building.md index 85d09812..e4912090 100644 --- a/docs/self-building.md +++ b/docs/self-building.md @@ -15,6 +15,7 @@ List of roles where self-building the Docker image is currently possible: - `matrix-riot-web` - `matrix-coturn` - `matrix-ma1sd` +- `matrix-mailer` - `matrix-mautrix-facebook` - `matrix-mautrix-hangouts` - `matrix-mx-puppet-skype` diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index 8ff5ce96..6835c93a 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -537,11 +537,13 @@ matrix_jitsi_web_stun_servers: | # ###################################################################### -# By default, this playbook sets up a postfix mailer server (running in a container). +# By default, this playbook sets up an exim mailer server (running in a container). # This is so that Synapse can send email reminders for unread messages. # Other services (like ma1sd), also use the mailer. matrix_mailer_enabled: true +matrix_mailer_container_image_self_build: "{{ matrix_architecture != 'amd64'}}" + ###################################################################### # # /matrix-mailer diff --git a/roles/matrix-mailer/defaults/main.yml b/roles/matrix-mailer/defaults/main.yml index c1ffb0cf..0a8fd13c 100644 --- a/roles/matrix-mailer/defaults/main.yml +++ b/roles/matrix-mailer/defaults/main.yml @@ -2,6 +2,11 @@ matrix_mailer_enabled: true matrix_mailer_base_path: "{{ matrix_base_data_path }}/mailer" +matrix_mailer_container_image_self_build: false +matrix_mailer_container_image_self_build_repository_url: "https://github.com/devture/exim-relay" +matrix_mailer_container_image_self_build_src_files_path: "{{ matrix_mailer_base_path }}/docker-src" +matrix_mailer_container_image_self_build_version: "{{ matrix_mailer_docker_image.split(':')[1] }}" + matrix_mailer_docker_image: "devture/exim-relay:4.93.1-r0" matrix_mailer_docker_image_force_pull: "{{ matrix_mailer_docker_image.endswith(':latest') }}" diff --git a/roles/matrix-mailer/tasks/setup_mailer.yml b/roles/matrix-mailer/tasks/setup_mailer.yml index 6104edfe..99370638 100644 --- a/roles/matrix-mailer/tasks/setup_mailer.yml +++ b/roles/matrix-mailer/tasks/setup_mailer.yml @@ -6,12 +6,15 @@ - name: Ensure mailer base path exists file: - path: "{{ matrix_mailer_base_path }}" + path: "{{ item.path }}" state: directory mode: 0750 owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" - when: matrix_mailer_enabled|bool + with_items: + - { path: "{{ matrix_mailer_base_path }}", when: true } + - { path: "{{ matrix_mailer_container_image_self_build_src_files_path }}", when: "{{ matrix_mailer_container_image_self_build }}" } + when: "matrix_mailer_enabled|bool and item.when" - name: Ensure mailer environment variables file created template: @@ -20,13 +23,31 @@ mode: 0640 when: matrix_mailer_enabled|bool -- name: Ensure mailer image is pulled +- name: Ensure exim-relay repository is present on self-build + git: + repo: "{{ matrix_mailer_container_image_self_build_repository_url }}" + dest: "{{ matrix_mailer_container_image_self_build_src_files_path }}" + version: "{{ matrix_mailer_container_image_self_build_version }}" + force: "yes" + when: "matrix_mailer_container_image_self_build|bool" + +- name: Ensure exim-relay Docker image is built + docker_image: + name: "{{ matrix_mailer_docker_image }}" + source: build + build: + dockerfile: Dockerfile + path: "{{ matrix_mailer_container_image_self_build_src_files_path }}" + pull: yes + when: "matrix_mailer_enabled|bool and matrix_mailer_container_image_self_build|bool" + +- name: Ensure exim-relay image is pulled docker_image: name: "{{ matrix_mailer_docker_image }}" source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" force_source: "{{ matrix_mailer_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_mailer_docker_image_force_pull }}" - when: matrix_mailer_enabled|bool + when: "matrix_mailer_enabled|bool and not matrix_mailer_container_image_self_build|bool" - name: Ensure matrix-mailer.service installed template: