Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Rake task enhancement differ between my local environment and when deploying to Heroku Cedar?

I have this in lib/tasks/foo.rake:

Rake::Task["assets:precompile"].enhance do
  print ">>>>>>>> hello from precompile"
end
Rake::Task["assets:precompile:nondigest"].enhance do
  print ">>>>>>>> hello from precompile:nondigest"
end

When I run rake assets:precompile locally, both messages are printed.

When I push to heroku, only the nondigest message is printed. However, according to the buildpack, the push is executing the exact same command as I am locally.

Why does the enhancement to the base assets:precompile case not work on heroku but does work locally?

like image 862
John Bachir Avatar asked Apr 01 '12 17:04

John Bachir


2 Answers

i've been looking into this issue and I found out that the behavior of the assets:precompile depending on if RAILS_ENV and RAILS_GROUPS are both set or not take a look at this locally.

  # This works
  → bundle exec rake assets:precompile RAILS_ENV=production
  >>>>>>>> hello from precompile:nondigest
  >>>>>>>> hello from precompile

  # This works
  → bundle exec rake assets:precompile RAILS_GROUPS=assets
  >>>>>>>> hello from precompile:nondigest
  >>>>>>>> hello from precompile
  →

  # This does not work :'(
  → bundle exec rake assets:precompile RAILS_ENV=production RAILS_GROUPS=assets
  >>>>>>>> hello from precompile:nondigest
  →

The problem comes from https://github.com/rails/rails/blob/3-2-stable/actionpack/lib/sprockets/assets.rake in invoke_or_reboot_rake_task method if you replace the Rake::Task[task].invoke line with ruby_rake_task task then it works like you would expect it to. I've been poking around on exactly why this is, and haven't found the reason.

Since both variables are set in the Heroku build pack, you could create a custom build pack without setting both GROUP and ENV settings, though I think that is overkill. In this scenario you should be able to enhance assets:precompile:primary or assets:precompile:all and achieve an outcome similar to your desired intent.

like image 56
Schneems Avatar answered Nov 15 '22 21:11

Schneems


Are you setting RAILS_ENV=production and RAILS_GROUPS=assets?

Also, according to this post, Heroku doesn't support custom asset compilation tasks...

like image 32
hohner Avatar answered Nov 15 '22 19:11

hohner