From 3a44c414d16a15dc545d9b39141f1634f1eac18f Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 18 Aug 2022 10:50:39 -0400 Subject: [PATCH 1/6] fix: correct help output for caddy --- plugins/caddy-vhosts/help-functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/caddy-vhosts/help-functions b/plugins/caddy-vhosts/help-functions index ce2276420..287ffed04 100755 --- a/plugins/caddy-vhosts/help-functions +++ b/plugins/caddy-vhosts/help-functions @@ -6,7 +6,7 @@ cmd-caddy-help() { declare desc="help command" declare CMD="$1" local plugin_name="caddy" - local plugin_description="Manage mounted volumes" + local plugin_description="Manage the caddy proxy integration" if [[ "$CMD" == "${plugin_name}:help" ]]; then echo -e "Usage: dokku ${plugin_name}[:COMMAND]" From 591fe8642d524fa8f9539392413be0eb87b24efb Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 18 Aug 2022 10:50:46 -0400 Subject: [PATCH 2/6] fix: correct help output for traefik --- plugins/traefik-vhosts/help-functions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/traefik-vhosts/help-functions b/plugins/traefik-vhosts/help-functions index 838b0b960..22ec4c1a8 100755 --- a/plugins/traefik-vhosts/help-functions +++ b/plugins/traefik-vhosts/help-functions @@ -6,7 +6,7 @@ cmd-traefik-help() { declare desc="help command" declare CMD="$1" local plugin_name="traefik" - local plugin_description="Manage mounted volumes" + local plugin_description="Manage the traefik proxy integration" if [[ "$CMD" == "${plugin_name}:help" ]]; then echo -e "Usage: dokku ${plugin_name}[:COMMAND]" From 741ffc635c416b0849b365274225cf1b320f3cf8 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 18 Aug 2022 10:53:08 -0400 Subject: [PATCH 3/6] fix: fix issue with multiple domain support for caddy --- .../caddy-vhosts/docker-args-process-deploy | 7 +- tests/unit/caddy.bats | 83 +++++++++++++++++++ 2 files changed, 87 insertions(+), 3 deletions(-) create mode 100644 tests/unit/caddy.bats diff --git a/plugins/caddy-vhosts/docker-args-process-deploy b/plugins/caddy-vhosts/docker-args-process-deploy index d79c3ef73..79d871944 100755 --- a/plugins/caddy-vhosts/docker-args-process-deploy +++ b/plugins/caddy-vhosts/docker-args-process-deploy @@ -75,6 +75,7 @@ trigger-caddy-vhosts-docker-args-process-deploy() { app_domains="$(plugn trigger domains-list "$APP")" if [[ -n "$app_domains" ]]; then caddy_domains="$(echo "$app_domains" | xargs)" + caddy_domains="${caddy_domains// /, }" fi # add the labels for caddy here @@ -100,7 +101,7 @@ trigger-caddy-vhosts-docker-args-process-deploy() { letsencrypt_email="$(fn-caddy-letsencrypt-email)" scheme="http" if [[ -n "$letsencrypt_email" ]] && [[ "$has_443_mapping" == "true" ]]; then - output="--label caddy=${caddy_domains}" + output="--label 'caddy=${caddy_domains}'" scheme="https" if [[ -z "$proxy_container_https_port" ]]; then warning_scheme="$(awk -F ':' '{ print $1 }' <<<"$ssl_warning_mapping")" @@ -111,8 +112,8 @@ trigger-caddy-vhosts-docker-args-process-deploy() { output="$output --label \"caddy.reverse_proxy={{ upstreams $proxy_container_https_port }}\"" elif [[ -n "$proxy_container_http_port" ]] || [[ -n "$proxy_container_http_port_candidate" ]]; then - caddy_domains="${caddy_domains// /:80 }" - output="--label caddy=${caddy_domains}:80" + caddy_domains="${caddy_domains//, /:80, }" + output="--label 'caddy=${caddy_domains}:80'" if [[ -z "$proxy_container_http_port" ]]; then dokku_log_warn "Warning: http:80 port mapping not found" dokku_log_warn "Utilizing first http port mapping, http:$proxy_host_http_port_candidate:$proxy_container_http_port_candidate" diff --git a/tests/unit/caddy.bats b/tests/unit/caddy.bats new file mode 100644 index 000000000..c740fa830 --- /dev/null +++ b/tests/unit/caddy.bats @@ -0,0 +1,83 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + dokku nginx:stop + dokku caddy:start + create_app +} + +teardown() { + global_teardown + destroy_app + dokku caddy:stop + dokku nginx:start +} + +@test "(caddy) caddy:help" { + run /bin/bash -c "dokku caddy" + echo "output: $output" + echo "status: $status" + assert_output_contains "Manage the caddy proxy integration" + help_output="$output" + + run /bin/bash -c "dokku caddy:help" + echo "output: $output" + echo "status: $status" + assert_output_contains "Manage the caddy proxy integration" + assert_output "$help_output" +} + +@test "(caddy) single domain" { + run /bin/bash -c "dokku proxy:set $TEST_APP caddy" + echo "output: $output" + echo "status: $status" + assert_success + + run deploy_app + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "curl $(dokku url $TEST_APP)" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains "python/http.server" +} + +@test "(caddy) multiple domains" { + run /bin/bash -c "dokku proxy:set $TEST_APP caddy" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku domains:add $TEST_APP $TEST_APP.dokku.me" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku domains:add $TEST_APP $TEST_APP-2.dokku.me" + echo "output: $output" + echo "status: $status" + assert_success + + run deploy_app + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "curl $TEST_APP.dokku.me" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "python/http.server" + + run /bin/bash -c "curl $TEST_APP-2.dokku.me" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "python/http.server" +} From 801fc5d78cfa59c2945ce475c1ffcd53b8786047 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 18 Aug 2022 11:13:01 -0400 Subject: [PATCH 4/6] fix: ensure we don't output anything extra in tests --- tests/unit/caddy.bats | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/unit/caddy.bats b/tests/unit/caddy.bats index c740fa830..91665f690 100644 --- a/tests/unit/caddy.bats +++ b/tests/unit/caddy.bats @@ -41,7 +41,7 @@ teardown() { echo "status: $status" assert_success - run /bin/bash -c "curl $(dokku url $TEST_APP)" + run /bin/bash -c "curl --silent $(dokku url $TEST_APP)" echo "output: $output" echo "status: $status" assert_success @@ -69,13 +69,13 @@ teardown() { echo "status: $status" assert_success - run /bin/bash -c "curl $TEST_APP.dokku.me" + run /bin/bash -c "curl --silent $TEST_APP.dokku.me" echo "output: $output" echo "status: $status" assert_success assert_output "python/http.server" - run /bin/bash -c "curl $TEST_APP-2.dokku.me" + run /bin/bash -c "curl --silent $TEST_APP-2.dokku.me" echo "output: $output" echo "status: $status" assert_success From c9caa0880fbfe95885c837fc4f670499e5e5e1a6 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 18 Aug 2022 11:13:34 -0400 Subject: [PATCH 5/6] tests: add unit tests and support multiple routers/services in traefik --- .../traefik-vhosts/docker-args-process-deploy | 2 + tests/unit/traefik.bats | 83 +++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 tests/unit/traefik.bats diff --git a/plugins/traefik-vhosts/docker-args-process-deploy b/plugins/traefik-vhosts/docker-args-process-deploy index 93572ead1..9b46c9af8 100755 --- a/plugins/traefik-vhosts/docker-args-process-deploy +++ b/plugins/traefik-vhosts/docker-args-process-deploy @@ -91,6 +91,7 @@ trigger-traefik-vhosts-docker-args-process-deploy() { output="$output --label traefik.http.services.$APP-$PROC_TYPE.loadbalancer.server.port=$proxy_container_http_port" output="$output --label traefik.http.routers.$APP-$PROC_TYPE.entrypoints=http" + output="$output --label traefik.http.routers.$APP-$PROC_TYPE.service=$APP-$PROC_TYPE" if [[ -n "$traefik_domains" ]]; then output="$output --label \"traefik.http.routers.$APP-$PROC_TYPE.rule=Host(\\\`$traefik_domains\\\`)\"" echo "# THIS FILE IS GENERATED BY DOKKU - DO NOT EDIT, YOUR CHANGES WILL BE OVERWRITTEN" >"$app_urls_path" @@ -107,6 +108,7 @@ trigger-traefik-vhosts-docker-args-process-deploy() { output="$output --label traefik.http.services.$APP-$PROC_TYPE-https.loadbalancer.server.port=$proxy_container_https_port" output="$output --label traefik.http.routers.$APP-$PROC_TYPE-https.entrypoints=https" + output="$output --label traefik.http.routers.$APP-$PROC_TYPE-https.service=$APP-$PROC_TYPE-https" if [[ -n "$traefik_domains" ]]; then output="$output --label \"traefik.http.routers.$APP-$PROC_TYPE-https.rule=Host(\\\`$traefik_domains\\\`)\"" echo "# THIS FILE IS GENERATED BY DOKKU - DO NOT EDIT, YOUR CHANGES WILL BE OVERWRITTEN" >"$app_urls_path" diff --git a/tests/unit/traefik.bats b/tests/unit/traefik.bats new file mode 100644 index 000000000..a37624afb --- /dev/null +++ b/tests/unit/traefik.bats @@ -0,0 +1,83 @@ +#!/usr/bin/env bats + +load test_helper + +setup() { + global_setup + dokku nginx:stop + dokku traefik:start + create_app +} + +teardown() { + global_teardown + destroy_app + dokku traefik:stop + dokku nginx:start +} + +@test "(traefik) traefik:help" { + run /bin/bash -c "dokku traefik" + echo "output: $output" + echo "status: $status" + assert_output_contains "Manage the traefik proxy integration" + help_output="$output" + + run /bin/bash -c "dokku traefik:help" + echo "output: $output" + echo "status: $status" + assert_output_contains "Manage the traefik proxy integration" + assert_output "$help_output" +} + +@test "(traefik) single domain" { + run /bin/bash -c "dokku proxy:set $TEST_APP traefik" + echo "output: $output" + echo "status: $status" + assert_success + + run deploy_app + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "curl --silent $(dokku url $TEST_APP)" + echo "output: $output" + echo "status: $status" + assert_success + assert_output_contains "python/http.server" +} + +@test "(traefik) multiple domains" { + run /bin/bash -c "dokku proxy:set $TEST_APP traefik" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku domains:add $TEST_APP $TEST_APP.dokku.me" + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "dokku domains:add $TEST_APP $TEST_APP-2.dokku.me" + echo "output: $output" + echo "status: $status" + assert_success + + run deploy_app + echo "output: $output" + echo "status: $status" + assert_success + + run /bin/bash -c "curl --silent $TEST_APP.dokku.me" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "python/http.server" + + run /bin/bash -c "curl --silent $TEST_APP-2.dokku.me" + echo "output: $output" + echo "status: $status" + assert_success + assert_output "python/http.server" +} From 16dd0adb352dcedfeb1adc71c037cd1cfe87a26f Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Thu, 18 Aug 2022 13:10:47 -0400 Subject: [PATCH 6/6] fix: drop extra quote on LE server --- 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 bd64d20df..f8b9c0f54 100644 --- a/plugins/traefik-vhosts/templates/compose.yml.sigil +++ b/plugins/traefik-vhosts/templates/compose.yml.sigil @@ -17,7 +17,7 @@ services: - --log.format=json {{ if $.TRAEFIK_LETSENCRYPT_EMAIL }} - - --certificatesresolvers.leresolver.acme.caserver={{ $.TRAEFIK_LETSENCRYPT_SERVER }}" + - --certificatesresolvers.leresolver.acme.caserver={{ $.TRAEFIK_LETSENCRYPT_SERVER }} - --certificatesresolvers.leresolver.acme.email={{ $.TRAEFIK_LETSENCRYPT_EMAIL }} - --certificatesresolvers.leresolver.acme.storage=/acme.json - --certificatesresolvers.leresolver.acme.tlschallenge=true