Skip to content

Commit 90c1ecd

Browse files
jcormierclaude
andcommitted
assets: export RAILS_RELATIVE_URL_ROOT for rake-driven asset precompiles
When REDMINE_RELATIVE_URL_ROOT is a sub-URI, Propshaft bakes the prefix into url() refs inside compiled CSS at precompile time, reading it from RAILS_RELATIVE_URL_ROOT. puma.rb set it for the running app, but the entrypoint precompiles from rake-driven paths that don't load puma.rb (redmine:plugins:migrate, the redmine_detect_update boot hook), so those compiled a bare "/assets" prefix and every font/background referenced from inside CSS 404'd behind a sub-URI reverse proxy. Export it from env-defaults (sourced before anything runs) so every child process inherits it. Add test/relative-url-root-precompile.sh, which boots app:init under a sub-URI and asserts the compiled CSS has no bare /assets/ refs. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0fca8d6 commit 90c1ecd

2 files changed

Lines changed: 63 additions & 0 deletions

File tree

assets/runtime/env-defaults

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ REDMINE_BACKUPS_DIR=${REDMINE_BACKUPS_DIR:-$REDMINE_DATA_DIR/backups}
1515

1616
REDMINE_HTTPS=${REDMINE_HTTPS:-false}
1717
REDMINE_RELATIVE_URL_ROOT=${REDMINE_RELATIVE_URL_ROOT:-/}
18+
# Export for the rake-driven asset precompiles (redmine:plugins:migrate, the
19+
# redmine_detect_update boot hook) that don't load puma.rb; without it Propshaft
20+
# bakes a bare "/assets" prefix into CSS url()s and they 404 behind a sub-URI.
21+
if [[ ${REDMINE_RELATIVE_URL_ROOT} != / ]]; then
22+
export RAILS_RELATIVE_URL_ROOT=${REDMINE_RELATIVE_URL_ROOT}
23+
fi
1824
REDMINE_PORT=${REDMINE_PORT:-}
1925
if [[ $REDMINE_HTTPS == true ]]; then
2026
REDMINE_PORT=${REDMINE_PORT:-443}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/bash
2+
# Regression test for the REDMINE_RELATIVE_URL_ROOT asset-precompile bug:
3+
# compiled CSS url() refs must honour the sub-URI. Boots the image with
4+
# `app:init` under a sub-URI (sqlite3, single container) and asserts the
5+
# compiled application CSS has no bare /assets/ refs and >0 ${SUBURI}/assets/.
6+
#
7+
# Usage: ./test/relative-url-root-precompile.sh [image]
8+
# image docker image to test (default: sameersbn/redmine:<VERSION file>, the
9+
# tag the compose files build/publish)
10+
set -u
11+
12+
REPO="$(cd "$(dirname "$0")/.." && pwd)"
13+
SUBURI="/redmine"
14+
15+
IMAGE="${1:-sameersbn/redmine:$(cat "$REPO/VERSION")}"
16+
17+
C="relurl-precompile-test-$$"
18+
OUT="$(mktemp -d)"
19+
cleanup() { docker rm -f "$C" >/dev/null 2>&1; rm -rf "$OUT"; }
20+
trap cleanup EXIT
21+
22+
echo ">>> Testing image: $IMAGE (REDMINE_RELATIVE_URL_ROOT=$SUBURI)"
23+
docker rm -f "$C" >/dev/null 2>&1
24+
25+
# app:init -> install_plugins -> redmine:plugins:migrate boots Rails and
26+
# triggers the precompile this bug lives in.
27+
if ! docker run --name "$C" \
28+
-e DB_ADAPTER=sqlite3 \
29+
-e REDMINE_RELATIVE_URL_ROOT="$SUBURI" \
30+
"$IMAGE" app:init > "$OUT/init.log" 2>&1; then
31+
echo "FAIL: app:init did not complete cleanly"; tail -20 "$OUT/init.log"; exit 1
32+
fi
33+
34+
# public/assets is a symlink into the data volume; read the real path.
35+
docker cp "$C:/home/redmine/data/tmp/assets/." "$OUT/assets/" >/dev/null 2>&1
36+
37+
shopt -s nullglob
38+
css=("$OUT"/assets/application-*.css)
39+
if [ ${#css[@]} -eq 0 ]; then
40+
echo "FAIL: no compiled application-*.css found in the container"; exit 1
41+
fi
42+
echo " compiled CSS: $(basename "${css[0]}")"
43+
44+
# Bare "/assets/..." is the bug; "${SUBURI}/assets/..." is correct.
45+
bare=$(grep -hoE 'url\(["'"'"']?/assets/' "${css[@]}" | wc -l | tr -d ' ')
46+
sub=$( grep -hoE "url\\([\"']?${SUBURI}/assets/" "${css[@]}" | wc -l | tr -d ' ')
47+
echo " bare url(/assets/...) refs : $bare (want 0)"
48+
echo " sub-URI url(${SUBURI}/assets/...) refs : $sub (want >0)"
49+
50+
if [ "$bare" -ne 0 ] || [ "$sub" -eq 0 ]; then
51+
echo "FAIL: compiled CSS ignores REDMINE_RELATIVE_URL_ROOT"
52+
echo " sample offending refs:"
53+
grep -hoE 'url\(["'"'"']?/assets/[^)]*\)' "${css[@]}" | sort -u | head -5 | sed 's/^/ /'
54+
exit 1
55+
fi
56+
57+
echo "PASS: every compiled url() asset ref uses the ${SUBURI}/assets/ prefix"

0 commit comments

Comments
 (0)