Просмотр исходного кода

Move matrix-email2matrix to its own container network

pull/3093/head
Slavi Pantaleev 2 лет назад
Родитель
Сommit
3f212feb1f
6 измененных файлов: 52 добавлений и 7 удалений
  1. +1
    -2
      docs/configuring-playbook-email2matrix.md
  2. +12
    -0
      group_vars/matrix_servers
  3. +10
    -1
      roles/custom/matrix-email2matrix/defaults/main.yml
  4. +5
    -0
      roles/custom/matrix-email2matrix/tasks/setup_install.yml
  5. +10
    -0
      roles/custom/matrix-email2matrix/tasks/validate_config.yml
  6. +14
    -4
      roles/custom/matrix-email2matrix/templates/systemd/matrix-email2matrix.service.j2

+ 1
- 2
docs/configuring-playbook-email2matrix.md Просмотреть файл

@@ -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`.

+ 12
- 0
group_vars/matrix_servers Просмотреть файл

@@ -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


+ 10
- 1
roles/custom/matrix-email2matrix/defaults/main.yml Просмотреть файл

@@ -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).
#


+ 5
- 0
roles/custom/matrix-email2matrix/tasks/setup_install.yml Просмотреть файл

@@ -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"


+ 10
- 0
roles/custom/matrix-email2matrix/tasks/validate_config.yml Просмотреть файл

@@ -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}



+ 14
- 4
roles/custom/matrix-email2matrix/templates/systemd/matrix-email2matrix.service.j2 Просмотреть файл

@@ -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


Загрузка…
Отмена
Сохранить