2025-03-22 22:01:00 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
set -eo pipefail
|
|
|
|
|
[[ $DOKKU_TRACE ]] && set -x
|
|
|
|
|
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
|
|
|
|
|
|
|
|
|
fn-proxy-escape-extended-sed() {
|
|
|
|
|
# Escaped delimiter is '/'
|
|
|
|
|
local input="$1"
|
|
|
|
|
echo "$input" | sed -E 's#[][()\.^$?*+{}|/]#\\&#g'
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn-proxy-report-label-overwrite() {
|
|
|
|
|
declare desc="overwrite proxy labels file with new labels"
|
|
|
|
|
declare LABELS="$1" PROXY_LABELS_FILE_PATH="$2"
|
|
|
|
|
|
|
|
|
|
if [[ -f "$PROXY_LABELS_FILE_PATH" ]]; then
|
|
|
|
|
local DONE=false
|
|
|
|
|
until $DONE; do
|
|
|
|
|
local line
|
|
|
|
|
read -r line || local DONE=true
|
|
|
|
|
|
|
|
|
|
[[ -z "$line" ]] && continue
|
|
|
|
|
|
|
|
|
|
case "$line" in
|
|
|
|
|
\#*)
|
|
|
|
|
continue
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
--label*)
|
|
|
|
|
local label_name="$(echo "$line" | sed -E "s/^--label ['\"]([^=]+)=.*/\1/")"
|
2025-11-16 18:00:04 -05:00
|
|
|
local escaped_label_name="$(fn-proxy-escape-extended-sed "$label_name")"
|
2025-03-22 22:01:00 +00:00
|
|
|
local match="$(echo "$LABELS" | sed -E "s/.*--label ['\"]($escaped_label_name)=.*/\1/")"
|
|
|
|
|
if [[ -n "$match" ]]; then
|
|
|
|
|
dokku_log_warn "Dokku label \"$match\" will be overwritten by user-set proxy label."
|
|
|
|
|
fi
|
|
|
|
|
continue
|
|
|
|
|
;;
|
|
|
|
|
|
|
|
|
|
*)
|
|
|
|
|
dokku_log_warn "Invalid line '$line' in proxy label file $PROXY_FILE_PATH"
|
|
|
|
|
;;
|
|
|
|
|
esac
|
|
|
|
|
done <"$PROXY_LABELS_FILE_PATH"
|
|
|
|
|
fi
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn-proxy-get-labels-file-path() {
|
|
|
|
|
declare desc="return proxy labels config file path for specified proxy"
|
|
|
|
|
declare PROXY="$1" APP="$2"
|
2025-11-16 17:59:46 -05:00
|
|
|
local PROXY_FILE="${DOKKU_LIB_ROOT}/config/${PROXY}/${APP}/labels"
|
2025-03-22 22:01:00 +00:00
|
|
|
|
|
|
|
|
echo "$PROXY_FILE"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn-proxy-display-labels() {
|
|
|
|
|
declare desc="print user-set app container labels for specified proxy"
|
|
|
|
|
declare PROXY="$1" APP="$2"
|
|
|
|
|
local proxy_labels_file_path="$(fn-proxy-get-labels-file-path "$PROXY" "$APP")"
|
2025-11-16 18:12:38 -05:00
|
|
|
dokku_log_info2_quiet "${APP} ${PROXY} labels"
|
2025-03-22 22:01:00 +00:00
|
|
|
sed -e 's/^/ /' "$proxy_labels_file_path"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn-proxy-show-label() {
|
|
|
|
|
declare desc="print single user-set app container label for specified proxy"
|
|
|
|
|
declare PROXY="$1" APP="$2" PASSED_LABEL_NAME="$3"
|
|
|
|
|
|
|
|
|
|
local proxy_labels_file_path="$(fn-proxy-get-labels-file-path "$PROXY" "$APP")"
|
|
|
|
|
if [[ ! -s "$proxy_labels_file_path" ]]; then
|
|
|
|
|
return
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
local all_proxy_labels="$(<"$proxy_labels_file_path")"
|
2025-11-16 18:00:04 -05:00
|
|
|
local escaped_label_name="$(fn-proxy-escape-extended-sed "$PASSED_LABEL_NAME")"
|
2025-03-22 22:01:00 +00:00
|
|
|
local proxy_label_value="$(echo -e "${all_proxy_labels}" | sed -E -n "s/^--label ['\"]${escaped_label_name}=(.*)['\"] \$/\1/p")"
|
|
|
|
|
|
|
|
|
|
echo "$proxy_label_value"
|
|
|
|
|
}
|