T1 of every per-backend test file asserted 200 with the api Procfile body for a request that lacks --strip-prefix, but without the strip the upstream sees /api/v0/Procfile and python's http.server returns 404; the retry loop polled on status only and accepted web's catch-all 200 first. The assertion now expects 404, which is the right signal that the route reaches the api process. T3 was rewritten to follow T2's two-step pattern (404 without strip, then 200 with strip) so the route is proven applied before checking content. T4 of proxy-route-nginx.bats relaxes the WebSocket header assertions to allow more than one occurrence because the headers correctly appear in both the route location block and the existing location / block. Backticks in fn-traefik-host-rule and fn-traefik-route-labels are now triple-escaped so they survive the docker-args eval path that turns the labels into a docker run invocation, matching the existing convention in docker-args-process-deploy. The label-based backend test files also echo the ps:rebuild output now so future failures of that step surface in the CI logs instead of silently exiting non-zero.
333 lines
9.9 KiB
Bash
Executable File
333 lines
9.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
|
|
set -eo pipefail
|
|
[[ $DOKKU_TRACE ]] && set -x
|
|
|
|
fn-traefik-route-labels() {
|
|
declare desc="emits per-route traefik labels for a non-web container"
|
|
declare APP="$1" PROC_TYPE="$2" STDIN="$3"
|
|
local host_rule output route_proc route_port route_path route_strip
|
|
local router_name service_name middleware_name path_len
|
|
|
|
host_rule="$(fn-traefik-host-rule "$APP")"
|
|
output="--label traefik.enable=true"
|
|
|
|
while IFS='|' read -r route_proc route_port route_path route_strip; do
|
|
[[ -z "$route_proc" ]] && continue
|
|
[[ "$route_proc" != "$PROC_TYPE" ]] && continue
|
|
|
|
local route_slug
|
|
route_slug="$(fn-traefik-route-slug "$route_path")"
|
|
router_name="${APP}-${route_proc}-${route_slug}"
|
|
service_name="${APP}-${route_proc}-${route_slug}"
|
|
path_len="${#route_path}"
|
|
|
|
# Triple-backslash for the same eval-survival reason as fn-traefik-host-rule.
|
|
local rule="PathPrefix(\\\`${route_path}\\\`)"
|
|
if [[ -n "$host_rule" ]]; then
|
|
rule="(${host_rule}) && ${rule}"
|
|
fi
|
|
|
|
output="$output --label \"traefik.http.routers.${router_name}.rule=${rule}\""
|
|
output="$output --label traefik.http.routers.${router_name}.entrypoints=$(fn-traefik-computed-http-entry-point)"
|
|
output="$output --label traefik.http.routers.${router_name}.priority=${path_len}"
|
|
output="$output --label traefik.http.routers.${router_name}.service=${service_name}"
|
|
output="$output --label traefik.http.services.${service_name}.loadbalancer.server.port=${route_port}"
|
|
|
|
if [[ "$route_strip" == "1" ]]; then
|
|
middleware_name="${router_name}-strip"
|
|
output="$output --label traefik.http.middlewares.${middleware_name}.stripprefix.prefixes=${route_path}"
|
|
output="$output --label traefik.http.routers.${router_name}.middlewares=${middleware_name}"
|
|
fi
|
|
done < <(plugn trigger proxy-routes-list "$APP")
|
|
|
|
local proxy_labels_file_path=$(fn-proxy-get-labels-file-path "traefik" "$APP")
|
|
if [[ -f "$proxy_labels_file_path" ]]; then
|
|
while read -r line; do
|
|
[[ -z "$line" ]] && continue
|
|
output="$output --label '$line'"
|
|
done <"$proxy_labels_file_path"
|
|
fi
|
|
|
|
echo -n "$STDIN $output"
|
|
}
|
|
|
|
fn-traefik-route-slug() {
|
|
declare desc="returns a deterministic kebab-case slug for a route path"
|
|
declare ROUTE_PATH="$1"
|
|
local s="${ROUTE_PATH#/}"
|
|
s="${s%/}"
|
|
s="${s//\//-}"
|
|
s="${s,,}"
|
|
if [[ -z "$s" ]]; then
|
|
s="root"
|
|
fi
|
|
echo "$s"
|
|
}
|
|
|
|
fn-traefik-host-rule() {
|
|
declare desc="builds a traefik Host(\`d1\`) || Host(\`d2\`) rule fragment from an app's domains"
|
|
declare APP="$1"
|
|
local app_domains domain result=""
|
|
|
|
app_domains="$(plugn trigger domains-list "$APP")"
|
|
if [[ -z "$app_domains" ]]; then
|
|
return
|
|
fi
|
|
|
|
# Backticks must be double-escaped so they survive the docker-args eval
|
|
# path. A single backslash leaves a bare backtick in the final string,
|
|
# which then runs as a command substitution at eval time and breaks the
|
|
# docker run invocation. Triple-backslash matches the existing emission
|
|
# convention used by docker-args-process-deploy.
|
|
for domain in $(echo "$app_domains" | xargs); do
|
|
if [[ -z "$result" ]]; then
|
|
result="Host(\\\`${domain}\\\`)"
|
|
continue
|
|
fi
|
|
result="${result} || Host(\\\`${domain}\\\`)"
|
|
done
|
|
echo "$result"
|
|
}
|
|
|
|
fn-traefik-logs() {
|
|
declare desc="shows the logs for the traefik container"
|
|
declare TAIL="$1" NUM="$2"
|
|
local dokku_logs_args=("--tail" "$NUM")
|
|
|
|
if [[ "$TAIL" == "true" ]]; then
|
|
dokku_logs_args+=("--follow")
|
|
fi
|
|
|
|
"$DOCKER_BIN" logs traefik-traefik-1 "${dokku_logs_args[@]}"
|
|
}
|
|
|
|
fn-traefik-logs-usage() {
|
|
declare desc="logs specific usage"
|
|
echo "Usage: dokku traefik:logs"
|
|
echo " display recent traefik log output"
|
|
echo ""
|
|
echo " -n, --num NUM # the number of lines to display"
|
|
echo " -t, --tail # continually stream logs"
|
|
}
|
|
|
|
fn-traefik-template-compose-file() {
|
|
declare desc="templates out the compose file"
|
|
declare OUTPUT_PATH="$1"
|
|
local COMPOSE_TEMPLATE="$PLUGIN_AVAILABLE_PATH/traefik-vhosts/templates/compose.yml.sigil"
|
|
local basic_auth basic_auth_password basic_auth_username
|
|
|
|
CUSTOM_COMPOSE_TEMPLATE="$(plugn trigger traefik-template-source "$APP")"
|
|
if [[ -n "$CUSTOM_COMPOSE_TEMPLATE" ]]; then
|
|
COMPOSE_TEMPLATE="$CUSTOM_COMPOSE_TEMPLATE"
|
|
fi
|
|
|
|
basic_auth_password="$(fn-traefik-computed-basic-auth-password)"
|
|
basic_auth_username="$(fn-traefik-computed-basic-auth-username)"
|
|
if [[ -n "$basic_auth_password" ]] && [[ -n "$basic_auth_username" ]]; then
|
|
basic_auth="$(htpasswd -nb "$basic_auth_username" "$basic_auth_password" | sed -e s/\\$/\\$\\$/g)"
|
|
fi
|
|
|
|
local dns_provider_env_vars=""
|
|
local dns_provider
|
|
dns_provider="$(fn-traefik-computed-dns-provider)"
|
|
if [[ -n "$dns_provider" ]]; then
|
|
dns_provider_env_vars="$(fn-traefik-dns-provider-env-vars)"
|
|
fi
|
|
|
|
local api_entry_point_address api_entry_point_port=""
|
|
api_entry_point_address="$(fn-traefik-computed-api-entry-point-address)"
|
|
if [[ -n "$api_entry_point_address" ]]; then
|
|
api_entry_point_port="${api_entry_point_address##*:}"
|
|
fi
|
|
|
|
local SIGIL_PARAMS=(TRAEFIK_API_ENABLED="$(fn-traefik-computed-api-enabled)"
|
|
TRAEFIK_API_ENTRY_POINT="$(fn-traefik-computed-api-entry-point)"
|
|
TRAEFIK_API_ENTRY_POINT_ADDRESS="$api_entry_point_address"
|
|
TRAEFIK_API_ENTRY_POINT_PORT="$api_entry_point_port"
|
|
TRAEFIK_API_VHOST="$(fn-traefik-computed-api-vhost)"
|
|
TRAEFIK_BASIC_AUTH="$basic_auth"
|
|
TRAEFIK_CHALLENGE_MODE="$(fn-traefik-computed-challenge-mode)"
|
|
TRAEFIK_DASHBOARD_ENABLED="$(fn-traefik-computed-dashboard-enabled)"
|
|
TRAEFIK_DATA_DIR="${DOKKU_LIB_ROOT}/data/traefik"
|
|
TRAEFIK_DNS_PROVIDER="$dns_provider"
|
|
TRAEFIK_DNS_PROVIDER_ENV_VARS="$dns_provider_env_vars"
|
|
TRAEFIK_IMAGE="$(fn-traefik-computed-image)"
|
|
TRAEFIK_LETSENCRYPT_EMAIL="$(fn-traefik-computed-letsencrypt-email)"
|
|
TRAEFIK_LETSENCRYPT_SERVER="$(fn-traefik-computed-letsencrypt-server)"
|
|
TRAEFIK_LOG_LEVEL="$(fn-traefik-computed-log-level)")
|
|
|
|
sigil -f "$COMPOSE_TEMPLATE" "${SIGIL_PARAMS[@]}" | cat -s >"$OUTPUT_PATH"
|
|
}
|
|
|
|
fn-traefik-global-api-enabled() {
|
|
fn-plugin-property-get-default "traefik" "--global" "api-enabled" ""
|
|
}
|
|
|
|
fn-traefik-computed-api-enabled() {
|
|
local value
|
|
value="$(fn-traefik-global-api-enabled)"
|
|
if [[ -z "$value" ]]; then
|
|
value="false"
|
|
fi
|
|
echo "$value"
|
|
}
|
|
|
|
fn-traefik-global-api-vhost() {
|
|
fn-plugin-property-get-default "traefik" "--global" "api-vhost" ""
|
|
}
|
|
|
|
fn-traefik-computed-api-vhost() {
|
|
local value
|
|
value="$(fn-traefik-global-api-vhost)"
|
|
if [[ -z "$value" ]]; then
|
|
value="traefik.dokku.me"
|
|
fi
|
|
echo "$value"
|
|
}
|
|
|
|
fn-traefik-global-basic-auth-password() {
|
|
fn-plugin-property-get-default "traefik" "--global" "basic-auth-password" ""
|
|
}
|
|
|
|
fn-traefik-computed-basic-auth-password() {
|
|
fn-traefik-global-basic-auth-password
|
|
}
|
|
|
|
fn-traefik-global-basic-auth-username() {
|
|
fn-plugin-property-get-default "traefik" "--global" "basic-auth-username" ""
|
|
}
|
|
|
|
fn-traefik-computed-basic-auth-username() {
|
|
fn-traefik-global-basic-auth-username
|
|
}
|
|
|
|
fn-traefik-global-dashboard-enabled() {
|
|
fn-plugin-property-get-default "traefik" "--global" "dashboard-enabled" ""
|
|
}
|
|
|
|
fn-traefik-computed-dashboard-enabled() {
|
|
local value
|
|
value="$(fn-traefik-global-dashboard-enabled)"
|
|
if [[ -z "$value" ]]; then
|
|
value="false"
|
|
fi
|
|
echo "$value"
|
|
}
|
|
|
|
fn-traefik-global-image() {
|
|
fn-plugin-property-get-default "traefik" "--global" "image" ""
|
|
}
|
|
|
|
fn-traefik-computed-image() {
|
|
local value
|
|
value="$(fn-traefik-global-image)"
|
|
if [[ -z "$value" ]]; then
|
|
value="$(grep "FROM" "$PLUGIN_AVAILABLE_PATH/traefik-vhosts/Dockerfile" | awk '{print $2}')"
|
|
fi
|
|
echo "$value"
|
|
}
|
|
|
|
fn-traefik-global-letsencrypt-email() {
|
|
fn-plugin-property-get-default "traefik" "--global" "letsencrypt-email" ""
|
|
}
|
|
|
|
fn-traefik-computed-letsencrypt-email() {
|
|
fn-traefik-global-letsencrypt-email
|
|
}
|
|
|
|
fn-traefik-global-letsencrypt-server() {
|
|
fn-plugin-property-get-default "traefik" "--global" "letsencrypt-server" ""
|
|
}
|
|
|
|
fn-traefik-computed-letsencrypt-server() {
|
|
local value
|
|
value="$(fn-traefik-global-letsencrypt-server)"
|
|
if [[ -z "$value" ]]; then
|
|
value="https://acme-v02.api.letsencrypt.org/directory"
|
|
fi
|
|
echo "$value"
|
|
}
|
|
|
|
fn-traefik-global-log-level() {
|
|
fn-plugin-property-get-default "traefik" "--global" "log-level" ""
|
|
}
|
|
|
|
fn-traefik-computed-log-level() {
|
|
local value
|
|
value="$(fn-traefik-global-log-level)"
|
|
if [[ -z "$value" ]]; then
|
|
value="ERROR"
|
|
fi
|
|
echo "${value^^}"
|
|
}
|
|
|
|
fn-traefik-global-http-entry-point() {
|
|
fn-plugin-property-get-default "traefik" "--global" "http-entry-point" ""
|
|
}
|
|
|
|
fn-traefik-computed-http-entry-point() {
|
|
local value
|
|
value="$(fn-traefik-global-http-entry-point)"
|
|
if [[ -z "$value" ]]; then
|
|
value="http"
|
|
fi
|
|
echo "$value"
|
|
}
|
|
|
|
fn-traefik-global-https-entry-point() {
|
|
fn-plugin-property-get-default "traefik" "--global" "https-entry-point" ""
|
|
}
|
|
|
|
fn-traefik-computed-https-entry-point() {
|
|
local value
|
|
value="$(fn-traefik-global-https-entry-point)"
|
|
if [[ -z "$value" ]]; then
|
|
value="https"
|
|
fi
|
|
echo "$value"
|
|
}
|
|
|
|
fn-traefik-global-api-entry-point() {
|
|
fn-plugin-property-get-default "traefik" "--global" "api-entry-point" ""
|
|
}
|
|
|
|
fn-traefik-computed-api-entry-point() {
|
|
fn-traefik-global-api-entry-point
|
|
}
|
|
|
|
fn-traefik-global-api-entry-point-address() {
|
|
fn-plugin-property-get-default "traefik" "--global" "api-entry-point-address" ""
|
|
}
|
|
|
|
fn-traefik-computed-api-entry-point-address() {
|
|
fn-traefik-global-api-entry-point-address
|
|
}
|
|
|
|
fn-traefik-global-challenge-mode() {
|
|
fn-plugin-property-get-default "traefik" "--global" "challenge-mode" ""
|
|
}
|
|
|
|
fn-traefik-computed-challenge-mode() {
|
|
local value
|
|
value="$(fn-traefik-global-challenge-mode)"
|
|
if [[ -z "$value" ]]; then
|
|
value="tls"
|
|
fi
|
|
echo "$value"
|
|
}
|
|
|
|
fn-traefik-global-dns-provider() {
|
|
fn-plugin-property-get-default "traefik" "--global" "dns-provider" ""
|
|
}
|
|
|
|
fn-traefik-computed-dns-provider() {
|
|
fn-traefik-global-dns-provider
|
|
}
|
|
|
|
fn-traefik-dns-provider-env-vars() {
|
|
declare desc="returns all dns-provider-* environment variables"
|
|
fn-plugin-property-get-all-by-prefix "traefik" "--global" "dns-provider-"
|
|
}
|