Browse Source

Move matrix-bridge-heisenbridge to its own container network

pull/3093/head
Slavi Pantaleev 2 years ago
parent
commit
39e45b0298
6 changed files with 74 additions and 32 deletions
  1. +13
    -6
      group_vars/matrix_servers
  2. +11
    -2
      roles/custom/matrix-bridge-heisenbridge/defaults/main.yml
  3. +3
    -0
      roles/custom/matrix-bridge-heisenbridge/tasks/main.yml
  4. +5
    -0
      roles/custom/matrix-bridge-heisenbridge/tasks/setup_install.yml
  5. +10
    -0
      roles/custom/matrix-bridge-heisenbridge/tasks/validate_config.yml
  6. +32
    -24
      roles/custom/matrix-bridge-heisenbridge/templates/systemd/matrix-heisenbridge.service.j2

+ 13
- 6
group_vars/matrix_servers View File

@@ -1479,17 +1479,24 @@ matrix_sms_bridge_homeserver_token: "{{ '%s' | format(matrix_homeserver_generic_
# We don't enable bridges by default. # We don't enable bridges by default.
matrix_heisenbridge_enabled: false matrix_heisenbridge_enabled: false


matrix_heisenbridge_appservice_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'heisen.as.tok', rounds=655555) | to_uuid }}"
matrix_heisenbridge_systemd_required_services_list_auto: |
{{
matrix_addons_homeserver_systemd_services_list
}}


matrix_heisenbridge_homeserver_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'heisen.hs.tok', rounds=655555) | to_uuid }}"
matrix_heisenbridge_container_network: "{{ matrix_addons_container_network }}"


matrix_heisenbridge_systemd_wanted_services_list: |
matrix_heisenbridge_container_additional_networks_auto: |-
{{ {{
['matrix-' + matrix_homeserver_implementation + '.service']
+
(['matrix-nginx-proxy.service'] if matrix_nginx_proxy_enabled else [])
([] 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_homeserver_url: "{{ matrix_addons_homeserver_client_api_url }}"

###################################################################### ######################################################################
# #
# /matrix-bridge-heisenbridge # /matrix-bridge-heisenbridge


+ 11
- 2
roles/custom/matrix-bridge-heisenbridge/defaults/main.yml View File

@@ -17,6 +17,12 @@ matrix_heisenbridge_identd_enabled: false


matrix_heisenbridge_base_path: "{{ matrix_base_data_path }}/heisenbridge" 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. # 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. # 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 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: [] matrix_heisenbridge_container_extra_arguments: []


# List of systemd services that service depends on. # 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 # List of systemd services that service wants
matrix_heisenbridge_systemd_wanted_services_list: [] matrix_heisenbridge_systemd_wanted_services_list: []


matrix_heisenbridge_homeserver_url: "{{ matrix_homeserver_container_url }}"
matrix_heisenbridge_homeserver_url: ""


matrix_heisenbridge_appservice_token: '' matrix_heisenbridge_appservice_token: ''
matrix_heisenbridge_homeserver_token: '' matrix_heisenbridge_homeserver_token: ''


+ 3
- 0
roles/custom/matrix-bridge-heisenbridge/tasks/main.yml View File

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

- when: matrix_heisenbridge_enabled | bool - when: matrix_heisenbridge_enabled | bool
ansible.builtin.include_tasks: "{{ role_path }}/tasks/setup_install.yml" ansible.builtin.include_tasks: "{{ role_path }}/tasks/setup_install.yml"




+ 5
- 0
roles/custom/matrix-bridge-heisenbridge/tasks/setup_install.yml View File

@@ -29,6 +29,11 @@
owner: "{{ matrix_user_username }}" owner: "{{ matrix_user_username }}"
group: "{{ matrix_user_groupname }}" 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 - name: Ensure matrix-heisenbridge.service installed
ansible.builtin.template: ansible.builtin.template:
src: "{{ role_path }}/templates/systemd/matrix-heisenbridge.service.j2" src: "{{ role_path }}/templates/systemd/matrix-heisenbridge.service.j2"


+ 10
- 0
roles/custom/matrix-bridge-heisenbridge/tasks/validate_config.yml 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}

+ 32
- 24
roles/custom/matrix-bridge-heisenbridge/templates/systemd/matrix-heisenbridge.service.j2 View File

@@ -16,30 +16,38 @@ 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 }} stop --time={{ matrix_heisenbridge_container_stop_grace_time_seconds }} matrix-heisenbridge
ExecStartPre=-{{ devture_systemd_docker_base_host_command_docker }} rm 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 \
--log-driver=none \
--user={{ matrix_user_uid }}:{{ matrix_user_gid }} \
--cap-drop=ALL \
--network={{ matrix_docker_network }} \
{% if matrix_heisenbridge_identd_enabled %}
-p 113:13113 \
{% endif %}
-v {{ matrix_heisenbridge_base_path }}:/config:z \
{% for arg in matrix_heisenbridge_container_extra_arguments %}
{{ arg }} \
{% endfor %}
{{ matrix_heisenbridge_docker_image }} \
{% if matrix_heisenbridge_identd_enabled %}
--identd \
--identd-port 13113 \
{% endif %}
{% if matrix_heisenbridge_owner %}
-o {{ matrix_heisenbridge_owner }} \
{% endif %}
--config /config/registration.yaml \
--listen-address 0.0.0.0 \
--listen-port 9898 \
{{ matrix_heisenbridge_homeserver_url }}
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_heisenbridge_container_network }} \
{% if matrix_heisenbridge_identd_enabled %}
-p 113:13113 \
{% endif %}
--mount type=bind,src={{ matrix_heisenbridge_base_path }},dst=/config \
{% for arg in matrix_heisenbridge_container_extra_arguments %}
{{ arg }} \
{% endfor %}
{{ matrix_heisenbridge_docker_image }} \
{% if matrix_heisenbridge_identd_enabled %}
--identd \
--identd-port 13113 \
{% endif %}
{% if matrix_heisenbridge_owner %}
-o {{ matrix_heisenbridge_owner }} \
{% endif %}
--config /config/registration.yaml \
--listen-address 0.0.0.0 \
--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 }} stop --time={{ matrix_heisenbridge_container_stop_grace_time_seconds }} matrix-heisenbridge
ExecStop=-{{ devture_systemd_docker_base_host_command_docker }} rm matrix-heisenbridge ExecStop=-{{ devture_systemd_docker_base_host_command_docker }} rm matrix-heisenbridge


Loading…
Cancel
Save