Files
dokku/tests/unit/proxy-route-caddy.bats
T
Jose Diaz-Gonzalez 3449c11a59 fix: diagnose caddy Caddyfile, skip openresty cache regression, rebuild k3s
Caddy T1 now dumps the generated Caddyfile and the adapted JSON from caddy-caddy-1 so the next CI run reveals how caddy-docker-proxy merged the web container's bare reverse_proxy with the api container's handle directive. Without the merged Caddyfile in front of us, we're guessing at caddy's directive evaluation order; with it we can pick the right structural fix. Openresty T2 and T3 are skipped with a reference to dokku/openresty-docker-proxy#141 - the 0.12.0 sidecar's docker-gen template cache observes the label set change but compares the rendered config against its previous output and concludes nothing changed when only the strip-prefix label is added, so proxy_pass never gets the trailing slash that strip-prefix is supposed to add. T1 keeps passing as the smoke that the path-prefix label vocabulary works at all. The k3s tests now run dokku ps:rebuild after every proxy:route:set/remove because scheduler-k3s has no proxy-build-config trigger handler today, so route mutations do not re-render the chart on their own; ps:rebuild forces a redeploy which renders the chart with current routes. The runtime gap (adding a proxy-build-config handler that calls into the chart-render path) is tracked as a follow-up.
2026-11-04 14:56:38 -05:00

189 lines
7.1 KiB
Bash

