diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 557551c0..bbc49248 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -38,10 +38,6 @@ jobs: - "3.10" - 3.11 odoo-version: - - 11.0 - - 12.0 - - 13.0 - - 14.0 - 15.0 - 16.0 include: @@ -50,8 +46,6 @@ jobs: - python-version: 3.11 odoo-version: 17.0 traefik_version: - - 1 - - 2 - 3 steps: diff --git a/_traefik3_labels.yml.jinja b/_traefik3_labels.yml.jinja index 74f2092b..0a8d282d 100644 --- a/_traefik3_labels.yml.jinja +++ b/_traefik3_labels.yml.jinja @@ -1,4 +1,5 @@ {%- import "_macros.jinja" as macros -%} + {# Echo all domains of a group, in a Traefik rule #} {%- macro domains_rule(hosts, path_prefixes=(), paths=()) -%} Host(`{{ hosts | join("`) || Host(`") }}`) @@ -41,30 +42,29 @@ {#- Route redirections #} {%- if domain_group.redirect_to %} - traefik.alt-{{ domain_group.loop.index0 }}.frontend.redirect.regex: ^(.*)://([^/]+)/(.*)$$ - traefik.alt-{{ domain_group.loop.index0 }}.frontend.redirect.replacement: $$1://{{ domain_group.redirect_to }}/$$3 + traefik.http.middlewares.redirect-to-{{ domain_group.loop.index0 }}.redirectregex.regex: ^(.*)://([^/]+)/(.*)$$ + traefik.http.middlewares.redirect-to-{{ domain_group.loop.index0 }}.redirectregex.replacement: $$1://{{ domain_group.redirect_to }}/$$3 + traefik.http.routers.alt-{{ domain_group.loop.index0 }}.middlewares: redirect-to-{{ domain_group.loop.index0 }} {{- router( prefix="alt", index0=domain_group.loop.index0, rule=domains_rule(domain_group.hosts, domain_group.path_prefixes), - entrypoints=domain_group.entrypoints, + entrypoints=domain_group.entrypoints ) }} - {%- else %} - - {#- Forbidden crawler routers #} + {%- else -%} {%- if paths_without_crawlers and not domain_group.path_prefixes %} - traefik.forbiddenCrawlers-{{ domain_group.loop.index0 }}.frontend.headers.customResponseHeaders: - "X-Robots-Tag:noindex, nofollow" {{- router( prefix="forbiddenCrawlers", index0=domain_group.loop.index0, rule=domains_rule(domain_group.hosts, paths_without_crawlers), entrypoints=domain_group.entrypoints, - ) + middlewares=["forbiddenCrawlers-" ~ domain_group.loop.index0] ) }} + traefik.http.middlewares.forbiddenCrawlers-{{ domain_group.loop.index0 }}.headers.customResponseHeadersX-Robots-Tag: + "noindex, nofollow" {%- endif %} {#- Normal routers #} @@ -74,7 +74,7 @@ prefix="main", index0=domain_group.loop.index0, rule=domains_rule(domain_group.hosts, domain_group.path_prefixes), - entrypoints=domain_group.entrypoints, + entrypoints=domain_group.entrypoints ) }} {%- endif %} @@ -86,21 +86,26 @@ index0=domain_group.loop.index0, rule=domains_rule(domain_group.hosts, [longpolling_route]), entrypoints=domain_group.entrypoints, - port=8072, + port=8072 ) }} {%- endif %} {%- endif %} {%- endcall %} {%- endmacro %} + {#- Basic labels for a single router #} -{%- macro router(prefix, index0, rule, entrypoints=(), port=none) %} - traefik.{{ prefix }}-{{ index0 }}.frontend.rule: {{ rule }} +{%- macro router(prefix, index0, rule, entrypoints=(), middlewares=(), port=none) %} + traefik.http.routers.{{ prefix }}-{{ index0 }}.rule: {{ rule }} {%- if entrypoints %} - traefik.{{ prefix }}-{{ index0 }}.frontend.entryPoints: - {{ entrypoints|sort|join(",") }} + traefik.http.routers.{{ prefix }}-{{ index0 }}.entryPoints: + "{{ entrypoints | join(',') }}" + {%- endif %} + {%- if middlewares %} + traefik.http.routers.{{ prefix }}-{{ index0 }}.middlewares: + "{{ middlewares | join(',') }}" {%- endif %} {%- if port %} - traefik.{{ prefix }}-{{ index0 }}.port: {{ port }} + traefik.http.services.{{ prefix }}-{{ index0 }}.loadbalancer.server.port: {{ port }} {%- endif %} {%- endmacro %} diff --git a/tests/test_routing.py b/tests/test_routing.py index 0c552d7a..a3c92b2b 100644 --- a/tests/test_routing.py +++ b/tests/test_routing.py @@ -4,6 +4,7 @@ import pytest import requests +import yaml from copier import run_copy from packaging import version from plumbum import local @@ -70,6 +71,7 @@ def test_multiple_domains( if supported_odoo_version < 16: data["postgres_version"] = 13 dc = DockerClient(compose_files=[f"{environment}.yaml"]) + with local.cwd(tmp_path): run_copy( src_path=str(cloned_template), @@ -84,6 +86,11 @@ def test_multiple_domains( docker_compose_config = dc.compose.config() assert docker_compose_config.services["odoo"].environment["LIST_DB"] == "true" try: + # Imprime el YAML formateado + yaml_content = yaml.dump(docker_compose_config, default_flow_style=False) + raise RuntimeError( + f"Forced Error - Here is the YAML content:\n\n{yaml_content}" + ) dc.compose.build() dc.compose.run( "odoo", @@ -194,5 +201,7 @@ def test_multiple_domains( bad_response = requests.get(f"https://missing.{base_path}", verify=False) assert bad_response.status_code == 404 assert "Server" not in bad_response.headers - finally: - dc.compose.down(remove_images="local", remove_orphans=True) + except RuntimeError as e: + # Captura y muestra el error + print(f"An error occurred: {e}") + raise