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.
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.
In a rails project, I have a Gemfile which specifies a gem dependency as follows:
gem 'darshan', '1.1.4'
To be compiled, this particular gem requires the location of the corresponding C library, which may not be in a "standard" location such as /usr/lib. Manually, one would install this gem as follows, for example:
gem install darshan -- --with-darshan-dir=$HOME/local
How can I add this "with-darshan-dir..." to the gem command in the Gemfile, and more importantly, how can I make it such that the user himself provides this location as optional parameter when calling bundle install?
I checked the gemfiles manual (http://bundler.io/man/gemfile.5.html) but couldn't find anything to do that.
Thanks
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.
I have an app whose Gemfile requires a gem that is also dependent on another gem that is currently found on github.
So
app/Gemfile reads
gem "my-gem", :git => "git://github.com/MyCompany/my-gem.git"
my-gem/Gemfile reads
gem "my-gem-2", :git => "git#github.com:MyCompany/my-gem-2.git"
my-gem/my-gem.gemspec reads
spec.add_dependency "my-gem-2"
When I run bundle inside of app I get an error that it can't find gem my-gem-2 which is required by my-gem; however, if I put the following line
gem "my-gem-2", :git => "git#github.com:MyCompany/my-gem-2.git"
inside of app/Gemfile then it works fine.
This practice seems redundant as I wouldn't think I'd have to add gem dependencies of another gem into my parent app. Is there something I'm doing wrong here that myapp can't find my-gem-2?
This is just the way it goes - Gemfile dependencies within gems are just for when you're developing that gem. Only the gemspec gets evaluated when the gem is used elsewhere (and gemspecs have no concept of git dependencies), hence only dependencies in the gemspec apply.
So: you will need to have both git references within your app's Gemfile.
As stated in the gem specification, the list of gems that you provide through add_dependency will be use to make sure those are already installed in the system during the installation process (i.e gem install). So this line:
my-gem/my-gem.gemspec reads spec.add_dependency "my-gem-2"
Will trigger the verification of whether or not the gem is installed in the system, but it will not trigger any automatic installation of such gem, as Bundler would do.
This other line (inside of your gem):
gem "my-gem-2", :git => "git#github.com:MyCompany/my-gem-2.git"
Specify that a gem should come from a git repository with a .gemspec at its root.
For more details: Gems from git repositories
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.