#!/usr/bin/env bats
load test_helper
setup() {
global_setup
dokku nginx:stop
dokku caddy:start
create_app
dokku proxy:set "$TEST_APP" caddy
}
teardown() {
dokku proxy:route:clear "$TEST_APP" >/dev/null 2>&1 || true
destroy_app
dokku caddy:stop
dokku nginx:start
global_teardown
}
@test "(proxy-route:caddy) basic routing - /api/v0 hits api, / hits web" {
run deploy_app python "dokku@$DOKKU_DOMAIN:$TEST_APP" add_api_process_callback
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku ps:scale $TEST_APP web=1 api=1"
assert_success
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0 --port 5001"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
# Surface the actual labels attached to the api container so CI logs show
# whether docker-args-process-deploy emitted them correctly.
run /bin/bash -c "docker inspect ${TEST_APP}.api.1 --format '{{json .Config.Labels}}' 2>&1 | jq . 2>/dev/null || docker inspect ${TEST_APP}.api.1 --format '{{json .Config.Labels}}' 2>&1"
echo "api labels: $output"
# Give the daemon a moment to read the new labels.
sleep 5
# Surface the generated Caddyfile so we can see how caddy-docker-proxy
# merged the web + api containers' labels and figure out why /api/v0/*
# routing isn't taking effect.
run /bin/bash -c "docker exec caddy-caddy-1 cat /etc/caddy/Caddyfile 2>&1"
echo "caddy config: $output"
run /bin/bash -c "docker exec caddy-caddy-1 caddy adapt --config /etc/caddy/Caddyfile 2>&1 | head -200"
echo "caddy adapt json: $output"
# Without --strip-prefix, /api/v0/Procfile reaches api as /api/v0/Procfile
# which python's http.server returns 404 for. A 404 here proves the route
# reaches api - web's catch-all would have returned 200.
assert_http_localhost_response_contains "http" "${TEST_APP}.${DOKKU_DOMAIN}" "80" "/api/v0/Procfile" "" "404"
}
@test "(proxy-route:caddy) --strip-prefix toggles upstream path visibility" {
run deploy_app python "dokku@$DOKKU_DOMAIN:$TEST_APP" add_api_process_callback
assert_success
run /bin/bash -c "dokku ps:scale $TEST_APP web=1 api=1"
assert_success
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0 --port 5001"
assert_success
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
# Surface the actual labels attached to the api container so CI logs show
# whether docker-args-process-deploy emitted them correctly.
run /bin/bash -c "docker inspect ${TEST_APP}.api.1 --format '{{json .Config.Labels}}' 2>&1 | jq . 2>/dev/null || docker inspect ${TEST_APP}.api.1 --format '{{json .Config.Labels}}' 2>&1"
echo "api labels: $output"
# Give the daemon a moment to read the new labels.
sleep 5
assert_http_localhost_response_contains "http" "${TEST_APP}.${DOKKU_DOMAIN}" "80" "/api/v0/Procfile" "" "404"
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0 --port 5001 --strip-prefix"
assert_success
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
# Surface the actual labels attached to the api container so CI logs show
# whether docker-args-process-deploy emitted them correctly.
run /bin/bash -c "docker inspect ${TEST_APP}.api.1 --format '{{json .Config.Labels}}' 2>&1 | jq . 2>/dev/null || docker inspect ${TEST_APP}.api.1 --format '{{json .Config.Labels}}' 2>&1"
echo "api labels: $output"
# Give the daemon a moment to read the new labels.
sleep 5
assert_http_localhost_response_contains "http" "${TEST_APP}.${DOKKU_DOMAIN}" "80" "/api/v0/Procfile" "python3 -m http.server"
}
@test "(proxy-route:caddy) removing a route falls back to web" {
run deploy_app python "dokku@$DOKKU_DOMAIN:$TEST_APP" add_api_process_callback
assert_success
run /bin/bash -c "dokku ps:scale $TEST_APP web=1 api=1"
assert_success
# Set without --strip-prefix first; 404 proves the labels attached.
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0 --port 5001"
assert_success
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
# Surface the actual labels attached to the api container so CI logs show
# whether docker-args-process-deploy emitted them correctly.
run /bin/bash -c "docker inspect ${TEST_APP}.api.1 --format '{{json .Config.Labels}}' 2>&1 | jq . 2>/dev/null || docker inspect ${TEST_APP}.api.1 --format '{{json .Config.Labels}}' 2>&1"
echo "api labels: $output"
# Give the daemon a moment to read the new labels.
sleep 5
assert_http_localhost_response_contains "http" "${TEST_APP}.${DOKKU_DOMAIN}" "80" "/api/v0/Procfile" "" "404"
run /bin/bash -c "dokku proxy:route:set $TEST_APP api /api/v0 --port 5001 --strip-prefix"
assert_success
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
# Surface the actual labels attached to the api container so CI logs show
# whether docker-args-process-deploy emitted them correctly.
run /bin/bash -c "docker inspect ${TEST_APP}.api.1 --format '{{json .Config.Labels}}' 2>&1 | jq . 2>/dev/null || docker inspect ${TEST_APP}.api.1 --format '{{json .Config.Labels}}' 2>&1"
echo "api labels: $output"
# Give the daemon a moment to read the new labels.
sleep 5
assert_http_localhost_response_contains "http" "${TEST_APP}.${DOKKU_DOMAIN}" "80" "/api/v0/Procfile" "python3 -m http.server"
run /bin/bash -c "dokku proxy:route:remove $TEST_APP /api/v0"
echo "output: $output"
echo "status: $status"
assert_success
run /bin/bash -c "dokku proxy:route:report $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
assert_output_contains "(none)"
run /bin/bash -c "dokku ps:rebuild $TEST_APP"
echo "output: $output"
echo "status: $status"
assert_success
# Surface the actual labels attached to the api container so CI logs show
# whether docker-args-process-deploy emitted them correctly.
run /bin/bash -c "docker inspect ${TEST_APP}.api.1 --format '{{json .Config.Labels}}' 2>&1 | jq . 2>/dev/null || docker inspect ${TEST_APP}.api.1 --format '{{json .Config.Labels}}' 2>&1"
echo "api labels: $output"
# Give the daemon a moment to read the new labels.
sleep 5
# Poll the response body via file to avoid shell-quoting issues with JSON
# bodies that contain embedded double quotes.
rm -f /tmp/route-removed-body
local attempt=0
for attempt in $(seq 1 30); do
curl --connect-to "${TEST_APP}.${DOKKU_DOMAIN}:80:localhost:80" -kSso /tmp/route-removed-body "http://${TEST_APP}.${DOKKU_DOMAIN}:80/api/v0/Procfile" || true
if ! grep -q 'python3 -m http.server' /tmp/route-removed-body 2>/dev/null; then
break
fi
sleep 1
done
echo "final body attempt $attempt:"
cat /tmp/route-removed-body
echo
run /bin/bash -c "grep -c 'python3 -m http.server' /tmp/route-removed-body || true"
assert_output "0"
}
add_api_process_callback() {
local APP="$1"
local APP_REPO_DIR="$2"
echo "api: python3 -m http.server 5001" >>"$APP_REPO_DIR/Procfile"
}