From 1e19fee772010b160b741f34204e2b5249eaee28 Mon Sep 17 00:00:00 2001 From: Slavi Pantaleev Date: Mon, 8 Jan 2024 17:45:19 +0200 Subject: [PATCH] Move matrix-bridge-mx-puppet-steam to its own container network --- group_vars/matrix_servers | 25 +++++++++++++------ .../defaults/main.yml | 14 ++++++++++- .../tasks/setup_install.yml | 5 ++++ .../tasks/validate_config.yml | 1 + .../templates/config.yaml.j2 | 4 +-- .../systemd/matrix-mx-puppet-steam.service.j2 | 16 +++++++++--- 6 files changed, 50 insertions(+), 15 deletions(-) diff --git a/group_vars/matrix_servers b/group_vars/matrix_servers index abea74997..a93656c39 100755 --- a/group_vars/matrix_servers +++ b/group_vars/matrix_servers @@ -1932,17 +1932,24 @@ matrix_mx_puppet_discord_database_password: "{{ '%s' | format(matrix_homeserver_ # We don't enable bridges by default. matrix_mx_puppet_steam_enabled: false +matrix_mx_puppet_steam_systemd_required_services_list_auto: | + {{ + matrix_addons_homeserver_systemd_services_list + + + ([devture_postgres_identifier ~ '.service'] if (devture_postgres_enabled and matrix_mx_puppet_steam_database_hostname == devture_postgres_connection_hostname) else []) + }} + matrix_mx_puppet_steam_container_image_self_build: "{{ matrix_architecture not in ['arm64', 'amd64'] }}" -matrix_mx_puppet_steam_systemd_required_services_list: | +matrix_mx_puppet_steam_container_network: "{{ matrix_addons_container_network }}" + +matrix_mx_puppet_steam_container_additional_networks_auto: |- {{ - ['docker.service'] - + - ['matrix-' + matrix_homeserver_implementation + '.service'] - + - ([devture_postgres_identifier ~ '.service'] if devture_postgres_enabled else []) - + - (['matrix-nginx-proxy.service'] if matrix_nginx_proxy_enabled else []) + ( + ([] if matrix_addons_homeserver_container_network == '' else [matrix_addons_homeserver_container_network]) + + + ([devture_postgres_container_network] if (devture_postgres_enabled and matrix_mx_puppet_steam_database_hostname == devture_postgres_connection_hostname and matrix_mx_puppet_steam_container_network != devture_postgres_container_network) else []) + ) | unique }} matrix_mx_puppet_steam_appservice_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'mxste.as.tok', rounds=655555) | to_uuid }}" @@ -1952,6 +1959,8 @@ matrix_mx_puppet_steam_homeserver_token: "{{ '%s' | format(matrix_homeserver_gen matrix_mx_puppet_steam_login_shared_secret: "{{ matrix_synapse_ext_password_provider_shared_secret_auth_shared_secret if matrix_synapse_ext_password_provider_shared_secret_auth_enabled else '' }}" +matrix_mx_puppet_steam_presence_enabled: "{{ matrix_homeserver_implementation != 'synapse' or matrix_synapse_presence_enabled }}" + # Postgres is the default, except if not using internal Postgres server matrix_mx_puppet_steam_database_engine: "{{ 'postgres' if devture_postgres_enabled else 'sqlite' }}" matrix_mx_puppet_steam_database_hostname: "{{ devture_postgres_connection_hostname if devture_postgres_enabled else '' }}" diff --git a/roles/custom/matrix-bridge-mx-puppet-steam/defaults/main.yml b/roles/custom/matrix-bridge-mx-puppet-steam/defaults/main.yml index f31adf3af..f54e484a4 100644 --- a/roles/custom/matrix-bridge-mx-puppet-steam/defaults/main.yml +++ b/roles/custom/matrix-bridge-mx-puppet-steam/defaults/main.yml @@ -41,11 +41,20 @@ matrix_mx_puppet_steam_provisioning_whitelist: # "@.*:yourserver.com" disallow users on a specific homeserver matrix_mx_puppet_steam_provisioning_blacklist: [] +matrix_mx_puppet_steam_container_network: "" + +matrix_mx_puppet_steam_container_additional_networks: "{{ matrix_mx_puppet_steam_container_additional_networks_auto + matrix_mx_puppet_steam_container_additional_networks_custom }}" +matrix_mx_puppet_steam_container_additional_networks_auto: [] +matrix_mx_puppet_steam_container_additional_networks_custom: [] + # A list of extra arguments to pass to the container matrix_mx_puppet_steam_container_extra_arguments: [] # List of systemd services that matrix-puppet-steam.service depends on. -matrix_mx_puppet_steam_systemd_required_services_list: ['docker.service'] +matrix_mx_puppet_steam_systemd_required_services_list: "{{ matrix_mx_puppet_steam_systemd_required_services_list_default + matrix_mx_puppet_steam_systemd_required_services_list_auto + matrix_mx_puppet_steam_systemd_required_services_list_custom }}" +matrix_mx_puppet_steam_systemd_required_services_list_default: ['docker.service'] +matrix_mx_puppet_steam_systemd_required_services_list_auto: [] +matrix_mx_puppet_steam_systemd_required_services_list_custom: [] # List of systemd services that matrix-puppet-steam.service wants matrix_mx_puppet_steam_systemd_wanted_services_list: [] @@ -56,6 +65,9 @@ matrix_mx_puppet_steam_homeserver_token: '' # Can be set to enable automatic double-puppeting via Shared Secret Auth (https://github.com/devture/matrix-synapse-shared-secret-auth). matrix_mx_puppet_steam_login_shared_secret: '' +matrix_mx_puppet_steam_presence_enabled: true +matrix_mx_puppet_steam_presence_interval: 5000 + matrix_mx_puppet_steam_database_engine: sqlite matrix_mx_puppet_steam_sqlite_database_path_local: "{{ matrix_mx_puppet_steam_data_path }}/database.db" diff --git a/roles/custom/matrix-bridge-mx-puppet-steam/tasks/setup_install.yml b/roles/custom/matrix-bridge-mx-puppet-steam/tasks/setup_install.yml index f2ccea594..dc4f24bff 100644 --- a/roles/custom/matrix-bridge-mx-puppet-steam/tasks/setup_install.yml +++ b/roles/custom/matrix-bridge-mx-puppet-steam/tasks/setup_install.yml @@ -113,6 +113,11 @@ owner: "{{ matrix_user_username }}" group: "{{ matrix_user_groupname }}" +- name: Ensure mx-puppet-steam container network is created + community.general.docker_network: + name: "{{ matrix_mx_puppet_steam_container_network }}" + driver: bridge + - name: Ensure matrix-mx-puppet-steam.service installed ansible.builtin.template: src: "{{ role_path }}/templates/systemd/matrix-mx-puppet-steam.service.j2" diff --git a/roles/custom/matrix-bridge-mx-puppet-steam/tasks/validate_config.yml b/roles/custom/matrix-bridge-mx-puppet-steam/tasks/validate_config.yml index 4e847d929..7a09a8073 100644 --- a/roles/custom/matrix-bridge-mx-puppet-steam/tasks/validate_config.yml +++ b/roles/custom/matrix-bridge-mx-puppet-steam/tasks/validate_config.yml @@ -10,3 +10,4 @@ - {'name': 'matrix_mx_puppet_steam_homeserver_address', when: true} - {'name': 'matrix_mx_puppet_steam_homeserver_token', when: true} - {'name': 'matrix_mx_puppet_steam_database_hostname', when: "{{ matrix_mx_puppet_steam_database_engine == 'postgres' }}"} + - {'name': 'matrix_mx_puppet_steam_container_network', when: true} diff --git a/roles/custom/matrix-bridge-mx-puppet-steam/templates/config.yaml.j2 b/roles/custom/matrix-bridge-mx-puppet-steam/templates/config.yaml.j2 index 0919907dc..daf03916d 100644 --- a/roles/custom/matrix-bridge-mx-puppet-steam/templates/config.yaml.j2 +++ b/roles/custom/matrix-bridge-mx-puppet-steam/templates/config.yaml.j2 @@ -23,9 +23,9 @@ bridge: presence: # Bridge Steam online/offline status - enabled: true + enabled: {{ matrix_mx_puppet_steam_presence_enabled | to_json }} # How often to send status to the homeserver in milliseconds - interval: 5000 + interval: {{ matrix_mx_puppet_steam_presence_interval | to_json }} provisioning: # Regex of Matrix IDs allowed to use the puppet bridge diff --git a/roles/custom/matrix-bridge-mx-puppet-steam/templates/systemd/matrix-mx-puppet-steam.service.j2 b/roles/custom/matrix-bridge-mx-puppet-steam/templates/systemd/matrix-mx-puppet-steam.service.j2 index 0c7956785..2090b68e6 100644 --- a/roles/custom/matrix-bridge-mx-puppet-steam/templates/systemd/matrix-mx-puppet-steam.service.j2 +++ b/roles/custom/matrix-bridge-mx-puppet-steam/templates/systemd/matrix-mx-puppet-steam.service.j2 @@ -19,20 +19,28 @@ 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-mx-puppet-steam \ +ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \ + --rm \ + --name=matrix-mx-puppet-steam \ --log-driver=none \ --user={{ matrix_user_uid }}:{{ matrix_user_gid }} \ --cap-drop=ALL \ - --network={{ matrix_docker_network }} \ + --network={{ matrix_mx_puppet_steam_container_network }} \ -e CONFIG_PATH=/config/config.yaml \ -e REGISTRATION_PATH=/config/registration.yaml \ - -v {{ matrix_mx_puppet_steam_config_path }}:/config:z \ - -v {{ matrix_mx_puppet_steam_data_path }}:/data:z \ + --mount type=bind,src={{ matrix_mx_puppet_steam_config_path }},dst=/config \ + --mount type=bind,src={{ matrix_mx_puppet_steam_data_path }},dst=/data \ {% for arg in matrix_mx_puppet_steam_container_extra_arguments %} {{ arg }} \ {% endfor %} {{ matrix_mx_puppet_steam_docker_image }} +{% for network in matrix_mx_puppet_steam_container_additional_networks %} +ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} network connect {{ network }} matrix-mx-puppet-steam +{% endfor %} + +ExecStart={{ devture_systemd_docker_base_host_command_docker }} start --attach matrix-mx-puppet-steam + 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-mx-puppet-steam 2>/dev/null || true' ExecStop=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-mx-puppet-steam 2>/dev/null || true' Restart=always