Files
dokku/plugins/caddy-vhosts/command-functions
Jose Diaz-Gonzalez 5faabea3d4 feat: port vhost proxy :report subcommands to golang
The bash :report implementations for the caddy, haproxy, openresty, and traefik proxy plugins are replaced with a compiled golang binary that collects report keys in parallel and marshals json directly. The traefik dns-provider values keep their masking behaviour, remaining hidden in the default stdout report while surfacing for --format json or an explicit flag query. These four plugins previously had no unit tests, so a bats suite covering the report matrix is added for each.
2026-07-07 06:29:01 -04:00

121 lines
3.3 KiB
Bash

#!/usr/bin/env bash
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
source "$PLUGIN_CORE_AVAILABLE_PATH/common/property-functions"
source "$PLUGIN_AVAILABLE_PATH/proxy/command-functions"
source "$PLUGIN_AVAILABLE_PATH/caddy-vhosts/internal-functions"
set -eo pipefail
[[ $DOKKU_TRACE ]] && set -x
cmd-caddy-labels-add() {
declare desc="adds container label to app for specified proxy"
declare cmd="caddy:labels:add"
[[ "$1" == "$cmd" ]] && shift 1
cmd-proxy-labels-add "proxy:labels:add" "caddy" "$@"
}
cmd-caddy-labels-remove() {
declare desc="removes container label from app for specified proxy"
declare cmd="caddy:labels:remove"
[[ "$1" == "$cmd" ]] && shift 1
cmd-proxy-labels-remove "proxy:labels:remove" "caddy" "$@"
}
cmd-caddy-labels-show() {
declare desc="shows container labels for app for specified proxy"
declare cmd="caddy:labels:show"
[[ "$1" == "$cmd" ]] && shift 1
cmd-proxy-labels-show "proxy:labels:show" "caddy" "$@"
}
cmd-caddy-logs() {
declare desc="display caddy logs from command line"
declare cmd="caddy:logs"
[[ "$1" == "$cmd" ]] && shift 1
local NUM="100" TAIL=false
local TEMP=$(getopt -o htn: --long help,tail,num: -n 'dokku caddy:logs' -- "$@")
local EXIT_CODE="$?"
if [[ "$EXIT_CODE" != 0 ]]; then
fn-caddy-logs-usage >&2
exit 1
fi
eval set -- "$TEMP"
while true; do
case "$1" in
-t | --tail)
local TAIL=true
shift
;;
-n | --num)
local NUM="$2"
shift 2
;;
--)
shift
break
;;
*) dokku_log_fail "Internal error" ;;
esac
done
fn-caddy-logs "$TAIL" "$NUM"
}
cmd-caddy-show-config() {
declare desc="display caddy config"
declare cmd="caddy:show-config"
[[ "$1" == "$cmd" ]] && shift 1
if ! fn-is-compose-installed; then
dokku_log_fail "Required docker compose plugin is not installed"
fi
local TMP_COMPOSE_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
trap "rm -rf '$TMP_COMPOSE_FILE' >/dev/null" RETURN INT TERM EXIT
fn-caddy-template-compose-file "$TMP_COMPOSE_FILE"
cat "$TMP_COMPOSE_FILE"
}
cmd-caddy-start() {
declare desc="Starts the caddy server"
declare cmd="caddy:start"
[[ "$1" == "$cmd" ]] && shift 1
if ! fn-is-compose-installed; then
dokku_log_fail "Required docker compose plugin is not installed"
fi
local TMP_COMPOSE_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
trap "rm -rf '$TMP_COMPOSE_FILE' >/dev/null" RETURN INT TERM EXIT
fn-plugin-property-write "caddy" "--global" "proxy-status" "started"
fn-caddy-template-compose-file "$TMP_COMPOSE_FILE"
if ! "$PLUGIN_CORE_AVAILABLE_PATH/common/common" compose-up "caddy" "$TMP_COMPOSE_FILE"; then
return 1
fi
}
cmd-caddy-stop() {
declare desc="Stops the caddy server"
declare cmd="caddy:stop"
[[ "$1" == "$cmd" ]] && shift 1
if ! fn-is-compose-installed; then
dokku_log_fail "Required docker compose plugin is not installed"
fi
local TMP_COMPOSE_FILE=$(mktemp "/tmp/dokku-${DOKKU_PID}-${FUNCNAME[0]}.XXXXXX")
trap "rm -rf '$TMP_COMPOSE_FILE' >/dev/null" RETURN INT TERM EXIT
fn-plugin-property-write "caddy" "--global" "proxy-status" "stopped"
fn-caddy-template-compose-file "$TMP_COMPOSE_FILE"
if ! "$PLUGIN_CORE_AVAILABLE_PATH/common/common" compose-down "caddy" "$TMP_COMPOSE_FILE"; then
return 1
fi
}