Traefik was setting an explicit priority equal to the path length, which is smaller than traefik's default priority (rule length) on the web container. Web's bare Host(...) rule has implicit priority ~40 while my explicit 7 lost the match, so /api/v0/Procfile always went to web. Dropping the explicit priority lets traefik use rule length, which already gives longest-prefix-wins because the route rule includes both Host and PathPrefix and so is always longer than web's bare Host(...). Caddy's route block was being preempted by web's bare reverse_proxy due to caddy's default directive order (reverse_proxy ~190, route ~210). Switching to handle, which terminates matched requests and isn't bypassed by reverse_proxy, makes /api/v0/* land on api instead of web's catch-all. Openresty T2 polls longer (60 retries) and dumps sidecar logs on failure so the upstream label-update cache delay can be reported. The k3s files dump kubectl get service/ingress/endpoints in T1 so the next CI run reveals whether the api Service has ports and whether the Ingress backend reference is correct.
187 lines
7.1 KiB
Bash
187 lines
7.1 KiB
Bash
#!/usr/bin/env bats
|
|
|
|
load test_helper
|
|
|
|
setup() {
|
|
global_setup
|
|
dokku nginx:stop
|
|
dokku openresty:start
|
|
create_app
|
|
dokku proxy:set "$TEST_APP" openresty
|
|
}
|
|
|
|
teardown() {
|
|
dokku proxy:route:clear "$TEST_APP" >/dev/null 2>&1 || true
|
|
destroy_app
|
|
dokku openresty:stop
|
|
dokku nginx:start
|
|
global_teardown
|
|
}
|
|
|
|
@test "(proxy-route:openresty) 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
|
|
|
|
# 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:openresty) --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"
|
|
|
|
# openresty-docker-proxy 0.12.0 has a polling/caching delay before it
|
|
# re-renders the config after labels on an existing route key change.
|
|
# Give it a longer window than the default HTTP retry. If this still
|
|
# times out, dump the sidecar logs so we can file an upstream bug.
|
|
HTTP_ASSERT_RETRIES=60 assert_http_localhost_response_contains "http" "${TEST_APP}.${DOKKU_DOMAIN}" "80" "/api/v0/Procfile" "python3 -m http.server" || {
|
|
run /bin/bash -c "dokku openresty:logs --num 200 2>&1 || docker logs openresty-openresty-1 --tail 200 2>&1"
|
|
echo "openresty sidecar logs: $output"
|
|
return 1
|
|
}
|
|
}
|
|
|
|
@test "(proxy-route:openresty) 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"
|
|
}
|