- Регистрация
- 9 Май 2015
- Сообщения
- 1,483
- Баллы
- 155

You just typed git push heroku main with confidence.
Then... BOOM.
ERROR: Asset compilation failed or ENV_VAR not set.
Sound familiar? Let’s fix these deployment gremlins once and for all.
1. Asset Compilation: The Silent Killer (in Rails)
Why it fails:
- Missing dependencies (e.g., yarn not installed)
- Outdated Node/Ruby versions
- Path issues in deployment environment
The Fix:
# Precompile assets locally before deploying:
RAILS_ENV=production bundle exec rails assets:precompile
# Ensure Node.js & Yarn in deployment:
heroku buildpacks:add --index 1 heroku/nodejs
heroku buildpacks:add --index 2 heroku/ruby
Pro Tip: Add to package.json:
{
"scripts": {
"postinstall": "rails assets:precompile"
}
}
2. Environment Variables: The "It Works on My Machine" Trap
Classic Errors:
- Forgetting to set RAILS_ENV=production
- Typo in variable name (SECRET_KEY_BASE vs SECRET_KEY_BAS)
- Not restarting dynos after setting vars
The Fix:
# Set and VERIFY:
heroku config:set RAILS_ENV=production SECRET_KEY_BASE=$(rake secret)
heroku config:get SECRET_KEY_BASE # Double-check!
heroku restart
Debugging Pro Move:
# config/initializers/env_check.rb
raise "SECRET_KEY_BASE missing!" if ENV["SECRET_KEY_BASE"].nil?
3. Other Deployment Demons ?
Database Setup Fail
Symptom: PG::ConnectionBad
Fix:
heroku run rails db:migrate # ← Often forgotten!
File Permission Nightmares
Symptom: EACCES: permission denied
Fix:
# In Dockerfile:
RUN chown -R app:app /app
Memory Limits (Asset Compilation)
Fix:
# Heroku
heroku config:set NODE_OPTIONS="--max_old_space_size=2048"
4. Your Deployment Survival Kit
- Logs Are Oxygen:
heroku logs --tail # Live view
- Reproduce Locally:
RAILS_ENV=production bundle exec rails assets:precompile
- Staging Environment:
heroku create my-app-staging --remote staging
Real War Story
Last week, I spent 3 hours debugging why CSS wasn’t loading.
Cause: Precompilation failed silently.
Solution:
heroku run rails assets:clean # Cleared cached garbage
Your Turn
Next time deployment fails:
- Don’t panic
- Check logs
- Verify assets + env vars
- Slay the dragon ?
Got a deployment horror story? Share below! ?
Источник: