How do I change the bundler called in Capistrano 3? - ruby-on-rails

I am deploying in a multiuser, multiserver environment (Site5).
I am deploying a rails 4 app. The default environment is ruby 1.8.7, rails 3.0.
There is access to local versions of ruby,
Things are working until the bundler is called.
Here's the error snippet:
INFO [4439d586] Running /usr/bin/env bundle install --path /home/username/apps/todos/shared/bundle --without development test --deployment --quiet as username#dirktaylor.ca
DEBUG [4439d586] Command: cd /home/username/apps/todos/releases/20160121174533 && ( export RUBY_BIN_PATH="/usr/local/ruby20/bin" PATH="/usr/local/ruby20/bin:/usr/username/ruby/gems/gems/bundler-1.11.2/exe:$PATH" ; /usr/bin/env bundle install --path /home/username/apps/todos/shared/bundle --without development test --deployment --quiet )
DEBUG [4439d586] Gem::InstallError: i18n requires Ruby version >= 1.9.3.
DEBUG [4439d586] An error occurred while installing i18n (0.7.0), and Bundler cannot continue.
Make sure that `gem install i18n -v '0.7.0'` succeeds before bundling.
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as username#dirktaylor.ca: bundle exit status: 5
bundle stdout: Gem::InstallError: i18n requires Ruby version >= 1.9.3.
An error occurred while installing i18n (0.7.0), and Bundler cannot continue.
Make sure that `gem install i18n -v '0.7.0'` succeeds before bundling.
bundle stderr: Nothing written
As you can see, I am setting environment variables before the bundle command is called.
So, here's what I've figured...
Because Capistrano 3 is executing everything with /usr/bin/env and /usr/bin/env bundle install ... in particular, it is not finding the correct version of bundler to use.
username#dirktaylor.ca [~2]# /usr/bin/env bundle -v;whereis bundle
Bundler version 1.2.1
bundle: /usr/bin/bundle
(Note: /usr/bin/env is linked to /bin/env )
I have installed the current user of bundler (gem install bundler) which is now in ~/ruby/gems/gems/bundler-1.11.2 with executable script at ~/ruby/gems/gems/bundler-1.11.2/exe/bundle
So? Now What?
1) How can I get this version of bundler to execute?
2) Also, inside the script it calls #!/usr/bin/env ruby. Should I change this to the correct ruby path?
3) I saw this solution for Cap 2 elsewhere:
set :bundle_cmd, "/usr/username/ruby/gems/gems/bundler-1.11.2/exe/bundle"
set :bundle_dir, "/usr/username/ruby/gems/gems/bundler-1.11.2"
So the question remains: How do I change the bundler called in Capistrano 3?
(Finally: Can this be solved without rvm?)

In Capistrano 3 there is a concept of a "command map" that lets you override the string used for any arbitrary command. In the case you want to map bundle to /usr/username/ruby/gems/gems/bundler-1.11.2/exe/bundle, let's say.
You do that like this:
# Put this in deploy.rb or production.rb, etc.
SSHKit.config.command_map[:bundle] = "/usr/username/ruby/gems/gems/bundler-1.11.2/exe/bundle"

Related

Ruby 2.6.1 and Bundler 2.0.1 to Heroku : should I write a Procfile?

