Merge pull request #9083 from dokku/8974-caddy-vhosts-requests-are-routed-before-healthchecks-pass-on-docker-local-contrary-to-docs
Add proxy health checks from app.json readiness
This commit is contained in:
19 files changed
+895
-47
No files matched your search
File renamed without changes.
@@ -6,7 +6,8 @@ load test_helper
|
||||
# Stubs plugn and plugin sources so the trigger can run without a Dokku install.
|
||||
|
||||
setup() {
|
||||
TRIGGER="$(cd "$BATS_TEST_DIRNAME/../.." && pwd)/plugins/caddy-vhosts/docker-args-process-deploy"
|
||||
REPO_ROOT="$(cd "$BATS_TEST_DIRNAME/../.." && pwd)"
|
||||
TRIGGER="$REPO_ROOT/plugins/caddy-vhosts/docker-args-process-deploy"
|
||||
STUB_ROOT="$BATS_TEST_TMPDIR/stub"
|
||||
mkdir -p "$STUB_ROOT/bin" \
|
||||
"$STUB_ROOT/core/common" \
|
||||
@@ -16,10 +17,17 @@ setup() {
|
||||
cat >"$STUB_ROOT/core/common/functions" <<'EOF'
|
||||
#!/usr/bin/env bash
|
||||
dokku_log_warn() { echo "WARN: $*" >&2; }
|
||||
dokku_log_fail() {
|
||||
echo "FAIL: $*" >&2
|
||||
exit 1
|
||||
}
|
||||
EOF
|
||||
|
||||
cat >"$STUB_ROOT/plugins/proxy/functions" <<'EOF'
|
||||
cat >"$STUB_ROOT/plugins/proxy/functions" <<EOF
|
||||
#!/usr/bin/env bash
|
||||
source "$REPO_ROOT/plugins/proxy/functions"
|
||||
EOF
|
||||
cat >>"$STUB_ROOT/plugins/proxy/functions" <<'EOF'
|
||||
fn-proxy-get-labels-file-path() {
|
||||
echo "${STUB_LABELS_FILE:-/nonexistent}"
|
||||
}
|
||||
@@ -67,6 +75,9 @@ case "$cmd" in
|
||||
printf '%s\n' "$STUB_DOMAINS"
|
||||
fi
|
||||
;;
|
||||
app-json-get-content)
|
||||
echo "${STUB_APP_JSON:-{\}}"
|
||||
;;
|
||||
*)
|
||||
echo "unexpected plugn trigger: $cmd $*" >&2
|
||||
exit 1
|
||||
@@ -89,6 +100,7 @@ invoke_caddy_docker_args() {
|
||||
STUB_PROXY_ENABLED="${STUB_PROXY_ENABLED:-true}" \
|
||||
STUB_VHOST_ENABLED="${STUB_VHOST_ENABLED:-true}" \
|
||||
STUB_LABELS_FILE="${STUB_LABELS_FILE:-/nonexistent}" \
|
||||
STUB_APP_JSON="${STUB_APP_JSON:-}" \
|
||||
bash "$TRIGGER" "${APP_NAME:-testapp}" "dockerfile" "latest" "${PROC_TYPE:-web}" "1" <<<"${STDIN_DATA:-}"
|
||||
}
|
||||
|
||||
@@ -130,3 +142,170 @@ invoke_caddy_docker_args() {
|
||||
assert_success
|
||||
assert_output_contains "caddy.reverse_proxy"
|
||||
}
|
||||
|
||||
@test "(caddy-vhosts) readiness healthcheck emits health and retry labels" {
|
||||
STUB_DOMAINS="example.com"
|
||||
STUB_PORTS="http:80:5000"
|
||||
STUB_APP_JSON='{"healthchecks":{"web":[{"type":"readiness","path":"/health","timeout":3,"wait":2}]}}'
|
||||
|
||||
run invoke_caddy_docker_args
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains '--label "caddy.reverse_proxy.health_uri=/health"'
|
||||
assert_output_contains "--label caddy.reverse_proxy.health_interval=2s"
|
||||
assert_output_contains "--label caddy.reverse_proxy.health_timeout=3s"
|
||||
assert_output_contains "--label caddy.reverse_proxy.health_headers.Host=example.com"
|
||||
assert_output_contains "--label caddy.reverse_proxy.lb_try_duration=5s"
|
||||
assert_output_contains "--label caddy.reverse_proxy.lb_try_interval=250ms"
|
||||
assert_output_contains "health_port" 0
|
||||
}
|
||||
|
||||
@test "(caddy-vhosts) readiness healthcheck defaults and port" {
|
||||
STUB_DOMAINS="example.com"
|
||||
STUB_PORTS="http:80:5000"
|
||||
STUB_APP_JSON='{"healthchecks":{"web":[{"type":"readiness","path":"/","port":5001}]}}'
|
||||
|
||||
run invoke_caddy_docker_args
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "--label caddy.reverse_proxy.health_port=5001"
|
||||
assert_output_contains "--label caddy.reverse_proxy.health_interval=5s"
|
||||
assert_output_contains "--label caddy.reverse_proxy.health_timeout=5s"
|
||||
}
|
||||
|
||||
@test "(caddy-vhosts) healthcheck host header skips localhost and catch-all domains" {
|
||||
STUB_DOMAINS="localhost * app.example.com other.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_headers.Host=app.example.com"
|
||||
}
|
||||
|
||||
@test "(caddy-vhosts) startup healthcheck emits no health or retry labels" {
|
||||
STUB_DOMAINS="example.com"
|
||||
STUB_PORTS="http:80:5000"
|
||||
STUB_APP_JSON='{"healthchecks":{"web":[{"type":"startup","path":"/"}]}}'
|
||||
|
||||
run invoke_caddy_docker_args
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "caddy.reverse_proxy="
|
||||
assert_output_contains "health_" 0
|
||||
assert_output_contains "lb_try_" 0
|
||||
}
|
||||
|
||||
@test "(caddy-vhosts) missing app.json emits no health or retry labels" {
|
||||
STUB_DOMAINS="example.com"
|
||||
STUB_PORTS="http:80:5000"
|
||||
|
||||
run invoke_caddy_docker_args
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "caddy.reverse_proxy="
|
||||
assert_output_contains "health_" 0
|
||||
assert_output_contains "lb_try_" 0
|
||||
}
|
||||
|
||||
@test "(caddy-vhosts) readiness healthcheck without routing labels emits no health labels" {
|
||||
STUB_DOMAINS="example.com"
|
||||
STUB_PORTS=""
|
||||
STUB_APP_JSON='{"healthchecks":{"web":[{"type":"readiness","path":"/"}]}}'
|
||||
|
||||
run invoke_caddy_docker_args
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "health_" 0
|
||||
}
|
||||
|
||||
@test "(caddy-vhosts) invalid readiness healthcheck path fails" {
|
||||
STUB_DOMAINS="example.com"
|
||||
STUB_PORTS="http:80:5000"
|
||||
STUB_APP_JSON='{"healthchecks":{"web":[{"type":"readiness","path":"/has space"}]}}'
|
||||
|
||||
run invoke_caddy_docker_args
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
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
|
||||
}
|
||||
@@ -452,3 +452,193 @@ teardown() {
|
||||
echo "status: $status"
|
||||
assert_output "0"
|
||||
}
|
||||
|
||||
@test "(caddy) healthcheck labels 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
|
||||
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_uri\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "/"
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"caddy.reverse_proxy.health_interval\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "2s"
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"caddy.reverse_proxy.health_timeout\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "5s"
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"caddy.reverse_proxy.health_headers.Host\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "$TEST_APP.$DOKKU_DOMAIN"
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"caddy.reverse_proxy.lb_try_duration\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "5s"
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"caddy.reverse_proxy.lb_try_interval\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "250ms"
|
||||
|
||||
assert_http_localhost_response "http" "$TEST_APP.dokku.me" "80" "" "python/http.server"
|
||||
|
||||
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
assert_http_localhost_response "http" "$TEST_APP.dokku.me" "80" "" "python/http.server"
|
||||
}
|
||||
|
||||
@test "(caddy) healthcheck labels can be overridden" {
|
||||
run /bin/bash -c "dokku proxy:set $TEST_APP caddy"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku caddy:labels:add $TEST_APP caddy.reverse_proxy.lb_try_duration 10s"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP setup_caddy_readiness_healthcheck
|
||||
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.lb_try_duration\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "10s"
|
||||
|
||||
assert_http_localhost_response "http" "$TEST_APP.dokku.me" "80" "" "python/http.server"
|
||||
}
|
||||
|
||||
@test "(caddy) no healthcheck labels without readiness check" {
|
||||
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 convert_to_dockerfile
|
||||
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_uri\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_not_exists
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"caddy.reverse_proxy.lb_try_duration\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_not_exists
|
||||
}
|
||||
|
||||
@test "(caddy) invalid stored healthcheck path fails restart" {
|
||||
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
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "jq '.healthchecks.web[0].path = \"/health check\"' /var/lib/dokku/data/app-json/$TEST_APP/app.json > /var/lib/dokku/data/app-json/$TEST_APP/app.json.tmp && mv /var/lib/dokku/data/app-json/$TEST_APP/app.json.tmp /var/lib/dokku/data/app-json/$TEST_APP/app.json"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku ps:restart $TEST_APP"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_failure
|
||||
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 cp caddy-caddy-1:/config/caddy/Caddyfile.autosave - | tar -xO"
|
||||
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"
|
||||
[[ -z "$APP" ]] && local APP="$TEST_APP"
|
||||
APP_REPO_DIR="$(realpath "$APP_REPO_DIR")"
|
||||
|
||||
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"
|
||||
}
|
||||
@@ -533,3 +533,28 @@ teardown() {
|
||||
assert_success
|
||||
assert_output "http:2019:2019 http:80:80 https:443:443 udp:443:443"
|
||||
}
|
||||
|
||||
@test "(domains) urls do not glob expand a catch-all domain" {
|
||||
local tmp_dir
|
||||
tmp_dir="$(mktemp -d)"
|
||||
touch "$tmp_dir/glob-canary"
|
||||
chmod 755 "$tmp_dir"
|
||||
|
||||
run /bin/bash -c "dokku proxy:set $TEST_APP caddy"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku domains:set $TEST_APP '*'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "cd $tmp_dir && dokku urls $TEST_APP"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
rm -rf "$tmp_dir"
|
||||
assert_success
|
||||
assert_output_contains "glob-canary" 0
|
||||
assert_output_contains "http://*"
|
||||
}
|
||||
@@ -760,6 +760,175 @@ teardown() {
|
||||
assert_output_not_exists
|
||||
}
|
||||
|
||||
@test "(openresty) healthcheck labels from app.json" {
|
||||
run /bin/bash -c "dokku proxy:set $TEST_APP openresty"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP setup_openresty_readiness_healthcheck
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"openresty.upstream-max-fails\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "1"
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"openresty.upstream-fail-timeout\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "2s"
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"openresty.proxy-next-upstream-timeout\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "5s"
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"openresty.healthcheck-path\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "/"
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"openresty.healthcheck-interval\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "2"
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"openresty.healthcheck-timeout\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "5"
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"openresty.healthcheck-fall\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "3"
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"openresty.healthcheck-host\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "$TEST_APP.dokku.me"
|
||||
|
||||
run /bin/bash -c "docker exec openresty-openresty-1 /usr/local/openresty/nginx/sbin/nginx -t"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "docker exec openresty-openresty-1 cat /etc/nginx/sites-enabled/sites.conf"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "max_fails=1 fail_timeout=2s;"
|
||||
assert_output_contains "proxy_next_upstream_timeout 5s;"
|
||||
|
||||
sleep 5
|
||||
|
||||
run /bin/bash -c "docker exec openresty-openresty-1 wget -qO- http://127.0.0.1:8999/upstream-healthcheck-status"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_contains "Upstream $TEST_APP-web-5000"
|
||||
assert_output_contains " UP"
|
||||
assert_output_contains "(NO checkers)" 0
|
||||
|
||||
assert_http_localhost_response "http" "$TEST_APP.dokku.me" "80" "" "python/http.server"
|
||||
}
|
||||
|
||||
@test "(openresty) no healthcheck labels without readiness check" {
|
||||
run /bin/bash -c "dokku proxy:set $TEST_APP openresty"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP convert_to_dockerfile
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"openresty.upstream-max-fails\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_not_exists
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"openresty.proxy-next-upstream-timeout\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_not_exists
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"openresty.healthcheck-path\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_not_exists
|
||||
}
|
||||
|
||||
@test "(openresty) healthcheck headers from app.json" {
|
||||
run /bin/bash -c "dokku proxy:set $TEST_APP openresty"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP setup_openresty_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 \"openresty.healthcheck-header.X-Check\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "dokku"
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"openresty.healthcheck-host\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output "check.dokku.me"
|
||||
|
||||
run /bin/bash -c "docker inspect $TEST_APP.web.1 --format '{{ index .Config.Labels \"openresty.healthcheck-header.Host\" }}'"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
assert_output_not_exists
|
||||
|
||||
assert_http_localhost_response "http" "$TEST_APP.dokku.me" "80" "" "python/http.server"
|
||||
}
|
||||
|
||||
@test "(openresty) invalid stored healthcheck path fails restart" {
|
||||
run /bin/bash -c "dokku proxy:set $TEST_APP openresty"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run deploy_app python dokku@$DOKKU_DOMAIN:$TEST_APP setup_openresty_readiness_healthcheck
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "jq '.healthchecks.web[0].path = \"/health check\"' /var/lib/dokku/data/app-json/$TEST_APP/app.json > /var/lib/dokku/data/app-json/$TEST_APP/app.json.tmp && mv /var/lib/dokku/data/app-json/$TEST_APP/app.json.tmp /var/lib/dokku/data/app-json/$TEST_APP/app.json"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run /bin/bash -c "dokku ps:restart $TEST_APP"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_failure
|
||||
assert_output_contains "Invalid app.json healthcheck path for openresty" -1
|
||||
}
|
||||
|
||||
add_openresty_include() {
|
||||
local APP="$1"
|
||||
local APP_REPO_DIR="$2"
|
||||
@@ -786,3 +955,23 @@ add_openresty_include_unsafe() {
|
||||
mkdir -p "$APP_REPO_DIR/openresty/http-location-includes"
|
||||
printf '# location\n' >"$APP_REPO_DIR/openresty/http-location-includes/unsafe filename.conf"
|
||||
}
|
||||
|
||||
setup_openresty_readiness_healthcheck() {
|
||||
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"
|
||||
mv "$APP_REPO_DIR/app-readiness.json" "$APP_REPO_DIR/app.json"
|
||||
}
|
||||
|
||||
setup_openresty_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].httpHeaders = [{"name": "X-Check", "value": "dokku"}, {"name": "Host", "value": "check.dokku.me"}]' "$APP_REPO_DIR/app-readiness.json" >"$APP_REPO_DIR/app.json"
|
||||
}
|
||||
@@ -943,7 +943,7 @@ setup_traefik_healthcheck() {
|
||||
[[ -z "$APP" ]] && local APP="$TEST_APP"
|
||||
APP_REPO_DIR="$(realpath "$APP_REPO_DIR")"
|
||||
|
||||
mv "$APP_REPO_DIR/app-traefik.json" "$APP_REPO_DIR/app.json"
|
||||
mv "$APP_REPO_DIR/app-readiness.json" "$APP_REPO_DIR/app.json"
|
||||
}
|
||||
|
||||
setup_traefik_healthcheck_whitespace_path() {
|
||||
@@ -952,7 +952,7 @@ setup_traefik_healthcheck_whitespace_path() {
|
||||
[[ -z "$APP" ]] && local APP="$TEST_APP"
|
||||
APP_REPO_DIR="$(realpath "$APP_REPO_DIR")"
|
||||
|
||||
jq '.healthchecks.web[0].path = "/health check"' "$APP_REPO_DIR/app-traefik.json" >"$APP_REPO_DIR/app.json"
|
||||
jq '.healthchecks.web[0].path = "/health check"' "$APP_REPO_DIR/app-readiness.json" >"$APP_REPO_DIR/app.json"
|
||||
}
|
||||
|
||||
setup_traefik_healthcheck_invalid_scheme() {
|
||||
@@ -961,5 +961,5 @@ setup_traefik_healthcheck_invalid_scheme() {
|
||||
[[ -z "$APP" ]] && local APP="$TEST_APP"
|
||||
APP_REPO_DIR="$(realpath "$APP_REPO_DIR")"
|
||||
|
||||
jq '.healthchecks.web[0].scheme = "tcp"' "$APP_REPO_DIR/app-traefik.json" >"$APP_REPO_DIR/app.json"
|
||||
jq '.healthchecks.web[0].scheme = "tcp"' "$APP_REPO_DIR/app-readiness.json" >"$APP_REPO_DIR/app.json"
|
||||
}
|
||||
Reference in new issue
Block a user