Hotfix rename woff files so redirect works better#1128
Conversation
WalkthroughRemoves three custom font mime registrations, adds a Dockerfile post-assets-precompile step that creates short-name aliases for fingerprinted assets in production-like builds, and sets webpack's output.assetModuleFilename to "[name][ext]" so emitted assets keep original base names with extensions. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Dev as Developer / CI
participant Docker as Docker build
participant Rails as Rails asset precompile
participant Post as Post-assets step
participant Webpack as Webpack (asset emit)
Dev->>Docker: start image build
Docker->>Rails: run assets:precompile
Rails->>Webpack: invoke bundling/emit
Webpack->>Webpack: emit assets using assetModuleFilename "[name][ext]"
Rails-->>Docker: precompile output (fingerprinted files)
Docker->>Post: run post-assets-precompile step (RAILS_ENV check)
Post->>Post: find public/assets/*-*.* → copy to short-name (preserve metadata, skip existing)
Post-->>Docker: finish
Docker-->>Dev: image built
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
Dockerfile(1 hunks)config/initializers/mime_types.rb(0 hunks)
💤 Files with no reviewable changes (1)
- config/initializers/mime_types.rb
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Build
🔇 Additional comments (1)
Dockerfile (1)
49-55: Asset filename pattern is correct for Rails 7.2.3.Verification confirms that Rails 7.2.3 uses the standard fingerprinting format
<name>-<fingerprint>.<ext>(with SHA-256 64-character digests). The script's glob pattern*-*.*correctly targets these versioned files, and the parameter expansion${base%%-*}correctly extracts the short name by removing everything from the first hyphen onward. This works correctly even when asset names contain multiple hyphens (e.g.,some-font-abc123...woff2→some.woff2).
| # create short-name copies like "abcdef-....woff2" -> "abcdef.woff2" for fonts and other assets | ||
| bash -lc 'for f in public/assets/*-*.*; do \ | ||
| [ -f \"$f\" ] || continue; \ | ||
| base=$(basename \"$f\"); \ | ||
| ext=\"${base##*.}\"; \ | ||
| short=\"${base%%-*}.${ext}\"; \ | ||
| if [ ! -e \"public/assets/$short\" ]; then cp --preserve=mode,timestamps \"$f\" \"public/assets/$short\"; fi; \ | ||
| done'; \ |
There was a problem hiding this comment.
Add explicit error handling to the bash script.
The post-assets-precompile script lacks error handling. If cp fails (e.g., due to permission issues), the Docker build continues silently with incomplete asset setup, which could cause runtime issues.
Apply this diff to add error handling:
# create short-name copies like "abcdef-....woff2" -> "abcdef.woff2" for fonts and other assets
bash -lc 'for f in public/assets/*-*.*; do \
[ -f "$f" ] || continue; \
base=$(basename "$f"); \
ext="${base##*.}"; \
short="${base%%-*}.${ext}"; \
if [ ! -e "public/assets/$short" ]; then cp --preserve=mode,timestamps "$f" "public/assets/$short"; fi; \
done';Suggested fix — wrap the script with error handling:
# create short-name copies like "abcdef-....woff2" -> "abcdef.woff2" for fonts and other assets
bash -lc 'set -e; \
for f in public/assets/*-*.*; do \
[ -f "$f" ] || continue; \
base=$(basename "$f"); \
ext="${base##*.}"; \
short="${base%%-*}.${ext}"; \
if [ ! -e "public/assets/$short" ]; then cp --preserve=mode,timestamps "$f" "public/assets/$short"; fi; \
done'; \This ensures the build fails immediately if any cp command encounters an error, rather than silently continuing with partial state.
🤖 Prompt for AI Agents
In Dockerfile around lines 48 to 55, the bash loop that copies short-name asset
files lacks error handling so a failing cp will be ignored and the build can
continue with incomplete assets; modify the script to fail fast (e.g., wrap the
command with a bash -euo pipefail environment or prepend set -e; set -o
pipefail) and ensure each cp failure causes the whole command to exit non-zero
(alternatively check cp's exit status and exit 1 on failure), so the Docker
build stops immediately if any copy fails.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## staging #1128 +/- ##
========================================
Coverage 75.27% 75.27%
========================================
Files 50 50
Lines 1076 1076
========================================
Hits 810 810
Misses 266 266 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Removed redundant asset short-name copying from Dockerfile.
Checklist
origin/staging(git checkout staging ; git pull ; bundle exec rails db:reset ; git checkout BRANCH ; bundle exec rails db:migrate).Summary
Shortly summarize the changes in this pull request. Does it concern changes in the UI, add some screenshots. Are there related issues solved? Please, mention them (with 'fixes #xyz', see https://github.com/blog/1506-closing-issues-via-pull-requests), so they can be resolved automatically when merging this pull request.
Other information
If there is some other relevant and important information for this pull request, mention it here. For example, related pull requests or newly introduced conventions, packages or other dependencies.
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.