diff --git a/.woodpecker/edge-subpath.yml b/.woodpecker/edge-subpath.yml index d649073..a5e59c7 100644 --- a/.woodpecker/edge-subpath.yml +++ b/.woodpecker/edge-subpath.yml @@ -7,9 +7,8 @@ # # Checks: # 1. shellcheck — syntax check on tests/smoke-edge-subpath.sh -# 2. caddy validate — validate the Caddyfile template syntax -# 3. caddyfile-routing-test — verify Caddyfile routing block shape -# 4. test-caddyfile-routing — run standalone unit test for Caddyfile structure +# 2. caddyfile-routing-test — verify Caddyfile routing block shape +# 3. test-caddyfile-routing — run standalone unit test for Caddyfile structure # # Triggers: # - Pull requests that modify edge-related files @@ -59,6 +58,7 @@ steps: echo '' echo ' # Reverse proxy to Forgejo' echo ' handle /forge/* {' + echo ' uri strip_prefix /forge' echo ' reverse_proxy 127.0.0.1:3000' echo ' }' echo '' @@ -94,23 +94,7 @@ steps: cp edge-render/Caddyfile edge-render/Caddyfile.rendered echo "Caddyfile rendered successfully" - # ── 3. Caddy config validation ─────────────────────────────────────────── - # `caddy validate` checks Caddyfile syntax and configuration. - # This validates the rendered Caddyfile against Caddy's parser. - # Exit codes: - # 0 — configuration is valid - # 1 — configuration has errors - - name: caddy-validate - image: alpine:3.19 - failure: ignore - commands: - - apk add --no-cache ca-certificates curl - - curl -fsSL --connect-timeout 10 --max-time 60 -o /tmp/caddy "https://caddyserver.com/api/download?os=linux&arch=amd64" - - chmod +x /tmp/caddy - - /tmp/caddy version - - /tmp/caddy validate --config edge-render/Caddyfile.rendered --adapter caddyfile - - # ── 4. Caddyfile routing block shape test ───────────────────────────────── + # ── 3. Caddyfile routing block shape test ───────────────────────────────── # Verify that the Caddyfile contains all required routing blocks: # - /forge/ — Forgejo subpath # - /ci/ — Woodpecker subpath @@ -191,7 +175,7 @@ steps: exit 1 fi - # ── 5. Standalone Caddyfile routing test ───────────────────────────────── + # ── 4. Standalone Caddyfile routing test ───────────────────────────────── # Run the standalone unit test for Caddyfile routing block validation. # This test extracts the Caddyfile template from edge.hcl and validates # its structure without requiring a running Caddy instance. diff --git a/lib/generators.sh b/lib/generators.sh index 67ff830..9efd360 100644 --- a/lib/generators.sh +++ b/lib/generators.sh @@ -860,6 +860,7 @@ _generate_caddyfile_subpath() { # Reverse proxy to Forgejo handle /forge/* { + uri strip_prefix /forge reverse_proxy forgejo:3000 } diff --git a/nomad/jobs/edge.hcl b/nomad/jobs/edge.hcl index 67c474c..9371768 100644 --- a/nomad/jobs/edge.hcl +++ b/nomad/jobs/edge.hcl @@ -151,6 +151,7 @@ EOT # Reverse proxy to Forgejo handle /forge/* { + uri strip_prefix /forge reverse_proxy 127.0.0.1:3000 } diff --git a/tests/test-caddyfile-routing.sh b/tests/test-caddyfile-routing.sh index 7eea806..9a04eec 100755 --- a/tests/test-caddyfile-routing.sh +++ b/tests/test-caddyfile-routing.sh @@ -89,6 +89,13 @@ check_forgejo_routing() { tr_fail "Missing Forgejo handle block (handle /forge/*)" fi + # Check uri strip_prefix /forge (required for Forgejo routing) + if echo "$CADDYFILE" | grep -q "uri strip_prefix /forge"; then + tr_pass "Forgejo strip_prefix configured (/forge)" + else + tr_fail "Missing Forgejo strip_prefix (/forge)" + fi + # Check reverse_proxy to Forgejo on port 3000 if echo "$CADDYFILE" | grep -q "reverse_proxy 127.0.0.1:3000"; then tr_pass "Forgejo reverse_proxy configured (127.0.0.1:3000)"