Capistrano - system bundle install - ruby

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.

Related

How do I set older version of Capistrano as default version/gem system wide?

I'm setting up an environment on a new Ubuntu18.04 server and I need to use Capistrano 3.6.x but when installing using apt-get I continue to pull 3.11.x.
I know I can create gem files for individual apps but I don't want to create Gemfiles for each app in production.
I'd prefer to have Capistrano set at 3.6.x system-wide.
one way - sudo apt-mark hold <name>
another way- use gem install instead of apt get and specify the version

Can't install gem using Bundler's Rakefile install task when developing a custom gem

I'm developing a couple of private gems and I think I don't understand correctly the PATH/GEM_PATH and/or Bundler/RVM installation flow, would love if someone could chip in.
I have a repository with two gems (A & B for simplicity sake). I've developed the gems using the scaffolding + following the guidelines provided by this bundler tutorial.
Thanks to the Bundler project I have a few Rakefile tasks like rake build, rake install, rake install:local and rake release. Because of the private nature of these gems I can't release them to RubyGems (and we haven't looked into hosting our rubygems).
My machines are using RVM to manage ruby versions and Bundler version 1.15.1
What I want to do: Assuming a new machine/developer trying out the project, ideally we would cd into each of the subfolders (currently 2, gem A and gem B), run rake install and after that we should have the gems available system wide for the current user.
What is happening: The gems are built and work properly, but they are only available inside the subfolder of each gem i.e. gem A is only available inside the subfolder A and gem B is only available inside subfolder B.
What I've tried: So, after rake build/install/install:local a new .gem file is generated under pkg. I've tried to manually install the "compiled" file using gem install pkg/A.gem, gem install --local pkg/A.gem and gem install --local --user-install pkg/A.gem without success. (there are plenty of SO questions/answers about this)
I believe this has something to do with the PATH variables, but like I said before I don't fully understand the way they are managed. I get the following results from these commands:
# Our gem
> gem which A
/home/ubuntu/.rvm/gems/ruby-2.4.0/gems/A-0.1.8/lib/A.rb
# Pry, available globally
> gem which pry
/home/ubuntu/.rvm/gems/ruby-2.4.0/gems/pry-0.11.1/lib/pry.rb
I've been lost and frustrated for far too long now, any help is appreciated. Also open to hear suggestions of better private gem installation flows :)
Yes, it has something to do with your PATH variables. Your installation seems to be good.
I advise you to first affirm your gems installation path with:
echo $GEM_HOME
The double check your PATH to ensure its present and also confirm that the GEM home is also where the gem got installed into from the rake install
echo $PATH
If not, put it in your path and you should be fine with something like this:
echo PATH=$PATH:$GEM_HOME >> ~/.bashrc
source ~/.bashrc
Build your gem as per that guide you linked. You should end up with a gem file. Distribute this as you see fit (I use rsync/crontab to download newer gem versions but anything goes). User can install the gem as follows:
gem install --user-install /path/to/your/file.gem
This will install the gem in the user's ~/.gem/ruby/<version>/gems/<your-gem-name> directory.
Tried it with an empty gem (foodie, as in that example guide) and it works fine. But if you don't specify the --user-install parameter it will try to install in the system ruby dir (/usr/lib/ruby/gems...)

how to set bundler config to use system libraries whenever necessary

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

deploying a specific git version of a gem into passenger via rvm global gemset

We've a deploy issue I'm having with passenger using a specific github
version of the handsoap gem, which is specified in the Gemfile.
bundle states:
Using handsoap (1.1.8) from git://github.com/unwire/handsoap.git (at e6f79ec)
[ rubyapp]$ bundle show handsoap
/usr/local/rvm/gems/ruby-1.9.3-p286#global/bundler/gems/handsoap-e6f79ec9d6a3
[ rubyapp]$ bundle show capybara
/usr/local/rvm/gems/ruby-1.9.3-p286#global/gems/capybara-1.1.3
(There's many other gems but I thought I'd add capybara to show where they are. There's no other specific github versioned gems)
Sadly we've not got root access to change to another gemset - i.e. not
global and it was installed before the project was setup, so we were not able to specify a custom gemset before, as you would in the local development environment. This version of the gem is needed unfortunately.
Passenger reports:
git://github.com/unwire/handsoap.git (at e6f79ec) is not checked out.
Please run bundle install (Bundler::GitError)
I've tried a gemset empty global , and a following bundle install
I've tried a gemset empty global , and a following bundle install
I've tried
rm /usr/local/rvm/gems/ruby-1.9.3-p286#global/bundler/gems/handsoap-e6f79ec9d6a3
and a bundle install
all which give the same passenger error as specified above.
Any help would be appreciated. The application has been working previously within the global gemset - but with a previous version of handsoap, but now it's time for a new deploy of the code.
Spent a couple of hours now trying out different options.
Cheers in advance,
Ian.

Using Bundler in deployment

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).

Resources