I'm writing some scripts to set up development environment for a ruby app.
In my Gemfile, I have gems dependent on nokogiri, libv8 etc.
On running bundle install on different machines, it fails with messages like following
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
I now have this in my script to build to build native extension using system libraries.
bundle config build.nokogiri --use-system-libraries
bundle install
I can set configurations in bundler for each gem (bcrypt-ruby, libv8 etc) a similar way.
Is there a better way to do this? Like set a flag in bundler so that bundle understand details like using system libraries and bundle install works on all platforms
bundle config by default acts as global config for machine you run it - stores data in ~/.bundle/config
You may try to use --local, which stores in your_app_dir/.bundle/config and then commit the file or create it on deploy. I'd go with the latter
Related
I have a webapp running on sinatra with several gems installed.
I would like to zip it and move to another machine, but since that machine doesnt have internet connection I would like to pack all the gems (sinatra, mongoid etc) with it?
If the two machines are similar and you’re using the same Ruby implementation (and version) you could use Bundler. Create a Gemfile, add the gems your app needs to it, then run
$ bundle install
to install those gems to the local machine.
You can then run
$ bundle package
which will copy all the gems used to the vendor/cache directory in your app. After zipping up and transferring the app to the other machine run
$ bundle install --local
to install all the gems from the vendor/cache directory on the other machine.
See the docs for bundle package.
I am using Capistrano and I would like to have a system gem install (instead of deployment which is default). I have tried the following:
set :bundle_flags, '--system'
However I get the following error:
You have specified both a path to install your gems to, as well as --system. Please choose.
Is there a way to set system install?
I am using Capistrano 2.15.5.
Is there a way to put a ruby gem dependencies inside the project root folder ( in vendor directory or something similar ) ?
Run bundle package to cache gems to ./vendor/cache. As the docs point out, bundler will still look for platform-specific gems on rubygems.org. If you have control over the platforms (e.g. same development and deployment platforms), then you can use bundle install --local in addition to bundle package. You may also want to consider a command like bundle install --path vendor/bundle in this case.
Just generate gemfile with proper app dependencies, place it into the root of your app, and use bunlder to keep depencencies up-to-date. Since by default all gem will be placed into system folders, I strongly recommend you to use rvm or rbenv utilities to use for purpose of gem keeping.
I'm trying to install the gem 'taglib-ruby' on Heroku. This gem compiles as a native extension which requires a system dependency called taglib, so after compiling and uploading it through heroku vulcan, I achieved to compile the gem via command line on heroku bash:
bundle exec gem install taglib-ruby -- --with-opt-dir=/app/vendor/taglib
And in order to this parameter would be used by bundler later, I added it as a bundler configuration through the command:
bundle config build.taglib-ruby '--with-opt-dir=/app/vendor/taglib'
I've already verified this config was applied, inspecting the file /.bundle/config and looking for the line BUNDLE_BUILD__TAGLIB-RUBY.
However after pushing out my project to heroku and while it is executing the bundle install command, heroku complains that the above gem (taglib-ruby) cannot be installed due the taglib library isn't present, although it's what I was trying to solve with the option '--with-opt-dir=/app/vendor/taglib' mentioned above.
So it appears that Heroku is ignoring the bundler configuration.
What could be happening? Do you know another way the achieve the same intention (install a gem with custom build options) on Heroku?
Pretty fundamental question but I'm trying to understand how best to use Bundler in a deployment situation.
I'm working on a Sinatra application that has about 20 dependent gems. During development, I'm using RVM with a custom gemset for the application, and I run bundle install to update the gemset in accordance with the gemfile.
When it comes to deployment (manually for now, so I can understand how it all works before using a tool like capistrano), I need to do bundle install --development right? This downloads the gems and places them in vendor/bundle.
My question is what else do I need to do? I'm using Unicorn on the server - do I just bundle exec unicorn ... and everything just works? (i.e. bundler finds the vendor directory and uses the gems from there?)
Should unicorn be a vendored gem in the application or a separate 'system' gem on the server that all applications share?
You need --deployment key, not --development: http://gembundler.com/man/bundle-install.1.html#DEPLOYMENT-MODE
On first run bundler creates config in .bundle directory. You can check it by running bundle config or just cat .bundle/config in project's directory. So bundle exec unicorn is enough since bundler knows where gems are installed. On development machine you can also install gems to arbitrary directory using --path key. For more details see manpage for bundle install (link above or bundle help install).