Bundler error on deployment - ruby-on-rails

I'm currently using guard i.e. guard-coffeescript gem to compile my javascript (and in the future I'll probably add some more guard tasks) on my OSX dev system. I added the rb-fsevent gem to my Gemspec, now I saw that in a lot of Gemspecs it is added with an if statement like this:
gem 'rb-fsevent', :require => false if RUBY_PLATFORM =~ /darwin/i
Trying to deploy to my staging/production environment, which is running under Linux, the script executed on the server uses the bundle install --deployment results in following exception:
# bundle install --deployment
You have modified your Gemfile in development but did not check
the resulting snapshot (Gemfile.lock) into version control
You have deleted from the Gemfile:
* rb-fsevent
Is there a way around this problem or do I just have to remove the if so that I can deploy to my system and in turn installing a gem that is useless on a non OSX platform?
--
edit: I run bundle install before deploying to my staging environment and run bundle check after the first time it failed. I got it running after removing the if statement..

I had a similar problem. If you're using capistrano you can set the following option:
set :bundle_without, [:darwin, :development, :test]
Then wrap your gem 'rb-fsevent' line in a group called darwin. Something like this should work nicely:
group :test, :darwin do
gem 'rb-fsevent'
end
This makes bundler do this on the server:
bundle --without darwin development test
Which means that it ignores those groups in the Gemfile.lock. What you were doing would make you OS X machine and your server come up with different resulting lock files. Which is why it was complaining.

I had the exact same issue and Luke's solution fixed it for me, however, only after I removed the :require => false if RUBY_PLATFORM =~ /darwin/i string that is commonly used.

As described in
https://github.com/guard/guard
the solution is simply
group :development do
gem 'rb-inotify', :require => false
gem 'rb-fsevent', :require => false
gem 'rb-fchange', :require => false
end

Related

Skip non-development environment gems installation

I have some gems needed outside development environment. So I moved them to the corresponding group in Gemfile as follows:
group :staging, :production do
gem 'activerecord-oracle_enhanced-adapter', '~> 5.2.0'
gem 'ruby-oci8', '~> 2.2', '>= 2.2.7'
gem 'aws-sdk-s3', '~> 1.48', require: false
end
Nevertheless, after cloning the project, when running bundle install it still requires to install ruby-oci8. What am I missing?
By default, bundle install will install all gems in all groups in your Gemfile, except those declared for a different platform.
However, you can explicitly tell Bundler to skip installing certain groups with the --without option. This option takes a space-separated list of groups.
While the --without option will skip installing the gems in the specified groups, it will still download those gems and use them to resolve the dependencies of every gem in your Gemfile.
This is so that installing a different set of groups on another machine (such as a production server) will not change the gems and versions that you have already developed and tested against.
ref: https://bundler.io/man/bundle-install.1.html

Rails - how do gems relate to doing 'bundle'

I'm learning Ruby on Rails from Michael Hartl's website. I have a Gemfile that looks like this:
source 'https://rubygems.org'
ruby '2.0.0'
#check and remove below if not relevant
#ruby-gemset=railstutorial_rails_4_0
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.1'
group :development, :test do
gem 'sqlite3', '1.3.8'
gem 'rspec-rails', '2.13.1'
end
group :test do
gem 'selenium-webdriver', '2.35.1'
gem 'capybara', '2.1.0'
end
.
.
.
group :doc do
gem 'sdoc', '0.3.20', require: false
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor', '0.0.2'
end
# Use ActiveModel has_secure_password
# gem 'bcrypt-ruby', '~> 3.1.2'
# Use unicorn as the app server
# gem 'unicorn'
# Use Capistrano for deployment
# gem 'capistrano', group: :development
# Use debugger
# gem 'debugger', group: [:development, :test]
Why is this sequence of commands correct:
`$ bundle install --without production`
`$ bundle update`
`$ bundle install`
Shouldn't it first be bundle update then bundle install --without production. Why call bundle install twice? I think the second call is redundant.
Why is this sequence of commands correct:
$ bundle install --without production $ bundle update $ bundle install
Without context, it's difficult to answer this—but one can intuit from the commands that it probably doesn't appear as one string of commands to be executed dutifully.
bundle install --without production installs exactly the versions in your lockfile, skipping any gems in a production group or with a production tag. This allows you to install only what you need to test and develop your application. (e.g., you probably don't want to waste lines with your logging service or pollute your monitoring service.) More importantly, this gives you a known-good working state for development on any machine you use.
bundle update updates the lockfile with permissible newer versions of the gems in the Gemfile. This can and will break your application if the Gemfile has not been well-crafted and versions of your dependencies have changed in the mean time. (So to answer your other question, no, you wouldn't run an update before an install.)
bundle install is most likely there to illustrate the correct command for deploying your production application: It wouldn't make any sense to skip the production gems and immediately turn around to install the production gems.
Where actually are these stuff being downloaded saved? Where are they
being installed? On my computer? I never got where they actually go or
hide. Maybe in my applications folder? But where exactly?
On your computer, in your Ruby installation. Ruby, like Perl and Python, maintains a portion of its directory structure specifically for add-on libraries.
In Ruby 2.0.0, for example, they live someplace similar to [RUBY_ROOT]/lib/ruby/gems/2.0.0/gems. For very specific purposes, it's also possible to install them locally in your Rails application's directory.
My recommendation is
1) Just do bundle, forget the rest. Not important to your learning
2) bundle install
OK, so for whatever version of ruby you are currently using this will take your Gemfile and get the right versions of those gems from rubygems.org (the site). and then install those gems on your machine for version of ruby that you are using if that version doesn't already exist on your machine. If the version exist, no download is needed, the gem version will be able to be immediately included, e.g. when offline.
If you switch ruby version then you'll usually need to bundle install again to get the right versions of those gems for the version of ruby that is currently being used on your machine.
If you use a tool such as rvm to manage your ruby versions then this is as simple as:
cd the_application_directory_for_your_rails_application
rvm use 1.9.3
bundle install
then to switch to ruby 2.0
rvm use 2.0
bundle install
You can specify specific ruby versions with
rvm use 1.9.3-p448 # e.g. for the -p448 version
You can see the 'currently available' ruby versions on your machine with
rvm list rubies
You can install a specific ruby with, e.g.
rvm install 1.9.3-p194

