Files
dokku/plugins/traefik-vhosts/internal-functions
T
Jose Diaz-Gonzalez 83c9c4d72e fix: add proxy health checks from app.json readiness
The caddy, haproxy, openresty, and traefik docs stated that requests are only routed to containers passing healthchecks, but these proxies route to a new container as soon as it starts. The first `web` readiness healthcheck in `app.json` is now also turned into health checks and retries for caddy and openresty, as it already was for traefik, so requests are routed away from containers that are not yet ready, and the docs now describe how each proxy actually behaves.
2026-11-02 00:33:35 -05:00

246 lines
6.8 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-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-"
}