6

I'd like to deploy an angular+rails app on Heroku. The app is built off Emmanual Oda's example code, and compiles its assets using Grunt.

Instead of compiling my assets locally and then committing them to git, I'd prefer to compile them on Heroku. That is, I'd like to run grunt build on Heroku automatically whenever my app is deployed.

Does anyone know how I can configure Heroku to do this?

EDIT

I know server side asset compilation is possible with Node.js apps, for example using mbuchetics' fork of the heroku nodejs buildpack. When I follow the instructions at that site and push to Heroku, though, I get the following error

-----> Fetching custom git buildpack... done

 !     Push rejected, no Cedar-supported app detected

EDIT 2

For the time being I'm deploying using a Rake task that runs grunt build locally.

task :deploy do
  system("rm -rf ./public/*")       # empty the public directory
  system("cd ngapp; grunt build")

  # make a bogus manifest file to turn off asset compilation on heroku 
  #   see here: https://devcenter.heroku.com/articles/rails-asset-pipeline
  system("mkdir public/assets; touch public/assets/manifest-098f6bcd4621d373cade4e832627b4f6.json")  

  system("git add public/")
  system("git commit -m \"deploying...\"")
  system("git push heroku master")
end

A server side solution would be preferable!

dB'
  • 7,838
  • 15
  • 58
  • 101
  • 1
    possible duplicate of [How to deploy node app that uses grunt to heroku](http://stackoverflow.com/questions/13784600/how-to-deploy-node-app-that-uses-grunt-to-heroku) – poke Jan 05 '14 at 01:45
  • You'll need to use the Heroku [grunt buildpack](https://github.com/mbuchetics/heroku-buildpack-nodejs-grunt). Been a while since I used it, so I may not be of much help. – Jordan Kasper Jan 05 '14 at 18:39
  • I tried this and I got a `push rejected` error. See my edit, above. Any idea what I'm doing wrong? – dB' Jan 05 '14 at 18:46

2 Answers2

6

I believe this is what you want: http://www.angularonrails.com/deploy-angular-rails-single-page-application-heroku/

This solution uses multi buildpacks to run grunt build in production. No build artifacts in version control.

Jason Swett
  • 43,526
  • 67
  • 220
  • 351
2

My project is also based off of that sample rails app structure. May I ask why you want heroku to compile your grunt build rather than committing it? Having heroku compile it means even longer deploy times. What I do is I have a deploy script run grunt build and also run all the tests before committing to a build branch. That build branch is pushed to heroku. That way my development branch stays clean without the compiled assets in the public folder.

Homan
  • 25,618
  • 22
  • 70
  • 107
  • 2
    Huh. Ok. Having a separate build branch is a solution I hadn't thought of. Still, it just seems more elegant to have the assets compiled on Heroku. I'm still curious to know whether it's possible. Thanks for the answer, though! – dB' Jan 05 '14 at 03:22