Skip to content

Commit 0954fb9

Browse files
committed
Fix traefik labels
- Add stripprefix middleware (mother-of-all-self-hosting/mash-playbook#145) - Add slashless-redirect middleware - Move all traefik labels inside the traefik_enabled if condition
1 parent 1075b89 commit 0954fb9

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

templates/labels.j2

+17-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,23 @@
11
{% if changedetection_container_labels_traefik_enabled %}
2+
traefik.enable=true
3+
24
{% if changedetection_container_labels_traefik_docker_network %}
35
traefik.docker.network={{ changedetection_container_labels_traefik_docker_network }}
46
{% endif %}
57

68
{% set middlewares = [] %}
79

10+
{% if changedetection_container_labels_traefik_path_prefix != '/' %}
11+
traefik.http.middlewares.{{ changedetection_identifier }}-slashless-redirect.redirectregex.regex=^({{ changedetection_container_labels_traefik_path_prefix | quote }})$
12+
traefik.http.middlewares.{{ changedetection_identifier }}-slashless-redirect.redirectregex.replacement=${1}/
13+
{% set middlewares = middlewares + [changedetection_identifier + '-slashless-redirect'] %}
14+
{% endif %}
15+
16+
{% if changedetection_container_labels_traefik_path_prefix != '/' %}
17+
traefik.http.middlewares.{{ changedetection_identifier }}-strip-prefix.stripprefix.prefixes={{ changedetection_container_labels_traefik_path_prefix }}
18+
{% set middlewares = middlewares + [changedetection_identifier + '-strip-prefix'] %}
19+
{% endif %}
20+
821
{% if changedetection_container_labels_traefik_additional_request_headers.keys() | length > 0 %}
922
{% for name, value in changedetection_container_labels_traefik_additional_request_headers.items() %}
1023
traefik.http.middlewares.{{ changedetection_identifier }}-add-request-headers.headers.customrequestheaders.{{ name }}={{ value }}
@@ -19,21 +32,21 @@ traefik.http.middlewares.{{ changedetection_identifier }}-add-response-headers.h
1932
{% set middlewares = middlewares + [changedetection_identifier + '-add-response-headers'] %}
2033
{% endif %}
2134

22-
traefik.enable=true
23-
{% endif %}
2435
traefik.http.routers.{{ changedetection_identifier }}.rule={{ changedetection_container_labels_traefik_rule }}
2536
{% if changedetection_container_labels_traefik_priority | int > 0 %}
2637
traefik.http.routers.{{ changedetection_identifier }}.priority={{ changedetection_container_labels_traefik_priority }}
2738
{% endif %}
39+
traefik.http.routers.{{ changedetection_identifier }}.service={{ changedetection_identifier }}
2840
{% if middlewares | length > 0 %}
2941
traefik.http.routers.{{ changedetection_identifier }}.middlewares={{ middlewares | join(',') }}
3042
{% endif %}
31-
traefik.http.routers.{{ changedetection_identifier }}.service={{ changedetection_identifier }}
3243
traefik.http.routers.{{ changedetection_identifier }}.entrypoints={{ changedetection_container_labels_traefik_entrypoints }}
3344
traefik.http.routers.{{ changedetection_identifier }}.tls={{ changedetection_container_labels_traefik_tls | to_json }}
3445
{% if changedetection_container_labels_traefik_tls %}
3546
traefik.http.routers.{{ changedetection_identifier }}.tls.certResolver={{ changedetection_container_labels_traefik_tls_certResolver }}
3647
{% endif %}
48+
3749
traefik.http.services.{{ changedetection_identifier }}.loadbalancer.server.port={{ changedetection_container_http_port }}
50+
{% endif %}
3851

39-
{{ changedetection_container_labels_additional_labels }}
52+
{{ changedetection_container_labels_additional_labels }}

0 commit comments

Comments
 (0)