Installing gems on node heroku projects - ruby

I'm writing a node app on heroku, and the app requires a gem, compass to be installed, for node-compass.
However, I can't seem to work out how you install gems in a node application on heroku. I have a Gemfile, which looks like so.
source "https://rubygems.org"
gem 'compass'
Have you managed to do this successfully before?

According to an official reply from Heroku for this question:
You would need to use the heroku multi buildpack in order to have both the Ruby buildpack and the Node buildpack: https://github.com/ddollar/heroku-buildpack-multi

In addition to a Gemfile, you need a buildpack and a Gemfile.lock. I wrote up how I got this working in this answer to a slightly different question, but I think it should answer this question too.

Related

Cannot push Ruby app to Heroku: App not compatible with buildpack, yet Gemfile exists

I've built a Ruby app for Twitter. I have a Gemfile and the Gemfile.lock that bundler created. This is the contents of the Gemfile
source 'https://rubygems.org'
gem 'twitter'
When I try to push the app to Heroku, it fails with:
App not compatible with buildpack: https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku/ruby.tgz
I tried removing the buildpack from the Heroku settings. If I do this, it fails because it cannot detect the buildpack.
I can't see what is wrong here. Help gratefully received.
I solved this by adding a new line to the end of the gemfile

Bundler using binstub generated for a different gem using Middleman

I am using Middleman to build a project. I receive this message any time I run a Middleman command:
Bundler is using a binstub that was created for a different gem.
This is deprecated, in future versions you may need to `bundle binstub middleman-core` to work around a system/bundle conflict.
When I run bundle binstub middleman-core, I get this:
middleman-core has no executables, but you may want one from a gem it depends on.
bundler has: bundle, bundler
rack has: rackup
tilt has: tilt
erubis has: erubis
listen has: listen
sass has: sass, sass-convert, scss
Don't really know where to go and what to do from that message.
It is not causing the anything to fail and the server runs, but I feel like this could be a bigger issue if I leave it unfixed. This ended up happening when I was playing with s3_sync to push this up to s3 bucket and I gem installed middleman-sync_s3.
I have tried research and others led me through the path of deleting the bin/* file multiple times. I've tried updating the bin also and neither helps.
Any help is appreciated.
So I was hopping around the Gemfile trying to figure out what was going on. I had built a few previous projects in middleman and decided to look them up. I saw that I was using a previous version of Middleman 3.1.0 where as with this current project I was using Middleman 4.0.0
I reverted back to 3.1.0 and ran a bundle update. Tried running a Middleman command and the binstubs message no longer appears.
Ultimately, I think it had something with the way bundler plays with middleman-core.
gem install middleman-cli seems to help in case someone else is looking for a solution to this.

Is there a way to use Bundler for production gems?

I tried searching for this several times, but if this question has been answered already I didn't find it.
So, let's say I've developed a plain old gem (not a Rails app). I already know how to use Bundler for development, so I have a Gemfile and everything in my repository. However, I want this gem to use Bundler for dependency resolution when I install it, not just when I work on it.
Is there a way to do so, or would I have to resort to running its commands from a git checkout with bundle exec?
Bundler resolves dependencies not only for development. Just run bundle install on production server after deployment and it will install all needed gems there too.
If you need to install gems from several repositories, add row in you Gemfile:
source 'http://you_repository.com

JRuby with Sinatra on Heroku

I'm cloning this repo:
https://github.com/freeformz/sinatra-jruby-heroku.git
to try and use JRuby/Sinatra on Heroku's Cedar stack. I follow the included instructions and everything runs great locally with a 'foreman start'. I then git push to Heroku and it initially loads up fine but when I try to access the site I get an error in the logs:
jruby: No such file or directory -- trinidad (LoadError)
So it seems jruby can't find the "/app/.gems/bin/trinidad" file. I initially thought it wasn't there because .gems/ is in the .gitignore file, but I'm pretty sure Heroku creates that server side on a git push.
$APPDIR/.gems is added to the PATH so Heroku should be able to see the trinidad script. I've also tried to change the Procfile around to play with the path like:
web: script/jruby -S bin/trinidad -p $PORT
But no dice. Has anyone had any success deploying anything JRuby to Heroku cedar?
Thanks
As of Bundler 1.2 you are now able to specify the Ruby implementation and version in your Gemfile. The nice thing about this is that Heroku will understand these settings and prepare the your Heroku application for your environment.
Take this Gemfile for example:
source "https://rubygems.org"
ruby "1.9.3"
gem "rails"
gem "puma"
What's cool about this is that by default Celadon Cedar uses Ruby 1.9.2. However, when you specify ruby "1.9.3" in the Gemfile it'll actually compile Ruby 1.9.3 for your Heroku environment.
Now, if you want to add a different Ruby implementation to your Heroku environment, you can do so like this:
source "https://rubygems.org"
ruby "1.9.3", :engine => "jruby", :engine_version => "1.7.0.preview1"
gem "rails"
gem "puma"
Now it'll install and use JRuby 1.7.0.preview1 in Ruby 1.9 mode for your Heroku application upon deployment. It'll also even define the proper JVM options in the Heroku environment variables.
Best of all is that this comes with the official Heroku buildpack, so there is no need to switch to a 3rd party buildpack to get the JRuby/JVM going on Heroku. Although I haven't gotten it to work yet, this should also work with Rubinius, but I believe it's currently bugged. Either that, or I'm doing it wrong.
This is in my opinion an awesome and scalable feature. Just define the Ruby implementation/version/mode you're using in your Gemfile along with your other dependencies and Heroku will ensure the environment is prepared.
Now, with all this in place, Heroku should create binstubs (through Bundler) in APP_ROOT/bin so what you can do is for example this:
web: bin/trinidad -p $PORT -e $RACK_ENV --threaded
Just don't use bundle exec since JRuby doesn't play nice with that. Always use the binstubs provided by Bundler which are always located in APP_ROOT/bin on Heroku.
I believe the details about including gems on this blog entry might be helpful to you:
http://chris.chowie.net/2011/08/28/Sinatra-with-JRuby-on-Heroku/
I suspect that your gems are not in /app/.gems but rather in /app/vendor/bundle
You can find out by running this command:
heroku run ls /app/.gem
heroku run ls /app/vendor/bundle
Either way, you should probably add the GEM_HOME/bin to the path, and not the GEM_HOME as you state.
I've got a blog post on running Jruby and Trinidad on Heroku here:
http://deployingjruby.blogspot.com/2012/03/deploying-with-trinidad-on-heroku.html
And an example app here:
https://github.com/jkutner/jruby-trinidad-heroku
Some of the other material you may find is a little out of date.

Push Rack-Jekyll app to Heroku

I haven't used Ruby. I don't know what gems are. But I know how to install them and do basic things like that.
I heard of Jekyll and decided to start my own using Heroku. I found Rack-Jekyll that will work on Heroku.
I created my site as per Jekyll instructions and it is running fine on my system. Then I did what I was told to do in http://github.com/bry4n/rack-jekyll#readme. But when I push it to Heroku, I get an error:
---> Heroku received push
---> Rack app detected
---> Installing rack-jekyll from http://rubygems.org
ERROR: could not find gem "rack-jekyll" locally or in a repository
On seeing this, I downloaded the rack-jekyll.gem file and committed it to the repsitory and tried uploading it. Even that didn't work. Can you tell me precisely what to do?
Updated (ht Andrew): use heroku's Bundler support
create a Gemfile like so
source "http://rubygems.org"
gem "rack-jekyll"

Resources