From 5e62850727cfedfee17c04cd36a3c60a796dd0cb Mon Sep 17 00:00:00 2001 From: Yan Minagawa Date: Thu, 18 Jan 2024 23:13:26 +0000 Subject: [PATCH] initial copy of webhooks service --- group_vars/matrix_servers | 58 ++++++++ .../defaults/main.yml | 124 ++++++++++++++++++ .../tasks/main.yml | 20 +++ .../tasks/setup_install.yml | 103 +++++++++++++++ .../tasks/setup_uninstall.yml | 20 +++ .../tasks/validate_config.yml | 16 +++ .../templates/config.yaml.j2 | 28 ++++ .../templates/database.json.j2 | 13 ++ .../templates/labels.j2 | 44 +++++++ .../templates/schema.yml.j2 | 54 ++++++++ .../matrix-appservice-webhooks.service.j2 | 51 +++++++ setup.yml | 1 + 12 files changed, 532 insertions(+) create mode 100644 roles/custom/matrix-bridge-appservice-polychat/defaults/main.yml create mode 100644 roles/custom/matrix-bridge-appservice-polychat/tasks/main.yml create mode 100644 roles/custom/matrix-bridge-appservice-polychat/tasks/setup_install.yml create mode 100644 roles/custom/matrix-bridge-appservice-polychat/tasks/setup_uninstall.yml create mode 100644 roles/custom/matrix-bridge-appservice-polychat/tasks/validate_config.yml create mode 100644 roles/custom/matrix-bridge-appservice-polychat/templates/config.yaml.j2 create mode 100644 roles/custom/matrix-bridge-appservice-polychat/templates/database.json.j2 create mode 100644 roles/custom/matrix-bridge-appservice-polychat/templates/labels.j2 create mode 100644 roles/custom/matrix-bridge-appservice-polychat/templates/schema.yml.j2 create mode 100644 roles/custom/matrix-bridge-appservice-polychat/templates/systemd/matrix-appservice-webhooks.service.j2 diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index 92653ee3b..64962065d 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -79,6 +79,8 @@ matrix_homeserver_container_extra_arguments_auto: | + (['--mount type=bind,src=' + matrix_appservice_webhooks_config_path + '/webhooks-registration.yaml,dst=/matrix-appservice-webhooks-registration.yaml,ro'] if matrix_appservice_webhooks_enabled else []) + + (['--mount type=bind,src=' + matrix_appservice_polychat_config_path + '/polychat-registration.yaml,dst=/matrix-appservice-polychat-registration.yaml,ro'] if matrix_appservice_polychat_enabled else []) + + (['--mount type=bind,src=' + matrix_beeper_linkedin_config_path + '/registration.yaml,dst=/matrix-beeper-linkedin-registration.yaml,ro'] if matrix_beeper_linkedin_enabled else []) + (['--mount type=bind,src=' + matrix_go_skype_bridge_config_path + '/registration.yaml,dst=/matrix-go-skype-bridge-registration.yaml,ro'] if matrix_go_skype_bridge_enabled else []) @@ -142,6 +144,8 @@ matrix_homeserver_app_service_config_files_auto: | + (['/matrix-appservice-webhooks-registration.yaml'] if matrix_appservice_webhooks_enabled else []) + + (['/matrix-appservice-polychat-registration.yaml'] if matrix_appservice_polychat_enabled else []) + + (['/matrix-beeper-linkedin-registration.yaml'] if matrix_beeper_linkedin_enabled else []) + (['/matrix-go-skype-bridge-registration.yaml'] if matrix_go_skype_bridge_enabled else []) @@ -266,6 +270,8 @@ devture_systemd_service_manager_services_list_auto: | + ([{'name': 'matrix-appservice-webhooks.service', 'priority': 2000, 'groups': ['matrix', 'bridges', 'appservice-webhooks']}] if matrix_appservice_webhooks_enabled else []) + + ([{'name': 'matrix-appservice-polychat.service', 'priority': 2000, 'groups': ['matrix', 'bridges', 'appservice-polychat']}] if matrix_appservice_polychat_enabled else []) + + ([{'name': 'matrix-beeper-linkedin.service', 'priority': 2000, 'groups': ['matrix', 'bridges', 'beeper-linkedin']}] if matrix_beeper_linkedin_enabled else []) + ([{'name': 'matrix-go-skype-bridge.service', 'priority': 2000, 'groups': ['matrix', 'bridges', 'go-skype']}] if matrix_go_skype_bridge_enabled else []) @@ -595,6 +601,58 @@ matrix_appservice_webhooks_id_token: "{{ '%s' | format(matrix_homeserver_generic ###################################################################### +###################################################################### +# +# matrix-appservice-polychat +# +###################################################################### + +# We don't enable bridges by default. +matrix_appservice_polychat_enabled: false + +matrix_appservice_polychat_hostname: "{{ matrix_server_fqn_matrix }}" + +matrix_appservice_polychat_systemd_required_services_list_auto: | + {{ + matrix_addons_homeserver_systemd_services_list + }} + +matrix_appservice_polychat_container_image_self_build: "{{ matrix_architecture != 'amd64' }}" + +matrix_appservice_polychat_container_http_host_bind_port: "{{ (matrix_playbook_service_host_bind_interface_prefix ~ matrix_appservice_polychat_matrix_port) if matrix_playbook_service_host_bind_interface_prefix else '' }}" + +matrix_appservice_polychat_container_network: "{{ matrix_addons_container_network }}" + +matrix_appservice_polychat_container_additional_networks_auto: |- + {{ + ( + ([] if matrix_addons_homeserver_container_network == '' else [matrix_addons_homeserver_container_network]) + + + ([matrix_playbook_reverse_proxyable_services_additional_network] if (matrix_playbook_reverse_proxyable_services_additional_network and matrix_appservice_polychat_container_labels_traefik_enabled) else []) + ) | unique + }} + +matrix_appservice_polychat_container_labels_traefik_enabled: "{{ matrix_playbook_reverse_proxy_type in ['playbook-managed-traefik', 'other-traefik-container'] }}" +matrix_appservice_polychat_container_labels_traefik_docker_network: "{{ matrix_playbook_reverse_proxyable_services_additional_network }}" +matrix_appservice_polychat_container_labels_traefik_entrypoints: "{{ devture_traefik_entrypoint_primary }}" +matrix_appservice_polychat_container_labels_traefik_tls_certResolver: "{{ devture_traefik_certResolver_primary }}" + +matrix_appservice_polychat_appservice_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'webhook.as.token', rounds=655555) | to_uuid }}" + +matrix_appservice_polychat_homeserver_url: "{{ matrix_addons_homeserver_client_api_url }}" +matrix_appservice_polychat_homeserver_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'webhook.hs.token', rounds=655555) | to_uuid }}" + +matrix_appservice_polychat_id_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'webhook.id.token', rounds=655555) | to_uuid }}" + +###################################################################### +# +# /matrix-appservice-polychat +# +###################################################################### + + + + ###################################################################### # # matrix-appservice-slack diff --git a/roles/custom/matrix-bridge-appservice-polychat/defaults/main.yml b/roles/custom/matrix-bridge-appservice-polychat/defaults/main.yml new file mode 100644 index 000000000..fe6941558 --- /dev/null +++ b/roles/custom/matrix-bridge-appservice-polychat/defaults/main.yml @@ -0,0 +1,124 @@ +--- +# Matrix Appservice Polychat is a bridge service to multiple networks +# Project source code URL: https://github.com/polychatproject/polychat-appservice + +matrix_appservice_polychat_enabled: true + +matrix_appservice_polychat_scheme: https +matrix_appservice_polychat_hostname: '' +matrix_appservice_polychat_path_prefix: /appservice-polychat + +matrix_appservice_polychat_container_image_self_build: false +matrix_appservice_polychat_container_image_self_build_repo: "https://github.com/polychatproject/polychat-appservice.git" +matrix_appservice_polychat_container_image_self_build_repo_version: "{{ 'master' if matrix_appservice_polychat_version == 'latest' else matrix_appservice_polychat_version }}" +matrix_appservice_polychat_container_image_self_build_repo_dockerfile_path: "Dockerfile" + +matrix_appservice_polychat_version: v1.0.3-01 +matrix_appservice_polychat_docker_image: "{{ matrix_appservice_polychat_docker_image_name_prefix }}polychatproject/polychat-appservice:{{ matrix_appservice_polychat_version }}" +matrix_appservice_polychat_docker_image_name_prefix: "{{ 'localhost/' if matrix_appservice_polychat_container_image_self_build else matrix_container_global_registry_prefix }}" +matrix_appservice_polychat_docker_image_force_pull: "{{ matrix_appservice_polychat_docker_image.endswith(':latest') }}" + +matrix_appservice_polychat_base_path: "{{ matrix_base_data_path }}/appservice-polychat" +matrix_appservice_polychat_config_path: "{{ matrix_appservice_polychat_base_path }}/config" +matrix_appservice_polychat_data_path: "{{ matrix_appservice_polychat_base_path }}/data" +matrix_appservice_polychat_docker_src_files_path: "{{ matrix_appservice_polychat_base_path }}/docker-src" + +# If nginx-proxy is disabled, the bridge itself expects its endpoint to be on its own domain (e.g. "localhost:6789") +matrix_appservice_polychat_public_endpoint: "{{ matrix_appservice_polychat_path_prefix }}" +matrix_appservice_polychat_inbound_uri_prefix: "{{ matrix_appservice_polychat_scheme }}://{{ matrix_appservice_polychat_hostname }}{{ matrix_appservice_polychat_public_endpoint }}" + +matrix_appservice_polychat_bot_name: 'webhookbot' +matrix_appservice_polychat_user_prefix: '_webhook_' + +# Controls the polychat_PORT and MATRIX_PORT of the installation +matrix_appservice_polychat_matrix_port: 6789 + +# Controls whether the appservice-polychat container exposes its HTTP port (tcp/6789 in the container). +# +# Takes an ":" or "" value (e.g. "127.0.0.1:9999"), or empty string to not expose. +matrix_appservice_polychat_container_http_host_bind_port: '' + +matrix_appservice_polychat_container_network: "" + +matrix_appservice_polychat_container_additional_networks: "{{ matrix_appservice_polychat_container_additional_networks_auto + matrix_appservice_polychat_container_additional_networks_custom }}" +matrix_appservice_polychat_container_additional_networks_auto: [] +matrix_appservice_polychat_container_additional_networks_custom: [] + +# matrix_appservice_polychat_container_labels_traefik_enabled controls whether labels to assist a Traefik reverse-proxy will be attached to the container. +# See `../templates/labels.j2` for details. +# +# To inject your own other container labels, see `matrix_appservice_polychat_container_labels_additional_labels`. +matrix_appservice_polychat_container_labels_traefik_enabled: true +matrix_appservice_polychat_container_labels_traefik_docker_network: "{{ matrix_appservice_polychat_container_network }}" +matrix_appservice_polychat_container_labels_traefik_entrypoints: web-secure +matrix_appservice_polychat_container_labels_traefik_tls_certResolver: default # noqa var-naming + +# Controls whether labels will be added that expose matrix-appservice-webhook's public endpoints +matrix_appservice_polychat_container_labels_public_endpoint_enabled: true +matrix_appservice_polychat_container_labels_public_endpoint_hostname: "{{ matrix_appservice_polychat_hostname }}" +matrix_appservice_polychat_container_labels_public_endpoint_prefix: "{{ matrix_appservice_polychat_path_prefix }}" +matrix_appservice_polychat_container_labels_public_endpoint_traefik_rule: "Host(`{{ matrix_appservice_polychat_container_labels_public_endpoint_hostname }}`) && PathPrefix(`{{ matrix_appservice_polychat_path_prefix }}`)" +matrix_appservice_polychat_container_labels_public_endpoint_traefik_priority: 0 +matrix_appservice_polychat_container_labels_public_endpoint_traefik_entrypoints: "{{ matrix_appservice_polychat_container_labels_traefik_entrypoints }}" +matrix_appservice_polychat_container_labels_public_endpoint_traefik_tls: "{{ matrix_appservice_polychat_container_labels_public_endpoint_traefik_entrypoints != 'web' }}" +matrix_appservice_polychat_container_labels_public_endpoint_traefik_tls_certResolver: "{{ matrix_appservice_polychat_container_labels_traefik_tls_certResolver }}" # noqa var-naming + +# matrix_appservice_polychat_container_labels_additional_labels contains a multiline string with additional labels to add to the container label file. +# See `../templates/labels.j2` for details. +# +# Example: +# matrix_appservice_polychat_container_labels_additional_labels: | +# my.label=1 +# another.label="here" +matrix_appservice_polychat_container_labels_additional_labels: '' + +# A list of extra arguments to pass to the container +matrix_appservice_polychat_container_extra_arguments: [] + +# List of systemd services that matrix-appservice-polychat.service depends on. +matrix_appservice_polychat_systemd_required_services_list: "{{ matrix_appservice_polychat_systemd_required_services_list_default + matrix_appservice_polychat_systemd_required_services_list_auto + matrix_appservice_polychat_systemd_required_services_list_custom }}" +matrix_appservice_polychat_systemd_required_services_list_default: ['docker.service'] +matrix_appservice_polychat_systemd_required_services_list_auto: [] +matrix_appservice_polychat_systemd_required_services_list_custom: [] + +# List of systemd services that matrix-appservice-polychat.service wants +matrix_appservice_polychat_systemd_wanted_services_list: [] + +matrix_appservice_polychat_homeserver_media_url: "{{ matrix_server_fqn_matrix }}" +matrix_appservice_polychat_homeserver_url: "" +matrix_appservice_polychat_homeserver_domain: "{{ matrix_domain }}" +matrix_appservice_polychat_appservice_url: 'http://matrix-appservice-polychat' + +matrix_appservice_polychat_appservice_token: '' +matrix_appservice_polychat_homeserver_token: '' +matrix_appservice_polychat_id_token: '' +matrix_appservice_polychat_api_secret: '' + +# Logging information (info and verbose is available) default is: info +matrix_appservice_polychat_log_level: 'info' + +matrix_appservice_polychat_configuration_yaml: "{{ lookup('template', 'templates/config.yaml.j2') }}" + +matrix_appservice_polychat_configuration_extension_yaml: | + # + +matrix_appservice_polychat_configuration_extension: "{{ matrix_appservice_polychat_configuration_extension_yaml | from_yaml if matrix_appservice_polychat_configuration_extension_yaml | from_yaml else {} }}" + +matrix_appservice_polychat_configuration: "{{ matrix_appservice_polychat_configuration_yaml | from_yaml | combine(matrix_appservice_polychat_configuration_extension, recursive=True) }}" + +matrix_appservice_polychat_registration_yaml: | + id: "{{ matrix_appservice_polychat_id_token }}" + hs_token: "{{ matrix_appservice_polychat_homeserver_token }}" + as_token: "{{ matrix_appservice_polychat_appservice_token }}" + namespaces: + users: + - exclusive: true + regex: '^@{{ matrix_appservice_polychat_user_prefix | regex_escape }}.*:{{ matrix_domain | regex_escape }}$' + aliases: [] + rooms: [] + url: "{{ matrix_appservice_polychat_appservice_url }}:{{ matrix_appservice_polychat_matrix_port }}" + sender_localpart: _webhook + rate_limited: false + protocols: null + +matrix_appservice_polychat_registration: "{{ matrix_appservice_polychat_registration_yaml | from_yaml }}" diff --git a/roles/custom/matrix-bridge-appservice-polychat/tasks/main.yml b/roles/custom/matrix-bridge-appservice-polychat/tasks/main.yml new file mode 100644 index 000000000..f2ba6d06e --- /dev/null +++ b/roles/custom/matrix-bridge-appservice-polychat/tasks/main.yml @@ -0,0 +1,20 @@ +--- + +- tags: + - setup-all + - setup-appservice-polychats + - install-all + - install-appservice-polychat + block: + - when: matrix_appservice_polychat_enabled | bool + ansible.builtin.include_tasks: "{{ role_path }}/tasks/validate_config.yml" + + - when: matrix_appservice_polychat_enabled | bool + ansible.builtin.include_tasks: "{{ role_path }}/tasks/setup_install.yml" + +- tags: + - setup-all + - setup-appservice-polychat + block: + - when: not matrix_appservice_polychat_enabled | bool + ansible.builtin.include_tasks: "{{ role_path }}/tasks/setup_uninstall.yml" diff --git a/roles/custom/matrix-bridge-appservice-polychat/tasks/setup_install.yml b/roles/custom/matrix-bridge-appservice-polychat/tasks/setup_install.yml new file mode 100644 index 000000000..3805cfdfe --- /dev/null +++ b/roles/custom/matrix-bridge-appservice-polychat/tasks/setup_install.yml @@ -0,0 +1,103 @@ +--- + +- name: Ensure matrix-appservice-polychat paths exist + ansible.builtin.file: + path: "{{ item.path }}" + state: directory + mode: 0750 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + with_items: + - {path: "{{ matrix_appservice_polychat_base_path }}", when: true} + - {path: "{{ matrix_appservice_polychat_config_path }}", when: true} + - {path: "{{ matrix_appservice_polychat_data_path }}", when: true} + - {path: "{{ matrix_appservice_polychat_docker_src_files_path }}", when: "{{ matrix_appservice_polychat_container_image_self_build }}"} + when: "item.when | bool" + +- name: Ensure matrix-appservice-polychat container image is pulled + community.docker.docker_image: + name: "{{ matrix_appservice_polychat_docker_image }}" + source: "{{ 'pull' if ansible_version.major > 2 or ansible_version.minor > 7 else omit }}" + force_source: "{{ matrix_appservice_polychat_docker_image_force_pull if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}" + force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_appservice_polychat_docker_image_force_pull }}" + when: "not matrix_appservice_polychat_container_image_self_build | bool" + register: result + retries: "{{ devture_playbook_help_container_retries_count }}" + delay: "{{ devture_playbook_help_container_retries_delay }}" + until: result is not failed + +- when: "matrix_appservice_polychat_container_image_self_build | bool" + block: + - name: Ensure matrix-appservice-polychat repository is present on self-build + ansible.builtin.git: + repo: "{{ matrix_appservice_polychat_container_image_self_build_repo }}" + dest: "{{ matrix_appservice_polychat_docker_src_files_path }}" + version: "{{ matrix_appservice_polychat_container_image_self_build_repo_version }}" + force: "yes" + become: true + become_user: "{{ matrix_user_username }}" + register: matrix_appservice_polychat_git_pull_results + + - name: Ensure matrix-appservice-polychat container image is built + community.docker.docker_image: + name: "{{ matrix_appservice_polychat_docker_image }}" + source: build + force_source: "{{ matrix_appservice_polychat_git_pull_results.changed if ansible_version.major > 2 or ansible_version.minor >= 8 else omit }}" + force: "{{ omit if ansible_version.major > 2 or ansible_version.minor >= 8 else matrix_appservice_polychat_git_pull_results.changed }}" + build: + dockerfile: "{{ matrix_appservice_polychat_container_image_self_build_repo_dockerfile_path }}" + path: "{{ matrix_appservice_polychat_docker_src_files_path }}" + pull: true + +- name: Ensure matrix-appservice-polychat config is installed + ansible.builtin.copy: + content: "{{ matrix_appservice_polychat_configuration | to_nice_yaml(indent=2, width=999999) }}" + dest: "{{ matrix_appservice_polychat_config_path }}/config.yaml" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + +- name: Ensure matrix-appservice-polychat schema.yml template exists + ansible.builtin.template: + src: "{{ role_path }}/templates/schema.yml.j2" + dest: "{{ matrix_appservice_polychat_config_path }}/schema.yml" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + +- name: Ensure matrix-appservice-polychat database.json template exists + ansible.builtin.template: + src: "{{ role_path }}/templates/database.json.j2" + dest: "{{ matrix_appservice_polychat_data_path }}/database.json" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + +- name: Ensure appservice-polychat registration.yaml installed + ansible.builtin.copy: + content: "{{ matrix_appservice_polychat_registration | to_nice_yaml(indent=2, width=999999) }}" + dest: "{{ matrix_appservice_polychat_config_path }}/polychat-registration.yaml" + mode: 0644 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + +- name: Ensure matrix-appservice-polychat container network is created + community.general.docker_network: + name: "{{ matrix_appservice_polychat_container_network }}" + driver: bridge + +- name: Ensure matrix-appservice-polychat support files installed + ansible.builtin.template: + src: "{{ role_path }}/templates/{{ item }}.j2" + dest: "{{ matrix_appservice_polychat_base_path }}/{{ item }}" + mode: 0640 + owner: "{{ matrix_user_username }}" + group: "{{ matrix_user_groupname }}" + with_items: + - labels + +- name: Ensure matrix-appservice-polychat.service installed + ansible.builtin.template: + src: "{{ role_path }}/templates/systemd/matrix-appservice-polychat.service.j2" + dest: "{{ devture_systemd_docker_base_systemd_path }}/matrix-appservice-polychat.service" + mode: 0644 diff --git a/roles/custom/matrix-bridge-appservice-polychat/tasks/setup_uninstall.yml b/roles/custom/matrix-bridge-appservice-polychat/tasks/setup_uninstall.yml new file mode 100644 index 000000000..774ee7fc5 --- /dev/null +++ b/roles/custom/matrix-bridge-appservice-polychat/tasks/setup_uninstall.yml @@ -0,0 +1,20 @@ +--- + +- name: Check existence of matrix-appservice-polychat service + ansible.builtin.stat: + path: "{{ devture_systemd_docker_base_systemd_path }}/matrix-appservice-polychat.service" + register: matrix_appservice_polychat_service_stat + +- when: matrix_appservice_polychat_service_stat.stat.exists | bool + block: + - name: Ensure matrix-appservice-polychat is stopped + ansible.builtin.service: + name: matrix-appservice-polychat + state: stopped + enabled: false + daemon_reload: true + + - name: Ensure matrix-appservice-polychat.service doesn't exist + ansible.builtin.file: + path: "{{ devture_systemd_docker_base_systemd_path }}/matrix-appservice-polychat.service" + state: absent diff --git a/roles/custom/matrix-bridge-appservice-polychat/tasks/validate_config.yml b/roles/custom/matrix-bridge-appservice-polychat/tasks/validate_config.yml new file mode 100644 index 000000000..bae1aa527 --- /dev/null +++ b/roles/custom/matrix-bridge-appservice-polychat/tasks/validate_config.yml @@ -0,0 +1,16 @@ +--- + +- name: Fail if required matrix-appservice-polychat settings not defined + ansible.builtin.fail: + msg: >- + You need to define a required configuration setting (`{{ item }}`). + when: "vars[item] == ''" + with_items: + - matrix_appservice_polychat_appservice_token + - matrix_appservice_polychat_homeserver_url + - matrix_appservice_polychat_homeserver_token + - matrix_appservice_polychat_id_token + - matrix_appservice_polychat_api_secret + - matrix_appservice_polychat_container_network + - matrix_appservice_polychat_hostname + - matrix_appservice_polychat_path_prefix diff --git a/roles/custom/matrix-bridge-appservice-polychat/templates/config.yaml.j2 b/roles/custom/matrix-bridge-appservice-polychat/templates/config.yaml.j2 new file mode 100644 index 000000000..6843e0f79 --- /dev/null +++ b/roles/custom/matrix-bridge-appservice-polychat/templates/config.yaml.j2 @@ -0,0 +1,28 @@ +#jinja2: lstrip_blocks: True +# Configuration specific to the application service. All fields (unless otherwise marked) are required. +homeserver: + # The domain for the client-server API calls. + url: "{{ matrix_appservice_polychat_homeserver_url }}" + + # The domain part for user IDs on this home server. Usually, but not always, this is the same as the + # home server's URL. + domain: "{{ matrix_domain }}" + +# Configuration specific to the bridge. All fields (unless otherwise marked) are required. +webhookBot: + # The localpart to use for the bot. May require re-registering the application service. + localpart: "_webhook" + +# Provisioning API options +provisioning: + # Your secret for the API. Required for all provisioning API requests. + secret: '{{ matrix_appservice_polychat_api_secret }}' + +# Configuration related to the web portion of the bridge. Handles the inbound polychat +web: + hookUrlBase: "{{ matrix_appservice_polychat_inbound_uri_prefix }}" + +logging: + console: true + consoleLevel: {{ matrix_appservice_polychat_log_level }} + writeFiles: false diff --git a/roles/custom/matrix-bridge-appservice-polychat/templates/database.json.j2 b/roles/custom/matrix-bridge-appservice-polychat/templates/database.json.j2 new file mode 100644 index 000000000..e70f1d832 --- /dev/null +++ b/roles/custom/matrix-bridge-appservice-polychat/templates/database.json.j2 @@ -0,0 +1,13 @@ +{ + "defaultEnv": { + "ENV": "NODE_ENV" + }, + "development": { + "driver": "sqlite3", + "filename": "/data/development.db" + }, + "production": { + "driver": "sqlite3", + "filename": "/data/production.db" + } +} diff --git a/roles/custom/matrix-bridge-appservice-polychat/templates/labels.j2 b/roles/custom/matrix-bridge-appservice-polychat/templates/labels.j2 new file mode 100644 index 000000000..36317889c --- /dev/null +++ b/roles/custom/matrix-bridge-appservice-polychat/templates/labels.j2 @@ -0,0 +1,44 @@ +{% if matrix_appservice_polychat_container_labels_traefik_enabled %} +traefik.enable=true + +{% if matrix_appservice_polychat_container_labels_traefik_docker_network %} +traefik.docker.network={{ matrix_appservice_polychat_container_labels_traefik_docker_network }} +{% endif %} + +traefik.http.services.matrix-appservice-polychat.loadbalancer.server.port={{ matrix_appservice_polychat_matrix_port }} + +{% if matrix_appservice_polychat_container_labels_public_endpoint_enabled %} +############################################################ +# # +# Public # +# # +############################################################ + +traefik.http.middlewares.matrix-appservice-polychat-public-strip-prefix.stripprefix.prefixes={{ matrix_appservice_polychat_container_labels_public_endpoint_prefix }} + +traefik.http.routers.matrix-appservice-polychat-public.rule={{ matrix_appservice_polychat_container_labels_public_endpoint_traefik_rule }} +traefik.http.routers.matrix-appservice-polychat-public.middlewares=matrix-appservice-polychat-public-strip-prefix + +{% if matrix_appservice_polychat_container_labels_public_endpoint_traefik_priority | int > 0 %} +traefik.http.routers.matrix-appservice-polychat-public.priority={{ matrix_appservice_polychat_container_labels_public_endpoint_traefik_priority }} +{% endif %} + +traefik.http.routers.matrix-appservice-polychat-public.service=matrix-appservice-polychat +traefik.http.routers.matrix-appservice-polychat-public.entrypoints={{ matrix_appservice_polychat_container_labels_public_endpoint_traefik_entrypoints }} + +traefik.http.routers.matrix-appservice-polychat-public.tls={{ matrix_appservice_polychat_container_labels_public_endpoint_traefik_tls | to_json }} +{% if matrix_appservice_polychat_container_labels_public_endpoint_traefik_tls %} +traefik.http.routers.matrix-appservice-polychat-public.tls.certResolver={{ matrix_appservice_polychat_container_labels_public_endpoint_traefik_tls_certResolver }} +{% endif %} + +############################################################ +# # +# /Public # +# # +############################################################ +{% endif %} + + +{% endif %} + +{{ matrix_appservice_polychat_container_labels_additional_labels }} diff --git a/roles/custom/matrix-bridge-appservice-polychat/templates/schema.yml.j2 b/roles/custom/matrix-bridge-appservice-polychat/templates/schema.yml.j2 new file mode 100644 index 000000000..e999555de --- /dev/null +++ b/roles/custom/matrix-bridge-appservice-polychat/templates/schema.yml.j2 @@ -0,0 +1,54 @@ +"$schema": "http://json-schema.org/draft-04/schema#" +type: "object" +properties: + provisioning: + type: "object" + properties: + secret: + type: "string" + homeserver: + type: "object" + properties: + domain: + type: "string" + url: + type: "string" + mediaUrl: + type: "string" + web: + type: "object" + properties: + hookUrlBase: + type: "string" + webhookBot: + type: "object" + properties: + localpart: + type: "string" + appearance: + type: "object" + properties: + displayName: + type: "string" + avatarUrl: + type: "string" + logging: + type: "object" + properties: + file: + type: "string" + console: + type: "boolean" + consoleLevel: + type: "string" + fileLevel: + type: "string" + writeFiles: + type: "boolean" + rotate: + type: "object" + properties: + size: + type: "number" + count: + type: "number" diff --git a/roles/custom/matrix-bridge-appservice-polychat/templates/systemd/matrix-appservice-webhooks.service.j2 b/roles/custom/matrix-bridge-appservice-polychat/templates/systemd/matrix-appservice-webhooks.service.j2 new file mode 100644 index 000000000..60dcdbb33 --- /dev/null +++ b/roles/custom/matrix-bridge-appservice-polychat/templates/systemd/matrix-appservice-webhooks.service.j2 @@ -0,0 +1,51 @@ +#jinja2: lstrip_blocks: "True" +[Unit] +Description=Matrix Appservice polychat bridge +{% for service in matrix_appservice_polychat_systemd_required_services_list %} +Requires={{ service }} +After={{ service }} +{% endfor %} +{% for service in matrix_appservice_polychat_systemd_wanted_services_list %} +Wants={{ service }} +{% endfor %} +DefaultDependencies=no + +[Service] +Type=simple +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-appservice-polychat 2>/dev/null || true' +ExecStartPre=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-appservice-polychat 2>/dev/null || true' + +ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ + --rm \ + --name=matrix-appservice-polychat \ + --log-driver=none \ + --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ + --cap-drop=ALL \ + --network={{ matrix_appservice_polychat_container_network }} \ + {% if matrix_appservice_polychat_container_http_host_bind_port %} + -p {{ matrix_appservice_polychat_container_http_host_bind_port }}:{{matrix_appservice_polychat_matrix_port}} \ + {% endif %} + --mount type=bind,src={{ matrix_appservice_polychat_config_path }},dst=/config \ + --mount type=bind,src={{ matrix_appservice_polychat_data_path }},dst=/data \ + --label-file={{ matrix_appservice_polychat_base_path }}/labels \ + {% for arg in matrix_appservice_polychat_container_extra_arguments %} + {{ arg }} \ + {% endfor %} + {{ matrix_appservice_polychat_docker_image }} \ + node index.js -p {{ matrix_appservice_polychat_matrix_port }} -c /config/config.yaml -f /config/polychat-registration.yaml + +{% for network in matrix_appservice_polychat_container_additional_networks %} +ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} network connect {{ network }} matrix-appservice-polychat +{% endfor %} + +ExecStart={{ devture_systemd_docker_base_host_command_docker }} start --attach matrix-appservice-polychat + +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-appservice-polychat 2>/dev/null || true' +ExecStop=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-appservice-polychat 2>/dev/null || true' +Restart=always +RestartSec=30 +SyslogIdentifier=matrix-appservice-polychat + +[Install] +WantedBy=multi-user.target diff --git a/setup.yml b/setup.yml index ea5070aa6..9b80d2a36 100644 --- a/setup.yml +++ b/setup.yml @@ -117,6 +117,7 @@ - custom/matrix-static-files - custom/matrix-coturn - custom/matrix-media-repo + - custom/matrix-bridge-appservice-polychat - role: galaxy/auxiliary