Move matrix-email2matrix to its own container network

This commit is contained in:
Slavi Pantaleev 2024-01-13 17:05:58 +02:00
parent 809cce98cc
commit 3f212feb1f
6 changed files with 52 additions and 7 deletions

View File

@ -70,7 +70,6 @@ matrix_email2matrix_matrix_mappings:
SkipMarkdown: true
```
You can also set `MatrixHomeserverUrl` to `http://matrix-synapse-reverse-proxy-companion:8008`, instead of the public `https://matrix.DOMAIN`.
However, that's more likely to break in the future if you switch to another server implementation than Synapse.
You can also set `MatrixHomeserverUrl` to the container URL where your homeserver's Client-Server API lives by using the `{{ matrix_homeserver_container_url }}` variable, instead of the public `https://matrix.DOMAIN` endpoint.
Re-run the playbook (`--tags=setup-email2matrix,start`) and try sending an email to `my-mailbox@matrix.DOMAIN`.

View File

@ -2940,8 +2940,20 @@ matrix_dynamic_dns_enabled: false
matrix_email2matrix_enabled: false
matrix_email2matrix_systemd_required_services_list_auto: |
{{
matrix_addons_homeserver_systemd_services_list
}}
matrix_email2matrix_container_image_self_build: "{{ matrix_architecture not in ['amd64', 'arm32', 'arm64'] }}"
matrix_email2matrix_container_network: "{{ matrix_addons_container_network }}"
matrix_email2matrix_container_additional_networks_auto: |-
{{
([] if matrix_addons_homeserver_container_network == '' else [matrix_addons_homeserver_container_network])
}}
######################################################################
#
# /matrix-email2matrix

View File

@ -17,11 +17,20 @@ matrix_email2matrix_docker_image_prefix: "{{ 'localhost/' if matrix_email2matrix
matrix_email2matrix_docker_image: "{{ matrix_email2matrix_docker_image_prefix }}devture/email2matrix:{{ matrix_email2matrix_version }}"
matrix_email2matrix_docker_image_force_pull: "{{ matrix_email2matrix_docker_image.endswith(':latest') }}"
matrix_email2matrix_container_network: ""
matrix_email2matrix_container_additional_networks: "{{ matrix_email2matrix_container_additional_networks_auto + matrix_email2matrix_container_additional_networks_custom }}"
matrix_email2matrix_container_additional_networks_auto: []
matrix_email2matrix_container_additional_networks_custom: []
# A list of extra arguments to pass to the container
matrix_email2matrix_container_extra_arguments: []
# List of systemd services that matrix-corporal.service depends on
matrix_email2matrix_systemd_required_services_list: ['docker.service']
matrix_email2matrix_systemd_required_services_list: "{{ matrix_email2matrix_systemd_required_services_list_default + matrix_email2matrix_systemd_required_services_list_auto + matrix_email2matrix_systemd_required_services_list_custom }}"
matrix_email2matrix_systemd_required_services_list_default: ['docker.service']
matrix_email2matrix_systemd_required_services_list_auto: []
matrix_email2matrix_systemd_required_services_list_custom: []
# Controls where the matrix-email2matrix container exposes the SMTP (tcp/2525 in the container).
#

View File

@ -56,6 +56,11 @@
pull: true
when: "matrix_email2matrix_container_image_self_build | bool"
- name: Ensure matrix-email2matrix container network is created
community.general.docker_network:
name: "{{ matrix_email2matrix_container_network }}"
driver: bridge
- name: Ensure matrix-email2matrix.service installed
ansible.builtin.template:
src: "{{ role_path }}/templates/systemd/matrix-email2matrix.service.j2"

View File

@ -5,3 +5,13 @@
msg: >
You need to define at least one mapping in `matrix_email2matrix_matrix_mappings` for enabling Email2Matrix.
when: "matrix_email2matrix_matrix_mappings | length == 0"
- name: Fail if required email2matrix settings not defined
ansible.builtin.fail:
msg: >-
You need to define a required configuration setting (`{{ item.name }}`).
when: "item.when | bool and vars[item.name] == ''"
with_items:
- {'name': 'matrix_email2matrix_container_network', when: true}

View File

@ -1,8 +1,10 @@
#jinja2: lstrip_blocks: "True"
[Unit]
Description=Email2Matrix
After=docker.service
Requires=docker.service
{% for service in matrix_email2matrix_systemd_required_services_list %}
Requires={{ service }}
After={{ service }}
{% endfor %}
DefaultDependencies=no
[Service]
@ -11,12 +13,14 @@ Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}"
ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop --time={{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-email2matrix 2>/dev/null || true'
ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-email2matrix 2>/dev/null || true'
ExecStart={{ devture_systemd_docker_base_host_command_docker }} run --rm --name matrix-email2matrix \
ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \
--rm \
--name=matrix-email2matrix \
--log-driver=none \
--user={{ matrix_user_uid }}:{{ matrix_user_gid }} \
--cap-drop=ALL \
--read-only \
--network={{ matrix_docker_network }} \
--network={{ matrix_email2matrix_container_network }} \
-p {{ matrix_email2matrix_smtp_host_bind_port }}:2525 \
--mount type=bind,src={{ matrix_email2matrix_config_dir_path }}/config.json,dst=/config.json,ro \
{% for arg in matrix_email2matrix_container_extra_arguments %}
@ -24,6 +28,12 @@ ExecStart={{ devture_systemd_docker_base_host_command_docker }} run --rm --name
{% endfor %}
{{ matrix_email2matrix_docker_image }}
{% for network in matrix_email2matrix_container_additional_networks %}
ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} network connect {{ network }} matrix-email2matrix
{% endfor %}
ExecStart={{ devture_systemd_docker_base_host_command_docker }} start --attach matrix-email2matrix
ExecStop=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} stop --time={{ devture_systemd_docker_base_container_stop_grace_time_seconds }} matrix-email2matrix 2>/dev/null || true'
ExecStop=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-email2matrix 2>/dev/null || true'
Restart=always