fix: deflake haproxy bats tests

The byjg/easy-haproxy image polls Docker for label changes every 10
seconds by default, which races with the haproxy bats suite and
intermittently produces curl exit 7. Expose `refresh-conf` as a
global-only haproxy property that maps to `EASYHAPROXY_REFRESH_CONF`,
lower it to 2 seconds in the bats setup, and wrap the localhost HTTP
assertions in a retry loop so checks wait for haproxy to converge
rather than failing on the first attempt.
This commit is contained in:
Jose Diaz-Gonzalez
2026-04-30 15:03:40 -04:00
parent 8f8a23aac3
commit 53ef8c7780
7 changed files with 81 additions and 13 deletions

View File

@@ -72,6 +72,7 @@ cmd-haproxy-report-single() {
"--haproxy-letsencrypt-email: $(fn-haproxy-letsencrypt-email)"
"--haproxy-letsencrypt-server: $(fn-haproxy-letsencrypt-server)"
"--haproxy-log-level: $(fn-haproxy-log-level)"
"--haproxy-refresh-conf: $(fn-haproxy-refresh-conf)"
)
fn-report-validate-format "$FORMAT" "$INFO_FLAG"

View File

@@ -38,7 +38,8 @@ fn-haproxy-template-compose-file() {
local SIGIL_PARAMS=(HAPROXY_IMAGE="$(fn-haproxy-image)"
HAPROXY_LOG_LEVEL="$(fn-haproxy-log-level)"
HAPROXY_LETSENCRYPT_EMAIL="$(fn-haproxy-letsencrypt-email)"
HAPROXY_LETSENCRYPT_SERVER="$(fn-haproxy-letsencrypt-server)")
HAPROXY_LETSENCRYPT_SERVER="$(fn-haproxy-letsencrypt-server)"
HAPROXY_REFRESH_CONF="$(fn-haproxy-refresh-conf)")
sigil -f "$COMPOSE_TEMPLATE" "${SIGIL_PARAMS[@]}" | cat -s >"$OUTPUT_PATH"
}
@@ -60,3 +61,7 @@ fn-haproxy-letsencrypt-email() {
fn-haproxy-letsencrypt-server() {
fn-plugin-property-get-default "haproxy" "--global" "letsencrypt-server" "https://acme-v02.api.letsencrypt.org/directory"
}
fn-haproxy-refresh-conf() {
fn-plugin-property-get-default "haproxy" "--global" "refresh-conf" "10"
}

View File

@@ -9,13 +9,14 @@ cmd-haproxy-set() {
declare cmd="haproxy:set"
[[ "$1" == "$cmd" ]] && shift 1
declare APP="$1" KEY="$2" VALUE="$3"
local VALID_KEYS=("image" "log-level" "letsencrypt-email" "letsencrypt-server")
local GLOBAL_KEYS=("image" "log-level" "letsencrypt-email" "letsencrypt-server")
local VALID_KEYS=("image" "log-level" "letsencrypt-email" "letsencrypt-server" "refresh-conf")
local GLOBAL_KEYS=("image" "log-level" "letsencrypt-email" "letsencrypt-server" "refresh-conf")
local GLOBAL_ONLY_KEYS=("refresh-conf")
[[ -z "$KEY" ]] && dokku_log_fail "No key specified"
if ! fn-in-array "$KEY" "${VALID_KEYS[@]}"; then
dokku_log_fail "Invalid key specified, valid keys include: image log-level letsencrypt-email letsencrypt-server"
dokku_log_fail "Invalid key specified, valid keys include: image log-level letsencrypt-email letsencrypt-server refresh-conf"
fi
if ! fn-in-array "$KEY" "${GLOBAL_KEYS[@]}"; then
@@ -25,6 +26,10 @@ cmd-haproxy-set() {
verify_app_name "$APP"
fi
if fn-in-array "$KEY" "${GLOBAL_ONLY_KEYS[@]}" && [[ "$APP" != "--global" ]]; then
dokku_log_fail "The key '$KEY' can only be set globally"
fi
if [[ -n "$VALUE" ]]; then
dokku_log_info2_quiet "Setting ${KEY} to ${VALUE}"
fn-plugin-property-write "haproxy" "$APP" "$KEY" "$VALUE"

View File

@@ -7,6 +7,7 @@ services:
- EASYHAPROXY_DISCOVER=docker
- EASYHAPROXY_LABEL_PREFIX=haproxy
- EASYHAPROXY_LOG_LEVEL={{ $.HAPROXY_LOG_LEVEL }}
- EASYHAPROXY_REFRESH_CONF={{ $.HAPROXY_REFRESH_CONF }}
- CERTBOT_LOG_LEVEL={{ $.HAPROXY_LOG_LEVEL }}
- HAPROXY_LOG_LEVEL={{ $.HAPROXY_LOG_LEVEL }}
{{ if $.HAPROXY_LETSENCRYPT_EMAIL }}