Skip to content

Commit cea437c

Browse files
committed
Expose mautrix-discord's avatar proxy
Possibly fixes #3900 This patch hasn't been tested.
1 parent f1c238e commit cea437c

File tree

6 files changed

+118
-2
lines changed

6 files changed

+118
-2
lines changed

group_vars/matrix_servers

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,9 +1103,16 @@ matrix_mautrix_discord_container_additional_networks_auto: |-
11031103
([] if matrix_addons_homeserver_container_network == '' else [matrix_addons_homeserver_container_network])
11041104
+
11051105
([postgres_container_network] if postgres_enabled and matrix_mautrix_facebook_database_hostname == postgres_connection_hostname else [])
1106+
+
1107+
([matrix_playbook_reverse_proxyable_services_additional_network] if (matrix_playbook_reverse_proxyable_services_additional_network and matrix_mautrix_discord_container_labels_traefik_enabled) else [])
11061108
) | unique
11071109
}}
11081110

1111+
matrix_mautrix_discord_container_labels_traefik_enabled: "{{ matrix_playbook_reverse_proxy_type in ['playbook-managed-traefik', 'other-traefik-container'] }}"
1112+
matrix_mautrix_discord_container_labels_traefik_docker_network: "{{ matrix_playbook_reverse_proxyable_services_additional_network }}"
1113+
matrix_mautrix_discord_container_labels_traefik_entrypoints: "{{ traefik_entrypoint_primary }}"
1114+
matrix_mautrix_discord_container_labels_traefik_tls_certResolver: "{{ traefik_certResolver_primary }}"
1115+
11091116
matrix_mautrix_discord_systemd_required_services_list_auto: |
11101117
{{
11111118
matrix_addons_homeserver_systemd_services_list
@@ -1118,9 +1125,11 @@ matrix_mautrix_discord_appservice_token: "{{ '%s' | format(matrix_homeserver_gen
11181125
matrix_mautrix_discord_homeserver_address: "{{ matrix_addons_homeserver_client_api_url }}"
11191126
matrix_mautrix_discord_homeserver_token: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'maudisc.hs.tok', rounds=655555) | to_uuid }}"
11201127

1121-
matrix_mautrix_discord_bridge_public_address: "{{ 'https' if matrix_playbook_ssl_enabled else 'http' }}://{{ matrix_server_fqn_matrix }}"
11221128
matrix_mautrix_discord_bridge_avatar_proxy_key: "{{ '%s' | format(matrix_homeserver_generic_secret_key) | password_hash('sha512', 'maudisc.avatar', rounds=655555) | to_uuid }}"
11231129

