From 3bbf5370da4b4dac2661e7ae805b5ba80239832c Mon Sep 17 00:00:00 2001 From: Alexey Kharchenko Date: Thu, 13 Jul 2023 12:01:20 +0530 Subject: [PATCH 1/3] Fix traefik vhosts compose template `auth` middleware label should only be added if `TRAEFIK_BASIC_AUTH` set --- plugins/traefik-vhosts/templates/compose.yml.sigil | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/traefik-vhosts/templates/compose.yml.sigil b/plugins/traefik-vhosts/templates/compose.yml.sigil index 9755a1d7a..c49f233b0 100644 --- a/plugins/traefik-vhosts/templates/compose.yml.sigil +++ b/plugins/traefik-vhosts/templates/compose.yml.sigil @@ -33,8 +33,8 @@ services: - "traefik.http.routers.api.entrypoints={{ if $.TRAEFIK_LETSENCRYPT_EMAIL }}https{{ else }}http{{ end }}" {{ end }} - - "traefik.http.routers.api.middlewares=auth" {{ if $.TRAEFIK_BASIC_AUTH }} + - "traefik.http.routers.api.middlewares=auth" - "traefik.http.middlewares.auth.basicauth.users={{ $.TRAEFIK_BASIC_AUTH }}" {{ end }} From 687c90844dd5cb8523c8ba10a2003de436c877fa Mon Sep 17 00:00:00 2001 From: Alexey Kharchenko Date: Thu, 13 Jul 2023 12:52:57 +0530 Subject: [PATCH 2/3] Add test for `dokku traefik:show-config` --- tests/unit/traefik.bats | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/unit/traefik.bats b/tests/unit/traefik.bats index a45725aef..4885a2aa4 100644 --- a/tests/unit/traefik.bats +++ b/tests/unit/traefik.bats @@ -238,3 +238,25 @@ teardown() { echo "status: $status" assert_output "http:80:5000" } + +@test "(traefik) show-config without auth set" { + run /bin/bash -c "dokku traefik:set --global basic-auth-username \"\"" + run /bin/bash -c "dokku traefik:set --global basic-auth-password \"\"" + + run /bin/bash -c "dokku traefik:show-config" + echo "output: $output" + echo "status: $status" + assert_success + refute_line ' - "traefik.http.routers.api.middlewares=auth"' +} + +@test "(traefik) show-config with auth set" { + run /bin/bash -c "dokku traefik:set --global basic-auth-username test-username" + run /bin/bash -c "dokku traefik:set --global basic-auth-password test-password" + + run /bin/bash -c "dokku traefik:show-config" + echo "output: $output" + echo "status: $status" + assert_success + assert_line ' - "traefik.http.routers.api.middlewares=auth"' +} From 4d41cbd3ab1b071fc18b8e3358b3ef663b13d68a Mon Sep 17 00:00:00 2001 From: Alexey Kharchenko Date: Mon, 17 Jul 2023 11:42:53 +0530 Subject: [PATCH 3/3] Hide empty labels section --- plugins/traefik-vhosts/templates/compose.yml.sigil | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/plugins/traefik-vhosts/templates/compose.yml.sigil b/plugins/traefik-vhosts/templates/compose.yml.sigil index c49f233b0..7102f374e 100644 --- a/plugins/traefik-vhosts/templates/compose.yml.sigil +++ b/plugins/traefik-vhosts/templates/compose.yml.sigil @@ -25,7 +25,12 @@ services: - --certificatesresolvers.leresolver.acme.tlschallenge=true {{ end }} + {{ if or (eq $.TRAEFIK_API_ENABLED "true") ($.TRAEFIK_BASIC_AUTH) ($.TRAEFIK_LETSENCRYPT_EMAIL) }} labels: + {{ else }} + labels: [] + {{ end }} + {{ if eq $.TRAEFIK_API_ENABLED "true" }} # Dashboard - "traefik.http.routers.api.rule=Host(`{{ $.TRAEFIK_API_VHOST }}`)"