fix: map caddy healthcheck headers and apply tls-internal
Caddy healthchecks now honor the `attempts` and `httpHeaders` properties of the `app.json` readiness healthcheck, matching openresty. The `tls-internal` property was also never applied to app containers, and now takes effect for apps served over https.
This commit is contained in:
6 files changed
+205
-43
No files matched your search
@@ -237,3 +237,75 @@ invoke_caddy_docker_args() {
|
||||
assert_failure
|
||||
assert_output_contains "Invalid app.json healthcheck path for caddy"
|
||||
}
|
||||
|
||||
@test "(caddy-vhosts) readiness healthcheck maps attempts and headers" {
|
||||
STUB_DOMAINS="example.com"
|
||||
STUB_PORTS="http:80:5000"
|
||||
STUB_APP_JSON='{"healthchecks":{"web":[{"type":"readiness","path":"/","attempts":4,"httpHeaders":[{"name":"X-Check","value":"dokku check"},{"name":"host","value":"check.example.com"}]}]}}'
|
||||
|
||||
run invoke_caddy_docker_args
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "--label caddy.reverse_proxy.health_fails=4"
|
||||
assert_output_contains "--label 'caddy.reverse_proxy.health_headers.X-Check=\"dokku check\"'"
|
||||
assert_output_contains "--label caddy.reverse_proxy.health_headers.Host=check.example.com"
|
||||
assert_output_contains "health_headers.Host=example.com" 0
|
||||
assert_output_contains "health_headers.host" 0
|
||||
}
|
||||
|
||||
@test "(caddy-vhosts) readiness healthcheck defaults attempts to 3" {
|
||||
STUB_DOMAINS="example.com"
|
||||
STUB_PORTS="http:80:5000"
|
||||
STUB_APP_JSON='{"healthchecks":{"web":[{"type":"readiness","path":"/"}]}}'
|
||||
|
||||
run invoke_caddy_docker_args
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "--label caddy.reverse_proxy.health_fails=3"
|
||||
}
|
||||
|
||||
@test "(caddy-vhosts) invalid healthcheck headers are skipped" {
|
||||
STUB_DOMAINS="example.com"
|
||||
STUB_PORTS="http:80:5000"
|
||||
STUB_APP_JSON='{"healthchecks":{"web":[{"type":"readiness","path":"/","httpHeaders":[{"name":"X.Dotted","value":"a"},{"name":"X-Order_1","value":"a"},{"name":"X-Quote","value":"it'"'"'s"},{"name":"Bad Name","value":"a"},{"name":"X-Good","value":"ok"}]}]}}'
|
||||
|
||||
run invoke_caddy_docker_args
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "Skipping invalid app.json healthcheck header for caddy" 4
|
||||
assert_output_contains "health_headers.X-Good=" 1
|
||||
assert_output_contains "health_headers.X.Dotted" 0
|
||||
assert_output_contains "health_headers.X-Order_1" 0
|
||||
assert_output_contains "health_headers.X-Quote" 0
|
||||
}
|
||||
|
||||
@test "(caddy-vhosts) tls-internal emits caddy.tls=internal alongside https site labels" {
|
||||
STUB_DOMAINS="example.com"
|
||||
STUB_PORTS="$(printf 'http:80:5000\nhttps:443:5000')"
|
||||
STUB_LETSENCRYPT_EMAIL="admin@example.com"
|
||||
STUB_TLS_INTERNAL="true"
|
||||
|
||||
run invoke_caddy_docker_args
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "--label 'caddy=example.com'"
|
||||
assert_output_contains "--label caddy.tls=internal"
|
||||
assert_output_contains "caddy.reverse_proxy="
|
||||
}
|
||||
|
||||
@test "(caddy-vhosts) tls-internal does not emit caddy.tls=internal for http-only sites" {
|
||||
STUB_DOMAINS="example.com"
|
||||
STUB_PORTS="http:80:5000"
|
||||
STUB_TLS_INTERNAL="true"
|
||||
|
||||
run invoke_caddy_docker_args
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "--label 'caddy=example.com:80'"
|
||||
assert_output_contains "caddy.tls=internal" 0
|
||||
}
|
||||
@@ -582,6 +582,47 @@ teardown() {
|
||||
assert_output_contains "Invalid app.json healthcheck path for caddy" -1
|
||||
}
|
||||
|
||||
@test "(caddy) healthcheck headers from app.json" {
|
||||
run /bin/bash -c "dokku proxy:set $TEST_APP caddy"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP setup_caddy_readiness_healthcheck_headers
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"caddy.reverse_proxy.health_headers.X-Check\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output '"dokku check"'
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"caddy.reverse_proxy.health_fails\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "2"
|
||||
|
||||
sleep 5
|
||||
|
||||
run /bin/bash -c "docker exec caddy-caddy-1 cat /config/caddy/Caddyfile.autosave"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains 'X-Check "dokku check"'
|
||||
assert_output_contains "health_fails 2"
|
||||
|
||||
run /bin/bash -c "docker logs caddy-caddy-1"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "Failed to convert caddyfile" 0
|
||||
|
||||
assert_http_localhost_response "http" "$TEST_APP.dokku.me" "80" "" "python/http.server"
|
||||
}
|
||||
|
||||
setup_caddy_readiness_healthcheck() {
|
||||
local APP="$1"
|
||||
local APP_REPO_DIR="$2"
|
||||
@@ -591,3 +632,13 @@ setup_caddy_readiness_healthcheck() {
|
||||
convert_to_dockerfile "$APP" "$APP_REPO_DIR"
|
||||
mv "$APP_REPO_DIR/app-readiness.json" "$APP_REPO_DIR/app.json"
|
||||
}
|
||||
|
||||
setup_caddy_readiness_healthcheck_headers() {
|
||||
local APP="$1"
|
||||
local APP_REPO_DIR="$2"
|
||||
[[ -z "$APP" ]] && local APP="$TEST_APP"
|
||||
APP_REPO_DIR="$(realpath "$APP_REPO_DIR")"
|
||||
|
||||
convert_to_dockerfile "$APP" "$APP_REPO_DIR"
|
||||
jq '.healthchecks.web[0].attempts = 2 | .healthchecks.web[0].httpHeaders = [{"name": "X-Check", "value": "dokku check"}]' "$APP_REPO_DIR/app-readiness.json" >"$APP_REPO_DIR/app.json"
|
||||
}
|
||||
Reference in new issue
Block a user