1130+
matrix_mautrix_discord_hostname: "{{ matrix_server_fqn_matrix }}"
1131+
matrix_mautrix_discord_scheme: "{{ 'https' if matrix_playbook_ssl_enabled else 'http' }}"
1132+
11241133
matrix_mautrix_discord_bridge_login_shared_secret_map_auto: |-
11251134
{{
11261135
({

roles/custom/matrix-bridge-mautrix-discord/defaults/main.yml

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44

55
matrix_mautrix_discord_enabled: true
66

7+
matrix_mautrix_discord_hostname: ""
8+
matrix_mautrix_discord_path_prefix: /
9+
matrix_mautrix_discord_scheme: https
10+
711
matrix_mautrix_discord_container_image_self_build: false
812
matrix_mautrix_discord_container_image_self_build_repo: "https://mau.dev/mautrix/discord.git"
913
matrix_mautrix_discord_container_image_self_build_branch: "{{ 'main' if matrix_mautrix_discord_version == 'latest' else matrix_mautrix_discord_version }}"
@@ -30,7 +34,7 @@ matrix_mautrix_discord_bridge_command_prefix: "!discord"
3034
# Publicly accessible base URL that Discord can use to reach the bridge, used for avatars in relay mode.
3135
# If not set, avatars will not be bridged. Only the /mautrix-discord/avatar/{server}/{id}/{hash} endpoint is used on this address.
3236
# This should not have a trailing slash, the endpoint above will be appended to the provided address.
33-
matrix_mautrix_discord_bridge_public_address: ''
37+
matrix_mautrix_discord_bridge_public_address: "{{ (matrix_mautrix_discord_scheme + '://' + matrix_mautrix_discord_hostname + (matrix_mautrix_discord_path_prefix if matrix_mautrix_discord_path_prefix != '/' else '')) if matrix_mautrix_discord_hostname else '' }}"
3438

3539
# A random key used to sign the avatar URLs. The bridge will only accept requests with a valid signature.
3640
matrix_mautrix_discord_bridge_avatar_proxy_key: ''
@@ -60,6 +64,38 @@ matrix_mautrix_discord_container_additional_networks: "{{ matrix_mautrix_discord
6064
matrix_mautrix_discord_container_additional_networks_auto: []
6165
matrix_mautrix_discord_container_additional_networks_custom: []
6266

67+
# matrix_mautrix_discord_container_labels_traefik_enabled controls whether labels to assist a Traefik reverse-proxy will be attached to the container.
68+
# See `../templates/labels.j2` for details.
69+
#
70+
# To inject your own other container labels, see `matrix_mautrix_discord_container_labels_additional_labels`.
71+
matrix_mautrix_discord_container_labels_traefik_enabled: true
72+
matrix_mautrix_discord_container_labels_traefik_docker_network: "{{ matrix_mautrix_discord_container_network }}"
73+
matrix_mautrix_discord_container_labels_traefik_hostname: "{{ matrix_mautrix_discord_hostname }}"
74+
# The path prefix must either be `/` or not end with a slash (e.g. `/matrix-alertmanager-receiver`).
75+
matrix_mautrix_discord_container_labels_traefik_path_prefix: "{{ matrix_mautrix_discord_path_prefix }}"
76+
matrix_mautrix_discord_container_labels_traefik_entrypoints: web-secure
77+
matrix_mautrix_discord_container_labels_traefik_tls_certResolver: default # noqa var-naming
78+
79+
# Controls whether labels will be added that expose the bridge's avatar proxy (`/mautrix-discord/avatar/{server}/{id}/{hash}`).
80+
# See: matrix_mautrix_discord_bridge_public_address
81+
matrix_mautrix_discord_container_labels_avatar_proxy_enabled: "{{ matrix_mautrix_discord_bridge_public_address != '' }}"
82+
matrix_mautrix_discord_container_labels_avatar_proxy_hostname: "{{ matrix_mautrix_discord_container_labels_traefik_hostname }}"
83+
matrix_mautrix_discord_container_labels_avatar_proxy_path_prefix: "{{ matrix_mautrix_discord_container_labels_traefik_path_prefix if matrix_mautrix_discord_container_labels_traefik_path_prefix == '/' else (matrix_mautrix_discord_container_labels_traefik_path_prefix + '/') }}mautrix-discord/avatar"
84+
matrix_mautrix_discord_container_labels_avatar_proxy_traefik_rule: "Host(`{{ matrix_mautrix_discord_container_labels_traefik_hostname }}`) && PathPrefix(`{{ matrix_mautrix_discord_container_labels_avatar_proxy_path_prefix }}`)"
85+
matrix_mautrix_discord_container_labels_avatar_proxy_traefik_priority: 0
86+
matrix_mautrix_discord_container_labels_avatar_proxy_traefik_entrypoints: "{{ matrix_mautrix_discord_container_labels_traefik_entrypoints }}"
87+
matrix_mautrix_discord_container_labels_avatar_proxy_traefik_tls: "{{ matrix_mautrix_discord_container_labels_avatar_proxy_traefik_entrypoints != 'web' }}"
88+
matrix_mautrix_discord_container_labels_avatar_proxy_traefik_tls_certResolver: "{{ matrix_mautrix_discord_container_labels_traefik_tls_certResolver }}" # noqa var-naming
89+
90+
# matrix_mautrix_discord_container_labels_additional_labels contains a multiline string with additional labels to add to the container label file.
91+
# See `../templates/labels.j2` for details.
92+
#
93+
# Example:
94+
# matrix_mautrix_discord_container_labels_additional_labels: |
95+
# my.label=1
96+
# another.label="here"
97+
matrix_mautrix_discord_container_labels_additional_labels: ''
98+
6399
# A list of extra arguments to pass to the container
64100
matrix_mautrix_discord_container_extra_arguments: []
65101

roles/custom/matrix-bridge-mautrix-discord/tasks/setup_install.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@
9393
owner: "{{ matrix_user_username }}"
9494
group: "{{ matrix_user_groupname }}"
9595

96+
- name: Ensure mautrix-discord support files installed
97+
ansible.builtin.template:
98+
src: "{{ role_path }}/templates/{{ item }}.j2"
99+
dest: "{{ matrix_mautrix_discord_base_path }}/{{ item }}"
100+
mode: 0640
101+
owner: "{{ matrix_user_username }}"
102+
group: "{{ matrix_user_groupname }}"
103+
with_items:
104+
- labels
105+
96106
- name: Ensure mautrix-discord container network is created
97107
community.general.docker_network:
98108
enable_ipv6: "{{ devture_systemd_docker_base_ipv6_enabled }}"

roles/custom/matrix-bridge-mautrix-discord/tasks/validate_config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
- {'name': 'matrix_mautrix_discord_bridge_public_address', when: true}
1313
- {'name': 'matrix_mautrix_discord_container_network', when: true}
1414
- {'name': 'matrix_mautrix_discord_database_hostname', when: "{{ matrix_mautrix_discord_database_engine == 'postgres' }}"}
15+
- {'name': 'matrix_mautrix_discord_container_labels_avatar_proxy_hostname', when: "{{ matrix_mautrix_discord_container_labels_avatar_proxy_enabled }}"}
16+
- {'name': 'matrix_mautrix_discord_container_labels_avatar_proxy_path_prefix', when: "{{ matrix_mautrix_discord_container_labels_avatar_proxy_enabled }}"}
1517

1618
- name: (Deprecation) Catch and report renamed settings
1719
ansible.builtin.fail:
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
{% if matrix_mautrix_discord_container_labels_traefik_enabled %}
2+
traefik.enable=true
3+
4+
{% if matrix_mautrix_discord_container_labels_traefik_docker_network %}
5+
traefik.docker.network={{ matrix_mautrix_discord_container_labels_traefik_docker_network }}
6+
{% endif %}
7+
8+
traefik.http.services.matrix-mautrix-discord.loadbalancer.server.port=8080
9+
10+
{% if matrix_mautrix_discord_container_labels_avatar_proxy_enabled %}
11+
############################################################
12+
# #
13+
# Avatar proxy #
14+
# #
15+
############################################################
16+
17+
{% set middlewares = [] %}
18+
19+
{% if matrix_mautrix_discord_container_labels_traefik_path_prefix != '/' %}
20+
traefik.http.middlewares.matrix-mautrix-discord-slashless-redirect.redirectregex.regex=({{ matrix_mautrix_discord_container_labels_traefik_path_prefix | quote }})$
21+
traefik.http.middlewares.matrix-mautrix-discord-slashless-redirect.redirectregex.replacement=${1}/
22+
{% set middlewares = middlewares + ['matrix-mautrix-discord-slashless-redirect'] %}
23+
{% endif %}
24+
25+
{% if matrix_mautrix_discord_container_labels_traefik_path_prefix != '/' %}
26+
traefik.http.middlewares.matrix-mautrix-discord-strip-prefix.stripprefix.prefixes={{ matrix_mautrix_discord_container_labels_traefik_path_prefix }}
27+
{% set middlewares = middlewares + ['matrix-mautrix-discord-strip-prefix'] %}
28+
{% endif %}
29+
30+
traefik.http.routers.matrix-mautrix-discord-avatar-proxy.rule={{ matrix_mautrix_discord_container_labels_avatar_proxy_traefik_rule }}
31+
32+
{% if matrix_mautrix_discord_container_labels_avatar_proxy_traefik_priority | int > 0 %}
33+
traefik.http.routers.matrix-mautrix-discord-avatar-proxy.priority={{ matrix_mautrix_discord_container_labels_avatar_proxy_traefik_priority }}
34+
{% endif %}
35+
36+
{% if middlewares | length > 0 %}
37+
traefik.http.routers.matrix-mautrix-discord-avatar-proxy.middlewares={{ middlewares | join(',') }}
38+
{% endif %}
39+
40+
traefik.http.routers.matrix-mautrix-discord-avatar-proxy.service=matrix-mautrix-discord
41+
traefik.http.routers.matrix-mautrix-discord-avatar-proxy.entrypoints={{ matrix_mautrix_discord_container_labels_avatar_proxy_traefik_entrypoints }}
42+
43+
traefik.http.routers.matrix-mautrix-discord-avatar-proxy.tls={{ matrix_mautrix_discord_container_labels_avatar_proxy_traefik_tls | to_json }}
44+
{% if matrix_mautrix_discord_container_labels_avatar_proxy_traefik_tls %}
45+
traefik.http.routers.matrix-mautrix-discord-avatar-proxy.tls.certResolver={{ matrix_mautrix_discord_container_labels_avatar_proxy_traefik_tls_certResolver }}
46+
{% endif %}
47+
48+
############################################################
49+
# #
50+
# /Avatar proxy #
51+
# #
52+
############################################################
53+
{% endif %}
54+
55+
56+
{% endif %}
57+
58+
{{ matrix_mautrix_discord_container_labels_additional_labels }}

roles/custom/matrix-bridge-mautrix-discord/templates/systemd/matrix-mautrix-discord.service.j2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ ExecStartPre={{ devture_systemd_docker_base_host_command_docker }} create \
2323
--user={{ matrix_user_uid }}:{{ matrix_user_gid }} \
2424
--cap-drop=ALL \
2525
--network={{ matrix_mautrix_discord_container_network }} \
26+
--label-file={{ matrix_mautrix_discord_base_path }}/labels \
2627
--mount type=bind,src={{ matrix_mautrix_discord_config_path }},dst=/config,ro \
2728
--mount type=bind,src={{ matrix_mautrix_discord_data_path }},dst=/data \
2829
--workdir=/data \

0 commit comments

Comments
 (0)