Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically precompile assets before pushing to Heroku

Is it possible to automatically precompile my assets in a Rails app before pushing out to Heroku? I always forget to do it, so it would be nice if when I typed git push heroku master, it would first run rake assets:precompile ; git commit add . ; git commit -a -m "Precompile.", or something to that effect.

Has anyone achieved such a solution? Possibly without hooks? Though I suspect that is the only way.

like image 859
Mike Avatar asked Nov 25 '11 20:11

Mike


People also ask

How do I Precompile assets in Heroku?

To compile your assets locally, run the assets:precompile task locally on your app. Make sure to use the production environment so that the production version of your assets are generated. A public/assets directory will be created. Inside this directory you'll find a manifest.

What does rake assets Precompile do?

rake assets:precompile. We use rake assets:precompile to precompile our assets before pushing code to production. This command precompiles assets and places them under the public/assets directory in our Rails application.


2 Answers

I finally figured this out. I was indeed on the Cedar stack. The problem was that I had checked my public directory into Git, and when I pushed to Heroku, it realized that public existed, and thus assumed I precompiled. Running git rm -r public and adding public/** to my .gitignore, then pushing, fixes the problem.

like image 138
Mike Avatar answered Sep 21 '22 14:09

Mike


It sounds like you might not be on Heroku's Cedar Stack? If you're using the asset pipeline (Rails -v >= 3.1), cedar provides three options for compiling assets.

From the docs:

If you have not compiled assets locally, we will attempt to run the assets:precompile task during slug compilation.

like image 22
dwhalen Avatar answered Sep 21 '22 14:09

dwhalen