I'm facing errors I can't handle while trying to deploy an app to Heroku (it's my first time).
# ERROR when I try to `git push heroku master`
remote: -----> Detecting rake tasks
remote:
remote: !
remote: ! Could not detect rake tasks
remote: ! ensure you can run `$ bundle exec rake -P` against your app
remote: ! and using the production group of your Gemfile.
remote: ! Activating bundler (2.0.1) failed:
remote: ! Could not find 'bundler' (2.0.1) required by your /tmp/build_e569680f858939ef8f1f8ef3e8902eff/Gemfile.lock.
remote: ! To update to the latest version installed on your system, run `bundle update --bundler`.
remote: ! To install the missing version, run `gem install bundler:2.0.1`
remote: ! Checked in 'GEM_PATH=/tmp/build_e569680f858939ef8f1f8ef3e8902eff/vendor/bundle/ruby/2.6.0', execute `gem env` for more information
remote: !
remote: ! To install the version of bundler this project requires, run `gem install bundler -v '2.0.1'
# heroku buildpacks
=== staging-det-music Buildpack URLs
1. heroku/nodejs
2. heroku/ruby
# Gemfile.lock
RUBY VERSION
ruby 2.6.1p33
BUNDLED WITH
2.0.1
I've tried several solutions, like:
running RAILS_ENV=production bundle exec rake assets:precompile (see here)
adding the RAILS_SERVE_STATIC_FILES key (same)
upgrade Ruby to 2.6.3 (see here, can't find 2.6.3 with rbenv nor rvm)
I believe it might be due to this issue. Am I concerned by this point ?
2) When using binstubs to run a command instead of bundle exec the wrong
version of Bundler can get activated when using Ruby 2.6.x. This bug
is reported to Ruby Core and will be fixed when Ruby 2.6.3 is
released.
In the short term, the workaround is to ensure all commands in the
Procfile and app.json are prefaced with bundle exec. For example:
web: bundle exec bin/rails server -p $PORT -e $RAILS_ENV
worker: bundle exec sidekiq -C config/sidekiq.yml
As a newbie I feel really lost, could anyone help me on this ?
Thanks for your time
SOLUTION: found here removing BUNDLED WITH and the following line in Gemfile.lock
There are known issues with Bundler 2 on Heroku, including this one:
A Gemfile.lock that specifies bundler 2.0.2 does not work with bundler 2.0.1
If you attempt to deploy an app that uses bundler 2.0.2 onto the Heroku platform with bundler 2.0.1 you may get this error:
`find_spec_for_exe': can't find gem bundler (>= 0.a) with executable bundle (Gem::GemNotFoundException)
This is due to a bug in the Rubygems bundler version checking code. To avoid this issue, upgrade your Ruby version. It is fixed in 2.5.5+ and 2.6.3+. If you do not update, your Ruby version then every new release of Bundler 2.x will trigger this issue.
Upgrade Ruby to at least version 2.6.3 locally, update the ruby version in your Gemfile, bundle install, commit the changes, and redeploy.

Install Gitlab on Mac OS 10.12 failed at 'Charlock_holmes (0.7.3)'

I want to install Gitlab on Mac OS X. Therefore I followed
Installation Guid for Gitlab on OS X
However, I get into trouble when I install ruby gems by bundle.
bundle install --deployment --without development test mysql aws kerberos
resulted in,
Gem files will remain installed in /Users/git/gitlab/vendor/bundle/ruby/2.3.0/gems/charlock_holmes-0.7.3 for inspection.
Results logged to /Users/git/gitlab/vendor/bundle/ruby/2.3.0/extensions/x86_64-darwin-16/2.3.0-static/charlock_holmes-0.7.3/gem_make.out
An error occurred while installing charlock_holmes (0.7.3), and Bundler cannot continue.
Make sure that `gem install charlock_holmes -v '0.7.3'` succeeds before bundling.
In Gemfile:
gitlab_git was resolved to 10.5.0, which depends on
github-linguist was resolved to 4.7.6, which depends on
charlock_holmes
I tried Unable to install version 0.7.3 on Mac OS Sierra in order to install charlock_holmes.
gem install charlock_holmes -v 0.7.3 -- --with-cxxflags=-std=c++11
it resulted in successfully installed.
Building native extensions with: '--with-cxxflags=-std=c++11'
This could take a while...
Successfully installed charlock_holmes-0.7.3
Parsing documentation for charlock_holmes-0.7.3
Done installing documentation for charlock_holmes after 0 seconds
1 gem installed
So I am confused why I can not keep install gems..
I install all gems by
bundle install --no-deployment --without development test mysql aws kerberos
However, I got in other error...
bundle exec rake gitlab:setup RAILS_ENV=production
resulted in,
D, [2018-01-25T16:22:14.066436 #89351] DEBUG -- sentry: ** [Raven] compared with non class/module excluded from capture due to environment or should_capture callback
rake aborted!
TypeError: compared with non class/module
I had this problem today. What fixed it for me was updating icu4c, then re-installing ruby which will compile with the updated version. I use ruby-install and chruby so it was basically like this:
$ brew upgrade icu4c
$ chruby 2.3.4 # change to previous ruby (if necessary)
$ rm -rf .rubies/ruby-2.4.4 # drop ruby compiled with old version of icu4c
$ ruby-install ruby 2.4.4 # don't forget to restart your terminal after this completes
$ ruby -e 'puts RUBY_VERSION'
2.4.4
$ bundle install # now it works!

Json -v 1.8.6 will not install as part of capistrano deploy

This question has been asked a couple of times on stackoverflow and other forums but I can't seem to get passed this error that I am getting. When I run capistrano production deploy, I get this error as part of the deploy process.
cap production bundler:install
00:00 bundler:install
01 bundle install --path /var/local/blackduck_flock_rails/shared/bundle --without development test --deployme…
01 An error occurred while installing json (1.8.6), and Bundler cannot continue.
01 Make sure that `gem install json -v '1.8.6'` succeeds before bundling.
(Backtrace restricted to imported tasks)
cap aborted!
SSHKit::Runner::ExecuteError: Exception while executing as serv-deployer#oh-utility01.dc1.lan: bundle exit status: 5
bundle stdout: An error occurred while installing json (1.8.6), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.6'` succeeds before bundling.
bundle stderr: Nothing written
Tasks: TOP => bundler:install
(See full trace by running task with --trace)
I've taken a look at my log/capistrano.log file and here are the relevant contents that I was looking at to trouble shoot.
# Logfile created on 2017-05-03 14:42:16 -0400 by logger.rb/54072
INFO ---------------------------------------------------------------------------
INFO START 2017-05-03 14:42:16 -0400 cap production bundler:install
INFO ---------------------------------------------------------------------------
DEBUG [ec1d281e] Running if test ! -d /var/local/blackduck_flock_rails/current; then echo "Directory does not exist '/var/local/blackduck_flock_rails/current'" 1>&2; false; fi as serv-deployer#oh-utility01.dc1.lan
DEBUG [ec1d281e] Command: if test ! -d /var/local/blackduck_flock_rails/current; then echo "Directory does not exist '/var/local/blackduck_flock_rails/current'" 1>&2; false; fi
DEBUG [ec1d281e] Finished in 0.328 seconds with exit status 0 (successful).
DEBUG [4f633904] Running /usr/bin/env bundle check --path /var/local/blackduck_flock_rails/shared/bundle as serv-deployer#oh-utility01.dc1.lan
DEBUG [4f633904] Command: cd /var/local/blackduck_flock_rails/current && /usr/bin/env bundle check --path /var/local/blackduck_flock_rails/shared/bundle
DEBUG [4f633904] Warning: the running version of Bundler is older than the version that created the lockfile. We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.
DEBUG [4f633904] The following gems are missing
* json (1.8.6)
* tzinfo (1.2.2)
* activesupport (4.2.6)
etc. etc..........
DEBUG [4f633904] * uglifier (3.0.4)
DEBUG [4f633904] Install missing gems with `bundle install`
DEBUG [4f633904] Finished in 0.179 seconds with exit status 1 (failed).
INFO [6c99e662] Running /usr/bin/env bundle install --path /var/local/blackduck_flock_rails/shared/bundle --without development test --deployment --quiet as serv-deployer#oh-utility01.dc1.lan
DEBUG [6c99e662] Command: cd /var/local/blackduck_flock_rails/current && /usr/bin/env bundle install --path /var/local/blackduck_flock_rails/shared/bundle --without development test --deployment --quiet
DEBUG [6c99e662] An error occurred while installing json (1.8.6), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.6'` succeeds before bundling.
So the first thing to note. The log is telling me that the running version of bundler is out of date and that I should install the newest one. Here is what I don't understand though. On my developing machine, I have Bundler version 1.14.6. On the targeting server that I am trying to deploy to, I also have Bundler version 1.14.6. I've confirmed it on both machines and they are indeed the same. Second, I have the same ruby versions for both developing machine and target machine. The ruby version is 2.2.5.
Second, when I run gem list on the target server, I can see that json 1.8.6 is installed.
json (1.8.3, 1.8.1)
What gives?
Finally, the problem has to be in this directory on the target machine /var/local/blackduck_flock_rails/shared/bundle. Inside the bundle directory, I have a ruby folder that has 1.9.1 and 2.2.0. Could this be the source of the problem. I'm stumped on this one and it seems that questions like these always relate to something specific on someone's machine that won't necessarily be applied. Help would be greatly appreciated.
The most probable cause is you're missing some system dependencies that capistrano cannot install.
Ssh to your server and try installing sudo apt-get install libgmp3-dev
If it doesn't fix the problem, ssh again and run the gem install json -v '1.8.6' as it tells you and post the error message you get from it here.

EC2 - Gem bundler is not installed, run `gem install bundler` first

I am deploying a rails app to EC2 with using Capistrano, but within the deployment process, I got
...
ERROR: Gem bundler is not installed, run `gem install bundler` first.
command finished in 344ms
*** [deploy:update_code] rolling back
...
I am not sure what's the problem, here's the list of installed gems on EC2:
bundler (1.3.5)
rake (10.0.4)
rubygems-bundler (1.1.1)
rvm (1.11.3.7)
ruby -v
ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-linux]
Can anyone give me a tip how to fix it?
Thanks
Can you give some details:
Are you using rvm ?
What is the rails version in your Gemfile ?
Gem version ?
If you are using rvm, check for the gemset being used, remove .bundle and do a fresh $ bundle to install the gems.
Post the entire o/p from command $ gem list from your project folder.

bundle fails with rake error on vagrant

I've been following the railscast on setting up Vagrant with rails found here:
http://railscasts.com/episodes/292-virtual-machines-with-vagrant
I have rbenv running on vagrant with a slightly more updated version of ruby(1.9.3p125). Everything goes fine until I try to bundle. Here's the error I get:
vagrant#lucid32:/vagrant$ bundle
Fetching gem metadata from http:rubygems...
Fetching gem metadata from http:rubygems...
Resolving dependencies...
Using rake (10.0.3)
Errno::EPROTO: Protocol error - /vagrant/bin
An error occurred while installing rake (10.0.3), and Bundler cannot continue.
Make sure that gem install rake -v '10.0.3' succeeds before bundling.
I've tried gem installing that version of rake, then running rbenv rehash which seems to install, but running bundle again still gives me the same error.
I was able to resolve this by downgrading bundler from 1.3.2 to 1.2.5.
rvm use #global
gem uninstall bundler
gem install bundler -v 1.2.5
# switch back to the default gemset
rvm use
bundle install
# everything should work now
The only other thing that I changed was I reverted from rvm 1.18.19 to 1.17.10, but I am not positive that step is necessary.

Resources