Move matrix-bridge-mx-puppet-discord to its own container network

This commit is contained in:
Slavi Pantaleev 2024-01-08 17:03:48 +02:00
parent 5764c2cc67
commit 6d0ecb0269
5 changed files with 43 additions and 13 deletions

View File

@ -1856,17 +1856,24 @@ matrix_mx_puppet_instagram_database_password: "{{ '%s' | format(matrix_homeserve
# We don't enable bridges by default.
matrix_mx_puppet_discord_enabled: false
matrix_mx_puppet_discord_systemd_required_services_list_auto: |
{{
matrix_addons_homeserver_systemd_services_list
+
([devture_postgres_identifier ~ '.service'] if (devture_postgres_enabled and matrix_mx_puppet_discord_database_hostname == devture_postgres_connection_hostname) else [])
}}
matrix_mx_puppet_discord_container_image_self_build: "{{ matrix_architecture != 'amd64' }}"
matrix_mx_puppet_discord_systemd_required_services_list: |
matrix_mx_puppet_discord_container_network: "{{ matrix_addons_container_network }}"
matrix_mx_puppet_discord_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_discord_database_hostname == devture_postgres_connection_hostname and matrix_mx_puppet_discord_container_network != devture_postgres_container_network) else [])
) | unique
}}
matrix_mx_puppet_discord_appservice_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'mxdsc.as.tok', rounds=655555) | to_uuid }}"

View File

@ -44,11 +44,20 @@ matrix_mx_puppet_discord_provisioning_whitelist:
# "@.*:yourserver.com" disallow users on a specific homeserver
matrix_mx_puppet_discord_provisioning_blacklist: []
matrix_mx_puppet_discord_container_network: ""
matrix_mx_puppet_discord_container_additional_networks: "{{ matrix_mx_puppet_discord_container_additional_networks_auto + matrix_mx_puppet_discord_container_additional_networks_custom }}"
matrix_mx_puppet_discord_container_additional_networks_auto: []
matrix_mx_puppet_discord_container_additional_networks_custom: []
# A list of extra arguments to pass to the container
matrix_mx_puppet_discord_container_extra_arguments: []
# List of systemd services that matrix-puppet-discord.service depends on.
matrix_mx_puppet_discord_systemd_required_services_list: ['docker.service']
matrix_mx_puppet_discord_systemd_required_services_list: "{{ matrix_mx_puppet_discord_systemd_required_services_list_default + matrix_mx_puppet_discord_systemd_required_services_list_auto + matrix_mx_puppet_discord_systemd_required_services_list_custom }}"
matrix_mx_puppet_discord_systemd_required_services_list_default: ['docker.service']
matrix_mx_puppet_discord_systemd_required_services_list_auto: []
matrix_mx_puppet_discord_systemd_required_services_list_custom: []
# List of systemd services that matrix-puppet-discord.service wants
matrix_mx_puppet_discord_systemd_wanted_services_list: []

View File

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

View File

@ -10,3 +10,4 @@
- {'name': 'matrix_mx_puppet_discord_homeserver_address', when: true}
- {'name': 'matrix_mx_puppet_discord_homeserver_token', when: true}
- {'name': 'matrix_mx_puppet_discord_database_hostname', when: "{{ matrix_mx_puppet_discord_database_engine == 'postgres' }}"}
- {'name': 'matrix_mx_puppet_discord_container_network', when: true}

View File

@ -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 }} 15
ExecStart={{ devture_systemd_docker_base_host_command_docker }} run --rm --name matrix-mx-puppet-discord \
ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \
--rm \
--name=matrix-mx-puppet-discord \
--log-driver=none \
--user={{ matrix_user_uid }}:{{ matrix_user_gid }} \
--cap-drop=ALL \
--network={{ matrix_docker_network }} \
--network={{ matrix_mx_puppet_discord_container_network }} \
-e CONFIG_PATH=/config/config.yaml \
-e REGISTRATION_PATH=/config/registration.yaml \
-v {{ matrix_mx_puppet_discord_config_path }}:/config:z \
-v {{ matrix_mx_puppet_discord_data_path }}:/data:z \
--mount type=bind,src={{ matrix_mx_puppet_discord_config_path }},dst=/config \
--mount type=bind,src={{ matrix_mx_puppet_discord_data_path }},dst=/data \
{% for arg in matrix_mx_puppet_discord_container_extra_arguments %}
{{ arg }} \
{% endfor %}
{{ matrix_mx_puppet_discord_docker_image }}
{% for network in matrix_mx_puppet_discord_container_additional_networks %}
ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} network connect {{ network }} matrix-mx-puppet-discord
{% endfor %}
ExecStart={{ devture_systemd_docker_base_host_command_docker }} start --attach matrix-mx-puppet-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-mx-puppet-discord 2>/dev/null || true'
ExecStop=-{{ devture_systemd_docker_base_host_command_sh }} -c '{{ devture_systemd_docker_base_host_command_docker }} rm matrix-mx-puppet-discord 2>/dev/null || true'
Restart=always