My organization has a number of in-house gems that are used in automated testing, but are not required for a production deployment. I am trying to use Bundler and so in my Gemfile I've wrapped those gems in:
group :test, :development do
gem 'dashboard_summary'
end
However, when I run:
$ bundle install --without staging development test
I still get
Could not find gem 'dashboard_summary (>= 0) ruby' in the gems available on this machine.
I'm trying to understand why Bundler isn't ignoring that gem when I've told it to.
This is expected behaviour. From the docs:
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(5).
Whilst an up to date Gemfile.lock might suggest that the dependencies don’t need to be resolved again, it looks like all gems are downloaded even in this case.
You didn't define any group that includes staging, development and test. Your group only had test and development.
Bundler is trying to ignore a group which has all three name in it, so you can add staging to
group :test, :development, :staging do
gem 'dashboard_summary'
end
or you can use
$ bundle install --without test development
I'm not sure why you have staging in there? but this should work
bundle install --without test development
You could also set the config environment variable documented in BUNDLE_WITHOUT in bundle config.
You could use
gem 'dashboard_summary', require: false
This would not load the gem on startup and you would have to require it when you wanted to use the gem. This may help if you need to keep dashboard_summary in your Gemfile because of dependencies, but save the time it takes to load and not get the error you are getting now. It's at least something to try.
Related
In our team some people do not have pg gem installed on their machines. At the moment we use two seprate database configs that are being copied to database.yml. We had problems with that approach because we had to keep commenting out gem pg in our Gemfile. So I tried following in our Gemfile:
unless ['host1, 'host2'].include? `hostname`.strip!
gem 'pg'
end
It seemed to work, but the boss wants a better solution, so that he can test the app on his laptop without having to install Postgres and without having his hostname in the Gemfile.
Gem::Specification.all_names
doesn't show pg being installed although 'gem list pg --local' shows it is installed.
Trying to use gem list pg --local in the Gemfile doesn't work because the system seems to go into infinite loop if you don't have pg installed.
Is there something similar to 'Gem::Specification.all_names' that correctly shows list of installed gems that could be used in optional excluding of gems in a Gemfile. Or is there a better way to use gifferent Gems on different machines for the above mentioned scenario?
note
if File.open('./config/database.yml').read.each_line.first.index('Postgre').is_a?(Integer)
gem 'pg'
end
seems to work but now I get this when I run bundle install:
Your bundle is complete!
Gems in the group postgres were not installed.
Use `bundle show [gemname]` to see where a bundled gem is installed.
any idea where it comes form?
note 2
'Gems in the group postgres were not installed' was fixed after running: rm -r ./.bundle
One possible solutions would be to use a custom environment and bundler group.
You might have noticed this line in config/application.rb:
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
Which means running rails s -e bossmode would require the gems in:
group :bossmode do
# no pg in here...
end
An even better solution would be to convince your boss to KISS and use PG. The performance cost even on a lowly macbook air is tiny.
There is the following code in Bundler:
group :production do
gem 'pg'
gem 'mysql2'
end
As you can see I use mysql2 on production only. Now I'm developing my app on my local machine, but I get the following error:
Could not find mysql2-0.3.15 in any of the sources
Run `bundle install` to install missing gems.
But I don't want to do it, I need production gems only on production VPS. How can I fix it? Thanks.
You just need to specify the option. See this too (it saves the option so you only have to specify it once)
bundle install --without production
I'm having a problem running bundle update with mysql2. I don't really need mysql2 in development, and it works in production, so I want to just tell my gemfile the following:
gem 'sqlite3', :group => :development
gem 'mysql2', :group => :production
Unfortunately it still says bundle update fails because of mysql2:
An error occurred while installing mysql2 (0.3.14), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.14'` succeeds before bundling.
Any reason why this is, and what can I do instead?
It's not a good idea to leave out production gems while you are in development because you want to be prepared for production from the development phase of your project in that you don't want unseen errors when you deploy. That being noted, it's still possible to run bundle update without the production group.
Execute the following and you should see 'Gems in the group production were not installed':
bundle update --without production
For your case though, since you've already installed production group gems, you may want to clean your gems and install them as follows:
> bundle clean --force
> bundle install --without production
# For test purpose
> bundle update --without production
I need to deploy a Rails app packaged up as a RHEL RPM. I want to bundle some of the gems it requires, but let the rest be satisfied from the production machine's system gems.
As an end result (for instance), I want the app to find some gems (like versionomy, for instance) in the app's vendor tree, but find the Rails activerecord, actionpack, and other gems in the host's system-wide gem library.
So far I've only found ways to bundle all-or-nothing. Can anyone point me to documentation explaining how to use Bundler and yet have $: be a search path, listing the app's bundled gems first and then the system's gems? Or if it's even possible?
Thanks!
specify path for gems in vendor directory
in Gemfile:
gem 'versionomy', :path => 'vendor/extensions'
Update
Yes it will work in deployment group.
You can specify wich gems are used in development, production and test
group :development, :test do
gem 'sqlite3'
gem 'thin'
end
group :production do
gem 'pg'
end
system path for gems in my case
/usr/local/lib/ruby/gems/1.9.1/gems/
check your install path by whereis gem
and if you are using rbenv
/home/username/.rbenv/versions/1.9.3-p362/lib/ruby/gems/1.9.1/gems/
You may have to install the requirements you don't want to provide as their own RPMs on the building machine. Then the RPM build process will require them but not provide them.
I work as a developer supporting several apps built in Rails, often I need to install gems that are not included into the gem file.
Last day I build a project and when I try to run it on another computer I experienced some issues with missing gems, a lot actually and I didn't know where to get a list of all the missing gems or how to install them.
The question is, is there a way to include all the gems that the project needs into the gem file so next time someone try to run it on another computer it will be enough to use the comand bundle install.
You need to include the Gems in your Gemfile, and then run bundle install on ANY new machine in order to install those Gems and their dependencies. For example:
source 'https://rubygems.org'
gem 'rails', '3.2.6'
gem 'jquery-rails'
gem 'mongoid'
gem 'devise'
gem 'cancan'
With this example, all dependencies of rails such as Active Record, Action Pack and so on will be installed when bundler installs rails. The same for the remaining gems and their dependencies.
If you are planning, and it appears that you are, to spend much time with rails, you should really read up on Bundler.