From 20c7cabfe48c2ff017b95a53f6ed40d51fff76f8 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Tue, 2 Jan 2024 17:22:23 +0200 Subject: [PATCH] Switch mautrix-discord from matrix-nginx-proxy to matrix-homeserver-proxy --- group_vars/matrix_servers | 23 +++++++++++++------ .../defaults/main.yml | 11 ++++++++- .../tasks/setup_install.yml | 5 ++++ .../tasks/validate_config.yml | 1 + .../systemd/matrix-mautrix-discord.service.j2 | 12 ++++++++-- .../tasks/setup_install.yml | 5 ++++ 6 files changed, 47 insertions(+), 10 deletions(-) diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index 1f0cf0f83..419351bdb 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -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 '' }}" diff --git a/roles/custom/matrix-bridge-mautrix-discord/defaults/main.yml b/roles/custom/matrix-bridge-mautrix-discord/defaults/main.yml index af12acac7..70db0b397 100644 --- a/roles/custom/matrix-bridge-mautrix-discord/defaults/main.yml +++ b/roles/custom/matrix-bridge-mautrix-discord/defaults/main.yml @@ -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: [] diff --git a/roles/custom/matrix-bridge-mautrix-discord/tasks/setup_install.yml b/roles/custom/matrix-bridge-mautrix-discord/tasks/setup_install.yml index f16422f7a..77ff027e4 100644 --- a/roles/custom/matrix-bridge-mautrix-discord/tasks/setup_install.yml +++ b/roles/custom/matrix-bridge-mautrix-discord/tasks/setup_install.yml @@ -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" diff --git a/roles/custom/matrix-bridge-mautrix-discord/tasks/validate_config.yml b/roles/custom/matrix-bridge-mautrix-discord/tasks/validate_config.yml index 8f4fe29e4..4ee5e9f29 100644 --- a/roles/custom/matrix-bridge-mautrix-discord/tasks/validate_config.yml +++ b/roles/custom/matrix-bridge-mautrix-discord/tasks/validate_config.yml @@ -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' }}"} diff --git a/roles/custom/matrix-bridge-mautrix-discord/templates/systemd/matrix-mautrix-discord.service.j2 b/roles/custom/matrix-bridge-mautrix-discord/templates/systemd/matrix-mautrix-discord.service.j2 index d3af8eb77..190835cb2 100644 --- a/roles/custom/matrix-bridge-mautrix-discord/templates/systemd/matrix-mautrix-discord.service.j2 +++ b/roles/custom/matrix-bridge-mautrix-discord/templates/systemd/matrix-mautrix-discord.service.j2 @@ -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 diff --git a/roles/custom/matrix-bridge-mautrix-facebook/tasks/setup_install.yml b/roles/custom/matrix-bridge-mautrix-facebook/tasks/setup_install.yml index 36a643661..05773de9c 100644 --- a/roles/custom/matrix-bridge-mautrix-facebook/tasks/setup_install.yml +++ b/roles/custom/matrix-bridge-mautrix-facebook/tasks/setup_install.yml @@ -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"