Files
dokku/plugins/traefik-vhosts/internal-functions
Matt Farmer 3cf02f9904 feat(traefik-vhosts): support custom entrypoint for API/dashboard
Add two new global-only properties to configure a dedicated Traefik entrypoint
for the API and dashboard, enabling network isolation on private interfaces.
Includes comprehensive test coverage for property management and compose config.

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
2026-02-28 18:07:07 -05:00

143 lines
4.7 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-basic-auth-password)"
basic_auth_username="$(fn-traefik-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-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-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-api-enabled)"
TRAEFIK_API_ENTRY_POINT="$(fn-traefik-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-api-vhost)"
TRAEFIK_BASIC_AUTH="$basic_auth"
TRAEFIK_CHALLENGE_MODE="$(fn-traefik-challenge-mode)"
TRAEFIK_DASHBOARD_ENABLED="$(fn-traefik-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-image)"
TRAEFIK_LETSENCRYPT_EMAIL="$(fn-traefik-letsencrypt-email)"
TRAEFIK_LETSENCRYPT_SERVER="$(fn-traefik-letsencrypt-server)"
TRAEFIK_LOG_LEVEL="$(fn-traefik-log-level)")
sigil -f "$COMPOSE_TEMPLATE" "${SIGIL_PARAMS[@]}" | cat -s >"$OUTPUT_PATH"
}
fn-traefik-api-enabled() {
fn-plugin-property-get-default "traefik" "--global" "api-enabled" "false"
}
fn-traefik-api-vhost() {
fn-plugin-property-get-default "traefik" "--global" "api-vhost" "traefik.dokku.me"
}
fn-traefik-basic-auth-password() {
fn-plugin-property-get-default "traefik" "--global" "basic-auth-password" ""
}
fn-traefik-basic-auth-username() {
fn-plugin-property-get-default "traefik" "--global" "basic-auth-username" ""
}
fn-traefik-dashboard-enabled() {
fn-plugin-property-get-default "traefik" "--global" "dashboard-enabled" "false"
}
fn-traefik-image() {
fn-plugin-property-get-default "traefik" "--global" "image" "$(grep "FROM" "$PLUGIN_AVAILABLE_PATH/traefik-vhosts/Dockerfile" | awk '{print $2}')"
}
fn-traefik-letsencrypt-email() {
fn-plugin-property-get-default "traefik" "--global" "letsencrypt-email" ""
}
fn-traefik-letsencrypt-server() {
fn-plugin-property-get-default "traefik" "--global" "letsencrypt-server" "https://acme-v02.api.letsencrypt.org/directory"
}
fn-traefik-log-level() {
local log_level
log_level="$(fn-plugin-property-get-default "traefik" "--global" "log-level" "ERROR")"
echo "${log_level^^}"
}
fn-traefik-http-entry-point() {
fn-plugin-property-get-default "traefik" "--global" "http-entry-point" "http"
}
fn-traefik-https-entry-point() {
fn-plugin-property-get-default "traefik" "--global" "https-entry-point" "https"
}
fn-traefik-api-entry-point() {
fn-plugin-property-get-default "traefik" "--global" "api-entry-point" ""
}
fn-traefik-api-entry-point-address() {
fn-plugin-property-get-default "traefik" "--global" "api-entry-point-address" ""
}
fn-traefik-challenge-mode() {
fn-plugin-property-get-default "traefik" "--global" "challenge-mode" "tls"
}
fn-traefik-dns-provider() {
fn-plugin-property-get-default "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-"
}