Move matrix-bridge-heisenbridge to its own container network

This commit is contained in:
Slavi Pantaleev 2024-01-07 14:53:22 +02:00
parent 493a9abafa
commit 39e45b0298
6 changed files with 74 additions and 32 deletions

View File

@ -1479,16 +1479,23 @@ matrix_sms_bridge_homeserver_token: "{{ '%s' | format(matrix_homeserver_generic_
# We don't enable bridges by default.
matrix_heisenbridge_enabled: false
matrix_heisenbridge_systemd_required_services_list_auto: |
{{
matrix_addons_homeserver_systemd_services_list
}}
matrix_heisenbridge_container_network: "{{ matrix_addons_container_network }}"
matrix_heisenbridge_container_additional_networks_auto: |-
{{
([] if matrix_addons_homeserver_container_network == '' else [matrix_addons_homeserver_container_network])
}}
matrix_heisenbridge_appservice_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'heisen.as.tok', rounds=655555) | to_uuid }}"
matrix_heisenbridge_homeserver_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'heisen.hs.tok', rounds=655555) | to_uuid }}"
matrix_heisenbridge_systemd_wanted_services_list: |
{{
['matrix-' + matrix_homeserver_implementation + '.service']
+
(['matrix-nginx-proxy.service'] if matrix_nginx_proxy_enabled else [])
}}
matrix_heisenbridge_homeserver_url: "{{ matrix_addons_homeserver_client_api_url }}"
######################################################################
#

View File

@ -17,6 +17,12 @@ matrix_heisenbridge_identd_enabled: false
matrix_heisenbridge_base_path: "{{ matrix_base_data_path }}/heisenbridge"
matrix_heisenbridge_container_network: ""
matrix_heisenbridge_container_additional_networks: "{{ matrix_heisenbridge_container_additional_networks_auto + matrix_heisenbridge_container_additional_networks_custom }}"
matrix_heisenbridge_container_additional_networks_auto: []
matrix_heisenbridge_container_additional_networks_custom: []
# Controls how long to wait for the container to stop gracefully before killing it.
# We use a small value here, because this container does not seem to handle the SIGTERM signal.
matrix_heisenbridge_container_stop_grace_time_seconds: 1
@ -25,12 +31,15 @@ matrix_heisenbridge_container_stop_grace_time_seconds: 1
matrix_heisenbridge_container_extra_arguments: []
# List of systemd services that service depends on.
matrix_heisenbridge_systemd_required_services_list: ['docker.service']
matrix_heisenbridge_systemd_required_services_list: "{{ matrix_heisenbridge_systemd_required_services_list_default + matrix_heisenbridge_systemd_required_services_list_auto + matrix_heisenbridge_systemd_required_services_list_custom }}"
matrix_heisenbridge_systemd_required_services_list_default: ['docker.service']
matrix_heisenbridge_systemd_required_services_list_auto: []
matrix_heisenbridge_systemd_required_services_list_custom: []
# List of systemd services that service wants
matrix_heisenbridge_systemd_wanted_services_list: []
matrix_heisenbridge_homeserver_url: "{{ matrix_homeserver_container_url }}"
matrix_heisenbridge_homeserver_url: ""
matrix_heisenbridge_appservice_token: ''
matrix_heisenbridge_homeserver_token: ''

View File

@ -6,6 +6,9 @@
- install-all
- install-heisenbridge
block:
- when: matrix_heisenbridge_enabled | bool
ansible.builtin.include_tasks: "{{ role_path }}/tasks/validate_config.yml"
- when: matrix_heisenbridge_enabled | bool
ansible.builtin.include_tasks: "{{ role_path }}/tasks/setup_install.yml"

View File

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

View File

@ -0,0 +1,10 @@
---
- name: Fail if required heisenbridge 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_heisenbridge_container_network', when: true}
- {'name': 'matrix_heisenbridge_homeserver_url', when: true}

View File

@ -16,15 +16,17 @@ Environment="HOME={{ devture_systemd_docker_base_systemd_unit_home_path }}"
ExecStartPre=-{{ devture_systemd_docker_base_host_command_docker }} stop --time={{ matrix_heisenbridge_container_stop_grace_time_seconds }} matrix-heisenbridge
ExecStartPre=-{{ devture_systemd_docker_base_host_command_docker }} rm matrix-heisenbridge
ExecStart={{ devture_systemd_docker_base_host_command_docker }} run --rm --name matrix-heisenbridge \
ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \
--rm \
--name=matrix-heisenbridge \
--log-driver=none \
--user={{ matrix_user_uid }}:{{ matrix_user_gid }} \
--cap-drop=ALL \
--network={{ matrix_docker_network }} \
--network={{ matrix_heisenbridge_container_network }} \
{% if matrix_heisenbridge_identd_enabled %}
-p 113:13113 \
{% endif %}
-v {{ matrix_heisenbridge_base_path }}:/config:z \
--mount type=bind,src={{ matrix_heisenbridge_base_path }},dst=/config \
{% for arg in matrix_heisenbridge_container_extra_arguments %}
{{ arg }} \
{% endfor %}
@ -41,6 +43,12 @@ ExecStart={{ devture_systemd_docker_base_host_command_docker }} run --rm --name
--listen-port 9898 \
{{ matrix_heisenbridge_homeserver_url }}
{% for network in matrix_heisenbridge_container_additional_networks %}
ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} network connect {{ network }} matrix-heisenbridge
{% endfor %}
ExecStart={{ devture_systemd_docker_base_host_command_docker }} start --attach matrix-heisenbridge
ExecStop=-{{ devture_systemd_docker_base_host_command_docker }} stop --time={{ matrix_heisenbridge_container_stop_grace_time_seconds }} matrix-heisenbridge
ExecStop=-{{ devture_systemd_docker_base_host_command_docker }} rm matrix-heisenbridge
Restart=always