Heroku not loading bundler for non-web ruby app - heroku

I have a program that I wrote using ruby. It doesn't have any web interface, but I use bundler for dependency management.
On my local system, running the app is as simple as typing rake app:start, and it loads up just fine.
When I deploy to heroku, however, my app crashes with a cannot load such file -- bundler error.
My Procfile looks has this entry app: bundle exec rake app:start.
Any help is greatly appreciated.

The problem was that Heroku was not changing the GEM_HOME field to the vendor/bundle directory.
By adding the following config vars to Heroku, my app ran as expected:
GEM_HOME: /app/vendor/bundle/ruby/1.9.1
PATH: /app/vendor/bundle/ruby/1.9.1/bin:bin:node_modules/.bin:/usr/local/bin:/usr/bin:/bin
Adding these was done via the heroku config:set CONFIG_NAME=VALUE command.

Related

Capistrano deploy bundle: command not found

I am running Capistrano with a Wordpress website that I work on locally and deploy to a staging server or a production server on Digital Ocean. I've been working on it for months now. And today all of a sudden, the simple deployment script doesn't worK scripts/deploy staging
It's worked just fine & now it's not. Any ideas of what would cause it to break?
I get the error:
scripts/deploy: line 3: bundle: command not found
The command on line 3 is:
(bundle exec cap $1 deploy)
I'm using ruby 2.0.0p645
And it looks like Capistrano gem 'capistrano', '~> 3.2.0'
I actually have 3 websites that use this command and none of them are working all of a sudden. Did Cap do an update or could my system have an error somehow?
Simply try on the remote site:
gem install bundler

Heroku: where did my gems go?

I have been deploying a Rails 3.2 application to heroku for several weeks now. I have also been executing rake tasks on the Cedar stack where my application is located.
One day after a deploy I noticed that rake was no longer working. I get, for example, the following:
$:~/dev/my_project$ heroku run rake -T
Running `rake -T` attached to terminal... up, run.7566
bundler: command not found: rake
Install missing gem executables with `bundle install`
Trying to run commands with bundle exec yields the same results.
What I've tried:
heroku run bundle install. This works and informs me that gems were installed into ./vendor/bundle. However, heroku run ls ./vendor/bundle yields only the following:
$:~/dev/my_project$ heroku run ls ./vendor/bundle/
Runningls ./vendor/bundle/attached to terminal... up, run.3458
bin ruby
bundle package. Although the deployment works it does not help my problem.
fiddling around with the rubygems-bundler gem (although I think this is now part of core bundler). This does not seem to have any effect.
On Heroku, gems are installed within the vendor/bundle/ruby/<version>/gems directory. I just checked my Heroku instance and confirmed this.
You are going to want to use bundle exec rake task because the gems are not in the users PATH.

Could not detect rake tasks

ensure you can run `$ bundle exec rake -P` against your app with no environment variables present
and using the production group of your Gemfile.
This may be intentional, if you expected rake tasks to be run
cancel the build (CTRL+C) and fix the error then commit the fix:
rake aborted!
I don't have any rake tasks that I'd like to run automatically. Should I just ignore this warning?
Effective December 05, 2013, Heroku added debug output to deploys using the Ruby build pack.
The error is triggered:
if the assets:precompile task does not exist or
if there is an error in the Rakefile.
Two common causes of errors in the Rakefile are referencing a dependency not available in production (such as rspec) or
expecting an environment variable to be present.
It's counter-intuitive because the app never runs without config vars, but Heroku's build process executes without config vars.
As per the error message, ensure you can run bundle exec rake -P RAILS_ENV=production with no environment variables present before pushing to Heroku (e.g. comment out your environment variables while running the aforementioned command).
Also, rest assured that rake's -P switch is harmless, so you can run it as much as you want until you fix this issue. This switch is used to display a list of all tasks and their immediate prerequisites. See Rake Command Line Usage if you want to double-check. The output may have over 200 lines, and look something like this:
rake about
environment
rake assets:clean
environment
rake assets:clobber
environment
rake assets:environment
rake assets:precompile
environment
rake db:_dump
...
rake tmp:pids:clear
rake tmp:sessions:clear
rake tmp:sockets:clear
I started getting this strange error all of a sudden yesterday. Heroku confirmed making an update to the Ruby buildpack...
It has to do with the Rakefile. Does your Rakefile require any files? Does it require your app files? If so, then the app should not raise exceptions when it is loaded without any config vars set.
It's counter-intuitive because the app never runs without the config vars set.
In my case, the Sinatra app was looking for database urls in the init file:
uri = URI.parse( ENV[ "REDISTOGO_URL" ])
This will raise an exception if there are no env vars set.
You may have the same issue with other database URL's, such as Mongo or Postgres.
So, protect against missing env vars:
if ENV[ "REDISTOGO_URL" ]
uri = URI.parse( ENV[ "REDISTOGO_URL" ])
...
You can check if it will work before pushing to Heroku by running bundle exec rake -P
Also, make sure all your tests pass after updating your init. Remove any cached init state by restarting Spork or similar.
Reference: Show Rakefile errors in Ruby deploys
you can also try enabling user-env-compile
heroku labs:enable user-env-compile
FWIW I just ran into this issue also.
It turned out that I had config.assets.css_compressor = :sass commented out, when there was a rake task referring to it in production.rb.
Very simple oversight, but that would cause rake assets:precompile to fail and thus cause this error.
Old question, but I ran into this issue just now, and there is a new fix for it. If you're using Ruby version <= 2.6.1, and Bundler 2.0.1, update Ruby to 2.6.3 ($ rvm install "ruby-2.6.3") and Bundler to 2.0.2 ($ gem install bundler '2.0.2'). Make sure to specify the new Ruby version in your Gemfile.
Unfortunately I can't tell you why this works, but it's worked for 3 other people on my team so far, so it's worth a shot.

Rails 3.2.3 Asset Pipeline precompile does nothing

I can reproduce this issue on both OSX and Windows with Ruby 1.9.2:
I have a simple Rails 3.2.3 app and am trying to precompile the assetpipeline, but the assets:precompile does nothing. Doesn't complain either.
Here is what I've done:
Using RVM, create a new and clean gemset, call it rails32
Install rails: gem install rails -v 3.2.3
Create a dummy scaffold: rails g scaffold test name:string
Migrate the prod db: rake db:migrate RAILS_ENV=production
Run the server in prod: rails s -e production
At this point I get the asset not precompiled exception, which I was expecting. Then:
I run rake assets:precompile RAILS_ENV=production
It runs with no errors and ends.
After that, my app has fingerprinted assets in the HTML but they don't exist anywhere.
Any ideas? I thought this is the simplest form of using the assetpipeline.
By default, Rails expects a high-load server (such as Apache or nginx) to serve static assets in production mode. If you really don't want to run your app behind such a server, in your config/environment.rb file, change config.serve_static_assets to true.

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.

Resources