refactor: store labels in key=value format
This makes it easier to display at the cost of removing the override warnings (for now).
This commit is contained in:
@@ -130,12 +130,11 @@ trigger-caddy-vhosts-docker-args-process-deploy() {
|
||||
fi
|
||||
|
||||
local proxy_labels_file_path=$(fn-proxy-get-labels-file-path "caddy" "$APP")
|
||||
fn-proxy-report-label-overwrite "$output" "$proxy_labels_file_path"
|
||||
|
||||
if [[ -f "$proxy_labels_file_path" ]]; then
|
||||
local user_proxy_labels="$(<"$proxy_labels_file_path")"
|
||||
user_proxy_labels="$(echo "$user_proxy_labels" | tr '\r\n' ' ')"
|
||||
output="$output $user_proxy_labels"
|
||||
while read -r line; do
|
||||
[[ -z "$line" ]] && continue
|
||||
output="$output --label '$line'"
|
||||
done <"$proxy_labels_file_path"
|
||||
fi
|
||||
|
||||
echo -n "$STDIN$output"
|
||||
|
||||
@@ -125,12 +125,11 @@ trigger-haproxy-vhosts-docker-args-process-deploy() {
|
||||
fi
|
||||
|
||||
local proxy_labels_file_path=$(fn-proxy-get-labels-file-path "haproxy" "$APP")
|
||||
fn-proxy-report-label-overwrite "$output" "$proxy_labels_file_path"
|
||||
|
||||
if [[ -f "$proxy_labels_file_path" ]]; then
|
||||
local user_proxy_labels="$(<"$proxy_labels_file_path")"
|
||||
user_proxy_labels="$(echo "$user_proxy_labels" | tr '\r\n' ' ')"
|
||||
output="$output $user_proxy_labels"
|
||||
while read -r line; do
|
||||
[[ -z "$line" ]] && continue
|
||||
output="$output --label '$line'"
|
||||
done <"$proxy_labels_file_path"
|
||||
fi
|
||||
|
||||
echo -n "$STDIN$output"
|
||||
|
||||
@@ -183,12 +183,11 @@ trigger-openresty-vhosts-docker-args-process-deploy() {
|
||||
[[ -n "$value" ]] && output="$output '--label=openresty.x-forwarded-ssl=$value'"
|
||||
|
||||
local proxy_labels_file_path=$(fn-proxy-get-labels-file-path "openresty" "$APP")
|
||||
fn-proxy-report-label-overwrite "$output" "$proxy_labels_file_path"
|
||||
|
||||
if [[ -f "$proxy_labels_file_path" ]]; then
|
||||
local user_proxy_labels="$(<"$proxy_labels_file_path")"
|
||||
user_proxy_labels="$(echo "$user_proxy_labels" | tr '\r\n' ' ')"
|
||||
output="$output $user_proxy_labels"
|
||||
while read -r line; do
|
||||
[[ -z "$line" ]] && continue
|
||||
output="$output --label '$line'"
|
||||
done <"$proxy_labels_file_path"
|
||||
fi
|
||||
|
||||
echo -n "$STDIN$output"
|
||||
|
||||
@@ -35,7 +35,7 @@ cmd-proxy-labels-add() {
|
||||
local proxy_labels_file_path="$(fn-proxy-get-labels-file-path "$PROXY" "$APP")"
|
||||
touch "$proxy_labels_file_path"
|
||||
cmd-proxy-labels-remove "$PROXY" "$APP" "$PASSED_LABEL_NAME" >/dev/null
|
||||
echo "--label '${PASSED_LABEL_NAME}=${PASSED_LABEL_VALUE}' " >>"$proxy_labels_file_path"
|
||||
echo "${PASSED_LABEL_NAME}=${PASSED_LABEL_VALUE}" >>"$proxy_labels_file_path"
|
||||
local all_proxy_labels="$(<"$proxy_labels_file_path")"
|
||||
echo -e "${all_proxy_labels}" | sed '/^$/d' | sort -u >"$proxy_labels_file_path"
|
||||
}
|
||||
@@ -57,6 +57,6 @@ cmd-proxy-labels-remove() {
|
||||
|
||||
local all_proxy_labels="$(<"$proxy_labels_file_path")"
|
||||
local escaped_label_name="$(fn-proxy-escape-extended-sed "$PASSED_LABEL_NAME")"
|
||||
local all_proxy_labels="$(echo -e "${all_proxy_labels}" | sed -E "s/^--label ['\"]${escaped_label_name}=.*\$//")"
|
||||
local all_proxy_labels="$(echo -e "${all_proxy_labels}" | sed -E "s/^${escaped_label_name}=.*\$//")"
|
||||
echo -e "${all_proxy_labels}" | sed '/^$/d' | sort -u >"$proxy_labels_file_path"
|
||||
}
|
||||
|
||||
@@ -9,41 +9,6 @@ fn-proxy-escape-extended-sed() {
|
||||
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/")"
|
||||
local escaped_label_name="$(fn-proxy-escape-extended-sed "$label_name")"
|
||||
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"
|
||||
@@ -56,8 +21,24 @@ 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")"
|
||||
dokku_log_info2_quiet "${APP} ${PROXY} labels"
|
||||
sed -e 's/^/ /' "$proxy_labels_file_path"
|
||||
if [[ -s "$proxy_labels_file_path" ]]; then
|
||||
dokku_log_info2_quiet "${APP} ${PROXY} labels"
|
||||
while read -r line; do
|
||||
[[ -z "$line" ]] && continue
|
||||
|
||||
case "$line" in
|
||||
\#*)
|
||||
continue
|
||||
;;
|
||||
|
||||
*)
|
||||
dokku_log_verbose "$line"
|
||||
;;
|
||||
esac
|
||||
done <"$proxy_labels_file_path"
|
||||
else
|
||||
dokku_log_warn_quiet "No ${PROXY} labels set for ${APP}"
|
||||
fi
|
||||
}
|
||||
|
||||
fn-proxy-show-label() {
|
||||
@@ -71,7 +52,7 @@ fn-proxy-show-label() {
|
||||
|
||||
local all_proxy_labels="$(<"$proxy_labels_file_path")"
|
||||
local escaped_label_name="$(fn-proxy-escape-extended-sed "$PASSED_LABEL_NAME")"
|
||||
local proxy_label_value="$(echo -e "${all_proxy_labels}" | sed -E -n "s/^--label ['\"]${escaped_label_name}=(.*)['\"] \$/\1/p")"
|
||||
local proxy_label_value="$(echo -e "${all_proxy_labels}" | sed -E -n "s/^${escaped_label_name}=(.*)\$/\1/p")"
|
||||
|
||||
echo "$proxy_label_value"
|
||||
}
|
||||
|
||||
@@ -132,12 +132,11 @@ trigger-traefik-vhosts-docker-args-process-deploy() {
|
||||
fi
|
||||
|
||||
local proxy_labels_file_path=$(fn-proxy-get-labels-file-path "traefik" "$APP")
|
||||
fn-proxy-report-label-overwrite "$output" "$proxy_labels_file_path"
|
||||
|
||||
if [[ -f "$proxy_labels_file_path" ]]; then
|
||||
local user_proxy_labels="$(<"$proxy_labels_file_path")"
|
||||
user_proxy_labels="$(echo "$user_proxy_labels" | tr '\r\n' ' ')"
|
||||
output="$output $user_proxy_labels"
|
||||
while read -r line; do
|
||||
[[ -z "$line" ]] && continue
|
||||
output="$output --label '$line'"
|
||||
done <"$proxy_labels_file_path"
|
||||
fi
|
||||
|
||||
echo -n "$STDIN$output"
|
||||
|
||||
Reference in New Issue
Block a user