Why does 'bundle' install production gems on my development machine?

Gemfile says:
gem 'sqlite3', :groups => [:development, :test]
gem 'mysql2', :group => :production
yet when I type bundle install on my development machine ALL gems are installed.
What's wrong with my setup?
The point of Bundler is to create a consistent gem environment across deployments. Gems, unfortunately, can interact even if they aren't loaded or required. So for maximum consistency, all gems should be installed, even if they aren't all required.
However, if you don't want all gems installed all the time, you can use the bundle install --without option.

Launching RoR server for an existing app gives error

I just made my first setup of RoR, and creating a new application works fine. But when I want to run the rails server I get the following error:
C:/Ruby192/lib/ruby/gems/1.9.1/gems/delayed_job-2.1.3/lib/delayed/yaml_ext.rb:30:in 'remove_method': method 'to_yaml' not defined in Class (NameError)
I ran the "bundle install" in the app directory and installed all the necessary files (with some problems however, but I excluded the gems with problems in the gemfile) and the last bundle install said that I have successfully installed all the needed packs.
I'm lost and I can't find a similar error on the internet. Can you help me?
EDIT: I forgot to mention that I'm not having a problem with a new application. It's running an existing one (that I didn't build, but works fine for others) that the error is related to. Here's the gemfile for that app:
source 'http://rubygems.org'
gem 'rails', '3.0.3'
gem 'mysql'
gem "haml", ">= 3.0.0"
gem "haml-rails"
gem 'simple_form'
gem 'delayed_job'
#gem 'auto_crawlers'
gem 'will_paginate', '~> 3.0.beta'
group :test do
gem 'factory_girl_rails'
gem 'mocha'
end
group :development do
#gem "nifty-generators", "0.4.3", :git => "git://github.com/JonasNielsen/nifty-generators.git"
gem 'fastercsv'
end
gem "mocha", :group => :test
Do you think the error is because I left out the two gems with "#" ? Those were causing problems at first, and I don't think I need them to test some minor changes in the app (some views that I have to modify)
The issue is being described, and supposedly fixed here: https://github.com/collectiveidea/delayed_job/issuesearch?state=open&q=yaml#issue/194
Try this from the command line: irb -rubygems -r delayed_job and then from your bundled directory bundle-exec irb -rubygems -r delayed_job which will show if there is a difference between your system gems and your bundled setup - you might see an error in one or both attempts to run IRB.
If there is an error using bundle-exec but not with your system gems then it's a bundler issue. If not, are you sure the app is designed to function under Ruby 1.9? It looks like to_yaml isn't available at the point DJ is required, which implies it probably needs a require "yaml" somewhere.

Ruby on Rails and RVM: Problem including external gems in my Gemfile (Rails 3)

When I try to include an external gem in my Gemfile (e.g. from github), my RVM doesn't recognize the external gem. It keeps telling me to run "bundle install" even after already doing.
For example, when I log into shell and do a "bundle check", I see that all "dependencies are satisfied" but in my browser, Passenger tells me that my gem is not checked out and to "Please run bundle install".
Just to make it clearer, doing this gives me the issues above:
gem 'thinking-sphinx',
:git => 'git://github.com/freelancing-god/thinking-sphinx.git',
:branch => 'rails3',
:require => 'thinking_sphinx'
But doing this using local gems do work:
gem 'thinking-sphinx'
The backtrace is here. Do you know what the problem could be?
Try:
gem 'thinking-sphinx', '2.0.0.rc2', :require => 'thinking_sphinx'
It's always best to require a specific gem version, rather than just checking out master or a branch still in development.
Your application is probably not running as the intended user.

Resources