feat: add ability to set a custom priority for traefik routing rules
This commit is contained in:
1 parent
38cb05e7b1
commit
e26b0ba1db
7 files changed
+59
-3
No files matched your search
@@ -114,6 +114,16 @@ dokku traefik:set --global log-level DEBUG
|
|||||||
|
|
||||||
After modifying, the Traefik container will need to be restarted.
|
After modifying, the Traefik container will need to be restarted.
|
||||||
|
|
||||||
|
### Setting rule priority
|
||||||
|
|
||||||
|
By default, app deployments will result in the newer traefik rules using a higher priority in order to have any newer rules respected by Traefik. Rule priorities will always increase according to the current unix timestamp. The priority may be fixed by setting the app-level `priority` property:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
dokku traefik:set node-js-app priority 12345
|
||||||
|
```
|
||||||
|
|
||||||
|
After modifying, the app container will need to be recreated via a `ps:rebuild` or an app deployment.
|
||||||
|
|
||||||
### SSL Configuration
|
### SSL Configuration
|
||||||
|
|
||||||
The traefik plugin only supports automatic ssl certificates from it's letsencrypt integration. Managed certificates provided by the `certs` plugin are ignored.
|
The traefik plugin only supports automatic ssl certificates from it's letsencrypt integration. Managed certificates provided by the `certs` plugin are ignored.
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ cmd-traefik-report-single() {
|
|||||||
"--traefik-letsencrypt-email: $(fn-traefik-letsencrypt-email)"
|
"--traefik-letsencrypt-email: $(fn-traefik-letsencrypt-email)"
|
||||||
"--traefik-letsencrypt-server: $(fn-traefik-letsencrypt-server)"
|
"--traefik-letsencrypt-server: $(fn-traefik-letsencrypt-server)"
|
||||||
"--traefik-log-level: $(fn-traefik-log-level)"
|
"--traefik-log-level: $(fn-traefik-log-level)"
|
||||||
|
"--traefik-priority: $(fn-traefik-priority "$APP")"
|
||||||
)
|
)
|
||||||
|
|
||||||
if [[ -z "$INFO_FLAG" ]]; then
|
if [[ -z "$INFO_FLAG" ]]; then
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||||
|
source "$PLUGIN_AVAILABLE_PATH/traefik-vhosts/internal-functions"
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
[[ $DOKKU_TRACE ]] && set -x
|
[[ $DOKKU_TRACE ]] && set -x
|
||||||
|
|
||||||
@@ -81,7 +82,10 @@ trigger-traefik-vhosts-docker-args-process-deploy() {
|
|||||||
traefik_domains="${traefik_domains// /\\\`,\\\`}"
|
traefik_domains="${traefik_domains// /\\\`,\\\`}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
priority="$(fn-traefik-priority "$APP")"
|
||||||
|
if [[ -z "$priority" ]]; then
|
||||||
priority="$(date +%s)"
|
priority="$(date +%s)"
|
||||||
|
fi
|
||||||
|
|
||||||
output="--label traefik.enable=true"
|
output="--label traefik.enable=true"
|
||||||
if [[ -n "$proxy_container_http_port" ]] || [[ -n "$proxy_container_http_port_candidate" ]]; then
|
if [[ -n "$proxy_container_http_port" ]] || [[ -n "$proxy_container_http_port_candidate" ]]; then
|
||||||
|
|||||||
@@ -92,3 +92,8 @@ fn-traefik-log-level() {
|
|||||||
log_level="$(fn-plugin-property-get-default "traefik" "--global" "log-level" "ERROR")"
|
log_level="$(fn-plugin-property-get-default "traefik" "--global" "log-level" "ERROR")"
|
||||||
echo "${log_level^^}"
|
echo "${log_level^^}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn-traefik-priority() {
|
||||||
|
declare APP="$1"
|
||||||
|
fn-plugin-property-get-default "traefik" "$APP" "priority" ""
|
||||||
|
}
|
||||||
Executable
+14
@@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
|
||||||
|
set -eo pipefail
|
||||||
|
[[ $DOKKU_TRACE ]] && set -x
|
||||||
|
|
||||||
|
trigger-traefik-vhosts-post-delete() {
|
||||||
|
declare desc="traefik-vhosts post-delete trigger"
|
||||||
|
declare trigger="post-delete"
|
||||||
|
declare APP="$1"
|
||||||
|
|
||||||
|
fn-plugin-property-destroy "traefik" "$APP"
|
||||||
|
}
|
||||||
|
|
||||||
|
trigger-traefik-vhosts-post-delete "$@"
|
||||||
@@ -9,13 +9,13 @@ cmd-traefik-set() {
|
|||||||
declare cmd="traefik:set"
|
declare cmd="traefik:set"
|
||||||
[[ "$1" == "$cmd" ]] && shift 1
|
[[ "$1" == "$cmd" ]] && shift 1
|
||||||
declare APP="$1" KEY="$2" VALUE="$3"
|
declare APP="$1" KEY="$2" VALUE="$3"
|
||||||
local VALID_KEYS=("api-enabled" "api-vhost" "dashboard-enabled" "basic-auth-username" "basic-auth-password" "image" "letsencrypt-email" "log-level")
|
local VALID_KEYS=("api-enabled" "api-vhost" "dashboard-enabled" "basic-auth-username" "basic-auth-password" "image" "letsencrypt-email" "letsencrypt-server" "log-level" "priority")
|
||||||
local GLOBAL_KEYS=("api-enabled" "api-vhost" "dashboard"-enabled "basic-auth-username" "basic-auth-password" "image" "letsencrypt-email" "log-level")
|
local GLOBAL_KEYS=("api-enabled" "api-vhost" "dashboard"-enabled "basic-auth-username" "basic-auth-password" "image" "letsencrypt-email" "letsencrypt-server" "log-level")
|
||||||
|
|
||||||
[[ -z "$KEY" ]] && dokku_log_fail "No key specified"
|
[[ -z "$KEY" ]] && dokku_log_fail "No key specified"
|
||||||
|
|
||||||
if ! fn-in-array "$KEY" "${VALID_KEYS[@]}"; then
|
if ! fn-in-array "$KEY" "${VALID_KEYS[@]}"; then
|
||||||
dokku_log_fail "Invalid key specified, valid keys include: api-enabled api-vhost dashboard-enabled basic-auth-username basic-auth-password image letsencrypt-email log-level"
|
dokku_log_fail "Invalid key specified, valid keys include: api-enabled api-vhost dashboard-enabled basic-auth-username basic-auth-password image letsencrypt-email letsencrypt-server log-level priority"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if ! fn-in-array "$KEY" "${GLOBAL_KEYS[@]}"; then
|
if ! fn-in-array "$KEY" "${GLOBAL_KEYS[@]}"; then
|
||||||
|
|||||||
@@ -81,3 +81,25 @@ teardown() {
|
|||||||
assert_success
|
assert_success
|
||||||
assert_output "python/http.server"
|
assert_output "python/http.server"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "(traefik) traefik:set priority" {
|
||||||
|
run /bin/bash -c "dokku proxy:set $TEST_APP traefik"
|
||||||
|
echo "output: $output"
|
||||||
|
echo "status: $status"
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run /bin/bash -c "dokku traefik:set $TEST_APP priority 12345"
|
||||||
|
echo "output: $output"
|
||||||
|
echo "status: $status"
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run deploy_app
|
||||||
|
echo "output: $output"
|
||||||
|
echo "status: $status"
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"traefik.http.services.$TEST_APP-web-http-12345.loadbalancer.server.port\" }}'"
|
||||||
|
echo "output: $output"
|
||||||
|
echo "status: $status"
|
||||||
|
assert_output "5000"
|
||||||
|
}
|
||||||
Reference in new issue
Block a user