Switch mautrix-discord from matrix-nginx-proxy to matrix-homeserver-proxy

This commit is contained in:
Slavi Pantaleev 2024-01-02 17:22:23 +02:00
parent 77b0ef4799
commit 20c7cabfe4
6 changed files with 47 additions and 10 deletions

View File

@ -806,19 +806,28 @@ matrix_mautrix_discord_enabled: false
matrix_mautrix_discord_container_image_self_build: "{{ matrix_architecture not in ['arm64', 'amd64'] }}"
matrix_mautrix_discord_systemd_required_services_list: |
matrix_mautrix_discord_container_network: "{{ matrix_bridges_container_network }}"
matrix_mautrix_discord_container_additional_networks_auto: |-
{{
['docker.service']
(
([] if matrix_bridges_homeserver_container_network == '' else [matrix_bridges_homeserver_container_network])
+
([devture_postgres_container_network] if devture_postgres_enabled and matrix_mautrix_facebook_database_hostname == devture_postgres_connection_hostname else [])
) | unique
}}
matrix_mautrix_discord_systemd_required_services_list_auto: |
{{
matrix_bots_homeserver_systemd_services_list
+
['matrix-' + matrix_homeserver_implementation + '.service']
+
([devture_postgres_identifier ~ '.service'] if devture_postgres_enabled else [])
+
(['matrix-nginx-proxy.service'] if matrix_nginx_proxy_enabled else [])
([devture_postgres_identifier ~ '.service'] if (devture_postgres_enabled and matrix_mautrix_discord_database_hostname == devture_postgres_connection_hostname) else [])
}}
matrix_mautrix_discord_appservice_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'maudisc.as.tok', rounds=655555) | to_uuid }}"
matrix_mautrix_discord_homeserver_address: "{{ matrix_bridges_homeserver_client_api_url }}"
matrix_mautrix_discord_homeserver_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'maudisc.hs.tok', rounds=655555) | to_uuid }}"
matrix_mautrix_discord_login_shared_secret: "{{ matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret if matrix_synapse_ext_password_provider_shared_secret_auth_enabled else '' }}"

View File

@ -33,11 +33,20 @@ matrix_mautrix_discord_bridge_permissions: |
| combine({matrix_admin: 'admin'} if matrix_admin else {})
}}
matrix_mautrix_discord_container_network: ''
matrix_mautrix_discord_container_additional_networks: "{{ matrix_mautrix_discord_container_additional_networks_auto + matrix_mautrix_discord_container_additional_networks_custom }}"
matrix_mautrix_discord_container_additional_networks_auto: []
matrix_mautrix_discord_container_additional_networks_custom: []
# A list of extra arguments to pass to the container
matrix_mautrix_discord_container_extra_arguments: []
# List of systemd services that matrix-mautrix-discord.service depends on.
matrix_mautrix_discord_systemd_required_services_list: ['docker.service']
matrix_mautrix_discord_systemd_required_services_list: "{{ matrix_mautrix_discord_systemd_required_services_list_default + matrix_mautrix_discord_systemd_required_services_list_auto + matrix_mautrix_discord_systemd_required_services_list_custom }}"
matrix_mautrix_discord_systemd_required_services_list_default: ['docker.service']
matrix_mautrix_discord_systemd_required_services_list_auto: []
matrix_mautrix_discord_systemd_required_services_list_custom: []
# List of systemd services that matrix-mautrix-discord.service wants
matrix_mautrix_discord_systemd_wanted_services_list: []

View File

@ -93,6 +93,11 @@
owner: "{{ matrix_user_username }}"
group: "{{ matrix_user_groupname }}"
- name: Ensure mautrix-discord container network is created
community.general.docker_network:
name: "{{ matrix_mautrix_discord_container_network }}"
driver: bridge
- name: Ensure matrix-mautrix-discord.service installed
ansible.builtin.template:
src: "{{ role_path }}/templates/systemd/matrix-mautrix-discord.service.j2"

View File

@ -8,4 +8,5 @@
with_items:
- {'name': 'matrix_mautrix_discord_appservice_token', when: true}
- {'name': 'matrix_mautrix_discord_homeserver_token', when: true}
- {'name': 'matrix_mautrix_discord_container_network', when: true}
- {'name': 'matrix_mautrix_discord_database_hostname', when: "{{ matrix_mautrix_discord_database_engine == 'postgres' }}"}

View File

@ -19,11 +19,13 @@ ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_s
# Intentional delay, so that the homeserver (we likely depend on) can manage to start.
ExecStartPre={{ matrix_host_command_sleep }} 5
ExecStart={{ devture_systemd_docker_base_host_command_docker }} run --rm --name matrix-mautrix-discord \
ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \
--rm \
--name=matrix-mautrix-discord \
--log-driver=none \
--user={{ matrix_user_uid }}:{{ matrix_user_gid }} \
--cap-drop=ALL \
--network={{ matrix_docker_network }} \
--network={{ matrix_mautrix_discord_container_network }} \
--mount type=bind,src={{ matrix_mautrix_discord_config_path }},dst=/config,ro \
--mount type=bind,src={{ matrix_mautrix_discord_data_path }},dst=/data \
--workdir=/data \
@ -33,6 +35,12 @@ ExecStart={{ devture_systemd_docker_base_host_command_docker }} run --rm --name
{{ matrix_mautrix_discord_docker_image }} \
/usr/bin/mautrix-discord -c /config/config.yaml -r /config/registration.yaml --no-update
{% for network in matrix_mautrix_discord_container_additional_networks %}
ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} network connect {{ network }} matrix-mautrix-discord
{% endfor %}
ExecStart={{ devture_systemd_docker_base_host_command_docker }} start --attach matrix-mautrix-discord
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-mautrix-discord 2>/dev/null || true'
ExecStop=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-mautrix-discord 2>/dev/null || true'
Restart=always

View File

@ -129,6 +129,11 @@
dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-mautrix-facebook.service"
mode: 0644
- name: Ensure matrix-mautrix-facebook container network is created
community.general.docker_network:
name: "{{ matrix_mautrix_facebook_container_network }}"
driver: bridge
- name: Ensure matrix-mautrix-facebook.service restarted, if necessary
ansible.builtin.service:
name: "matrix-mautrix-facebook.service"