Add support for running synapse-admin (on Traefik) at the root path

Previously, we had to run it at a subpath, like `/synapse-admin`.

We can now dedicate a whole domain and the `/` path to it, should we
wish to do so.
This commit is contained in:
Slavi Pantaleev 2023-02-14 08:42:50 +02:00
parent ff1338e003
commit 5ab5f28d14
3 changed files with 16 additions and 7 deletions

View File

@ -37,9 +37,9 @@ matrix_synapse_admin_container_extra_arguments: []
matrix_synapse_admin_container_labels_traefik_enabled: true matrix_synapse_admin_container_labels_traefik_enabled: true
matrix_synapse_admin_container_labels_traefik_docker_network: "{{ matrix_synapse_admin_container_network }}" matrix_synapse_admin_container_labels_traefik_docker_network: "{{ matrix_synapse_admin_container_network }}"
matrix_synapse_admin_container_labels_traefik_hostname: "{{ matrix_server_fqn_matrix }}" matrix_synapse_admin_container_labels_traefik_hostname: "{{ matrix_server_fqn_matrix }}"
# The path prefix must not end with a slash # The path prefix must either be `/` or not end with a slash (e.g. `/synapse-admin`).
matrix_synapse_admin_container_labels_traefik_path_prefix: /synapse-admin matrix_synapse_admin_container_labels_traefik_path_prefix: /synapse-admin
matrix_synapse_admin_container_labels_traefik_rule: "Host(`{{ matrix_synapse_admin_container_labels_traefik_hostname }}`) && PathPrefix(`{{ matrix_synapse_admin_container_labels_traefik_path_prefix | quote }}`)" matrix_synapse_admin_container_labels_traefik_rule: "Host(`{{ matrix_synapse_admin_container_labels_traefik_hostname }}`){% if matrix_synapse_admin_container_labels_traefik_path_prefix != '/' %} && PathPrefix(`{{ matrix_synapse_admin_container_labels_traefik_path_prefix | quote }}`){% endif %}"
matrix_synapse_admin_container_labels_traefik_entrypoints: web-secure matrix_synapse_admin_container_labels_traefik_entrypoints: web-secure
matrix_synapse_admin_container_labels_traefik_tls: "{{ matrix_synapse_admin_container_labels_traefik_entrypoints != 'web' }}" matrix_synapse_admin_container_labels_traefik_tls: "{{ matrix_synapse_admin_container_labels_traefik_entrypoints != 'web' }}"
matrix_synapse_admin_container_labels_traefik_tls_certResolver: default # noqa var-naming matrix_synapse_admin_container_labels_traefik_tls_certResolver: default # noqa var-naming

View File

@ -28,6 +28,5 @@
- name: Fail if matrix_synapse_admin_container_labels_traefik_path_prefix ends with a slash - name: Fail if matrix_synapse_admin_container_labels_traefik_path_prefix ends with a slash
ansible.builtin.fail: ansible.builtin.fail:
msg: >- msg: >-
matrix_synapse_admin_container_labels_traefik_path_prefix (`{{ matrix_synapse_admin_container_labels_traefik_path_prefix }}`) must not end with a slash. matrix_synapse_admin_container_labels_traefik_path_prefix (`{{ matrix_synapse_admin_container_labels_traefik_path_prefix }}`) must either be `/` or not end with a slash (e.g. `/synapse-admin`).
Example: `/synapse-admin`. when: "matrix_synapse_admin_container_labels_traefik_path_prefix != '/' and matrix_synapse_admin_container_labels_traefik_path_prefix[-1] == '/'"
when: "matrix_synapse_admin_container_labels_traefik_path_prefix[-1] == '/'"

View File

@ -5,13 +5,23 @@ traefik.enable=true
traefik.docker.network={{ matrix_synapse_admin_container_labels_traefik_docker_network }} traefik.docker.network={{ matrix_synapse_admin_container_labels_traefik_docker_network }}
{% endif %} {% endif %}
{% set middlewares = [] %}
{% if matrix_synapse_admin_container_labels_traefik_path_prefix != '/' %}
traefik.http.middlewares.matrix-synapse-admin-slashless-redirect.redirectregex.regex=({{ matrix_synapse_admin_container_labels_traefik_path_prefix | quote }})$ traefik.http.middlewares.matrix-synapse-admin-slashless-redirect.redirectregex.regex=({{ matrix_synapse_admin_container_labels_traefik_path_prefix | quote }})$
traefik.http.middlewares.matrix-synapse-admin-slashless-redirect.redirectregex.replacement=${1}/ traefik.http.middlewares.matrix-synapse-admin-slashless-redirect.redirectregex.replacement=${1}/
{% set middlewares = middlewares + ['matrix-synapse-admin-slashless-redirect'] %}
{% endif %}
traefik.http.middlewares.matrix-synapse-admin-replacepath.replacepath.path=/ {% if matrix_synapse_admin_container_labels_traefik_path_prefix != '/' %}
traefik.http.middlewares.matrix-synapse-admin-strip-prefix.stripprefix.prefixes={{ matrix_synapse_admin_container_labels_traefik_path_prefix }}
{% set middlewares = middlewares + ['matrix-synapse-admin-strip-prefix'] %}
{% endif %}
traefik.http.routers.matrix-synapse-admin.rule={{ matrix_synapse_admin_container_labels_traefik_rule }} traefik.http.routers.matrix-synapse-admin.rule={{ matrix_synapse_admin_container_labels_traefik_rule }}
traefik.http.routers.matrix-synapse-admin.middlewares=matrix-synapse-admin-slashless-redirect,matrix-synapse-admin-replacepath {% if middlewares | length > 0 %}
traefik.http.routers.matrix-synapse-admin.middlewares={{ middlewares | join(',') }}
{% endif %}
traefik.http.routers.matrix-synapse-admin.service=matrix-synapse-admin traefik.http.routers.matrix-synapse-admin.service=matrix-synapse-admin
traefik.http.routers.matrix-synapse-admin.entrypoints={{ matrix_synapse_admin_container_labels_traefik_entrypoints }} traefik.http.routers.matrix-synapse-admin.entrypoints={{ matrix_synapse_admin_container_labels_traefik_entrypoints }}
traefik.http.routers.matrix-synapse-admin.tls={{ matrix_synapse_admin_container_labels_traefik_tls | to_json }} traefik.http.routers.matrix-synapse-admin.tls={{ matrix_synapse_admin_container_labels_traefik_tls | to_json }}