Slavi Pantaleev 248463b58b Add Traefik labels to expose /.well-known/element on the matrix. domain
Some Element Call setup resources say that `/.well-known/element/element.json` should be served on the base domain
and should contain content like this:

```json
{
	"call": {
		"widget_url": "https://call.element.example.com"
	}
}
```

We were already generating the file via `matrix-static-files`, but weren't serving it yet.

This patch makes sure it's served on the `matrix.` domain, which allows
people to set up serving on the base domain via a redirect or reverse-proxying.

Related to https://github.com/spantaleev/matrix-docker-ansible-deploy/pull/3562
2025-03-17 07:51:04 +02:00

144 lines
8.6 KiB
Django/Jinja

{#
SPDX-FileCopyrightText: 2024 Slavi Pantaleev
SPDX-FileCopyrightText: 2024 Suguru Hirahara
SPDX-License-Identifier: AGPL-3.0-or-later
#}
{% if matrix_static_files_container_labels_traefik_enabled %}
traefik.enable=true
{% if matrix_static_files_container_labels_traefik_docker_network %}
traefik.docker.network={{ matrix_static_files_container_labels_traefik_docker_network }}
{% endif %}
traefik.http.services.{{ matrix_static_files_identifier }}.loadbalancer.server.port={{ matrix_static_files_environment_variable_server_port }}
{% if matrix_static_files_container_labels_well_known_matrix_endpoint_enabled %}
############################################################
# #
# Related to /.well-known/matrix on the Matrix domain #
# #
############################################################
{% set well_known_matrix_endpoint_middlewares = [] %}
{% if matrix_static_files_container_labels_well_known_matrix_endpoint_middleware_compress_enabled %}
traefik.http.middlewares.{{ matrix_static_files_identifier }}-well-known-matrix-compress.compress=true
traefik.http.middlewares.{{ matrix_static_files_identifier }}-well-known-matrix-compress.compress.minResponseBodyBytes={{ matrix_static_files_container_labels_well_known_matrix_endpoint_middleware_compress_minResponseBodyBytes }}
{% set well_known_matrix_endpoint_middlewares = well_known_matrix_endpoint_middlewares + [matrix_static_files_identifier + '-well-known-matrix-compress'] %}
{% endif %}
traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-matrix.rule={{ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_rule }}
{% if well_known_matrix_endpoint_middlewares | length > 0 %}
traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-matrix.middlewares={{ well_known_matrix_endpoint_middlewares | join(',') }}
{% endif %}
{% if matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_priority | int > 0 %}
traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-matrix.priority={{ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_priority }}
{% endif %}
traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-matrix.service={{ matrix_static_files_identifier }}
traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-matrix.entrypoints={{ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_entrypoints }}
traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-matrix.tls={{ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_tls | to_json }}
{% if matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_tls %}
traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-matrix.tls.certResolver={{ matrix_static_files_container_labels_well_known_matrix_endpoint_traefik_tls_certResolver }}
{% endif %}
############################################################
# #
# /Related to /.well-known/matrix on the Matrix domain #
# #
############################################################
{% endif %}
{% if matrix_static_files_container_labels_well_known_element_endpoint_enabled %}
############################################################
# #
# Related to /.well-known/element on the Matrix domain #
# #
############################################################
{% set well_known_element_endpoint_middlewares = [] %}
{% if matrix_static_files_container_labels_well_known_element_endpoint_middleware_compress_enabled %}
traefik.http.middlewares.{{ matrix_static_files_identifier }}-well-known-element-compress.compress=true
traefik.http.middlewares.{{ matrix_static_files_identifier }}-well-known-element-compress.compress.minResponseBodyBytes={{ matrix_static_files_container_labels_well_known_element_endpoint_middleware_compress_minResponseBodyBytes }}
{% set well_known_element_endpoint_middlewares = well_known_element_endpoint_middlewares + [matrix_static_files_identifier + '-well-known-element-compress'] %}
{% endif %}
traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-element.rule={{ matrix_static_files_container_labels_well_known_element_endpoint_traefik_rule }}
{% if well_known_element_endpoint_middlewares | length > 0 %}
traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-element.middlewares={{ well_known_element_endpoint_middlewares | join(',') }}
{% endif %}
{% if matrix_static_files_container_labels_well_known_element_endpoint_traefik_priority | int > 0 %}
traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-element.priority={{ matrix_static_files_container_labels_well_known_element_endpoint_traefik_priority }}
{% endif %}
traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-element.service={{ matrix_static_files_identifier }}
traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-element.entrypoints={{ matrix_static_files_container_labels_well_known_element_endpoint_traefik_entrypoints }}
traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-element.tls={{ matrix_static_files_container_labels_well_known_element_endpoint_traefik_tls | to_json }}
{% if matrix_static_files_container_labels_well_known_element_endpoint_traefik_tls %}
traefik.http.routers.{{ matrix_static_files_identifier }}-well-known-element.tls.certResolver={{ matrix_static_files_container_labels_well_known_element_endpoint_traefik_tls_certResolver }}
{% endif %}
############################################################
# #
# /Related to /.well-known/element on the Matrix domain #
# #
############################################################
{% endif %}
{% if matrix_static_files_container_labels_base_domain_enabled %}
############################################################
# #
# Base domain serving #
# #
############################################################
{% set middlewares = [] %}
{% if matrix_static_files_container_labels_base_domain_root_path_redirection_enabled %}
traefik.http.middlewares.{{ matrix_static_files_identifier }}-base-domain-root-path-redirect.redirectregex.regex={{ matrix_static_files_container_labels_base_domain_root_path_redirection_regex }}
traefik.http.middlewares.{{ matrix_static_files_identifier }}-base-domain-root-path-redirect.redirectregex.replacement={{ matrix_static_files_container_labels_base_domain_root_path_redirection_url }}
{% set middlewares = middlewares + [matrix_static_files_identifier + '-base-domain-root-path-redirect'] %}
{% endif %}
traefik.http.routers.{{ matrix_static_files_identifier }}-base-domain.rule={{ matrix_static_files_container_labels_base_domain_traefik_rule }}
{% if matrix_static_files_container_labels_base_domain_traefik_priority | int > 0 %}
traefik.http.routers.{{ matrix_static_files_identifier }}-base-domain.priority={{ matrix_static_files_container_labels_base_domain_traefik_priority }}
{% endif %}
{% if middlewares | length > 0 %}
traefik.http.routers.{{ matrix_static_files_identifier }}-base-domain.middlewares={{ middlewares | join(',') }}
{% endif %}
traefik.http.routers.{{ matrix_static_files_identifier }}-base-domain.service={{ matrix_static_files_identifier }}
traefik.http.routers.{{ matrix_static_files_identifier }}-base-domain.entrypoints={{ matrix_static_files_container_labels_base_domain_traefik_entrypoints }}
traefik.http.routers.{{ matrix_static_files_identifier }}-base-domain.tls={{ matrix_static_files_container_labels_base_domain_traefik_tls | to_json }}
{% if matrix_static_files_container_labels_base_domain_traefik_tls %}
traefik.http.routers.{{ matrix_static_files_identifier }}-base-domain.tls.certResolver={{ matrix_static_files_container_labels_base_domain_traefik_tls_certResolver }}
{% endif %}
############################################################
# #
# /Base domain serving #
# #
############################################################
{% endif %}
{% endif %}
{{ matrix_static_files_container_labels_additional_labels }}