Capistrano bundle install trying to install development gems on server - ruby-on-rails

I have a development gem that is trying to be installed on the server via capistrano and is failing b/c i'm pointing to github at the moment.
Why is this gem trying to be installed on my server anyways?
Gemfile snippet:
gem 'capistrano-local-precompile', '~> 1.0', :git => 'git#github.com:stve/capistrano-local-precompile.git', :branch => 'cap3', :group => :development, require: false
Capistrano snippet output:
00:08 bundler:install
01 ~/.rvm/bin/rvm 2.3.3 do bundle install --path /var/www/csmschedule/shared/bundle --without development test --quiet --no-cache
01 The authenticity of host 'github.com (192.30.253.112)' can't be established.
01
01 RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.

Is the GIT section for capistrano-local-precompile present in your Gemfile.lock, and is that lock file committed to your repo? In other words, have you run bundle install locally, committed both Gemfile and Gemfile.lock, and pushed those changes before running cap deploy?
Bundler needs to know the dependencies of the capistrano-local-precompile gem in order to do version resolution. Even if you specify --without development, it still needs this information (because version requirements of development gems can affect version resolution for production ones).
If your lock file is not present or if it is out of date (i.e. capistrano-local-precompile is not in the lock file), then Bundler needs to download the gem from GitHub in order to update the lock file.
On a related note: I notice you are not using --deployment in the bundle command on the server. That is probably not a good idea. You should use --deployment so that Bundler checks that your Gemfile.lock is up to date, as described here:
http://bundler.io/v1.15/man/bundle-install.1.html#DEPLOYMENT-MODE

Related

How to manually update a gem in the capstrino environment

We have a codebase, which is used as a gem in the older codebase. After deployment we see that, the older code in the gem is getting executed. Now we want to manually update the gem in the server
here is what capistrino is doing
bundler:install
01 ~/.rvm/bin/rvm 2.3.0 do bundle install --path /home/deployer/bla/shared/bundle --without development test --deployment --quiet
01 Warning, new version of rvm available '1.28.0', you are using older version '1.27.0'.
01 You can disable this warning with: echo rvm_autoupdate_flag=0 >> ~/.rvmrc
01 You can enable auto-update with: echo rvm_autoupdate_flag=2 >> ~/.rvmrc
So I went into the bundle folder and I did
bundle update gem_name.
It said it could not find the gemfile. And the contents of the bundle folder is just ruby. Is there a way that I can manually update the gem? Any help would be greatly appreciated.
Bundler doesn't work that way. Even if you updated the gem, if your Gemfile/Gemfile.lock still reference the old version, that's the one that will be loaded. If it's not available, then your app won't boot.
If you want to update the gem in your production environment, you need to run bundle update gem_name inside your app directory, where the Gemfile is located. Assuming you haven't picked a too-specific version in your Gemfile, this will modify your Gemfile.lock and install the new gem.

capistrano deployment error after Bundler upgrade and adding source block

The latest branch of my project includes changes to the Gemfile based on the upgrade to Bundler 1.10.5, notably the use of a source block for two internal gems. This appears to be the cause of a problem when attempting to deploy to the testing server, where capistrano throws an error and rolls back the deploy.
Command generating errors:
bundle install --gemfile /path/to/Gemfile --path /path/to/shared/bundle --deployment --without development test
Error message (private data anonymized but otherwise as in the original):
You are trying to install in deployment mode after changing
your Gemfile. Run `bundle install` elsewhere and add the
updated Gemfile.lock to version control.
You have deleted from the Gemfile:
* internal_gem1 (= 0.1.11)
* internal_gem2 (= 0.0.6)
You have changed in the Gemfile:
* internal_gem1 from `no specified source` to `rubygems repository
http://rubygems.org/, https://REDACTED#gem.fury.io/me/`
* internal_gem2 from `no specified source` to `rubygems repository
http://rubygems.org/, https://REDACTED#gem.fury.io/me/`
Gemfile contains lines:
source 'http://rubygems.org'
source 'https://REDACTED#gem.fury.io/me/' do
gem 'internal_gem1', '0.1.11' #, :path => '/path/to/gem/optional'
gem 'internal_gem2', '0.0.6'
end
gem "bundler", "~> 1.7"
...
# more gems and some groups follow
...
BUNDLED WITH
1.10.5
Based on common sense and a comment to this answer, I tried running gem install bundler -v '1.10.5' on the testing server, and it appears to have installed (installation messages showed success and gem which bundler returns a path containing the new version number), but there was no change in the deployment error.
Both Gemfile and Gemfile.lock are tracked in git and get deployed to the server (as per this answer). There is no vendor/cache directory present (as per this answer). Everything works smoothly locally, and deployment of a branch without the source block in the Gemfile went smoothly just a few hours ago. How can I fix this Bundler deployment problem?

Running "bundle update" tries to install production gems even in development?

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

Gem list contains multiple dependencies to a certain gem

I had unicorn 4.5.0 and after I did bundle update, I observe different versions of the same gem even though I wanted to use the latest version.
unicorn (4.6.1, 4.5.0)
How do I instruct the bundler to just keep the latest version.
As far as I can see you cannot instruct bundler to keep only the latest version when updating. You can delete all the old versions of all gems in one go:
bundle exec gem cleanup
(Reference)
You can instruct bundler to just use one version by putting that version in the gem file. Sometimes, I have had conflicts with rake, even though I did not explicitly have rake in my Gemfile, so I had to put the rake version that would be usable by all the other gems at the top of my Gemfile.
If your issue is that you used to use unicorn 4.5.0, and now it has installed unicorn 4.6.1 in you local gem source, you can tell gem to uninstall the version you no longer need.
gem uninstall unicorn --version 4.5.0
If you did a bundle --deployment and populated the vendor/bundle directory, and that is where you want to remove the gem from, then I usually just delete the gem directory, however, I think you can run bundle with --path, like the following:
bundle --deployment --path vendor/bundle
gem uninstall unicorn --version 4.5.0
When you run bundler, it remembers the settings. I painfully discovered this regarding the --without switch. The --path setting will tell gem to use the local vendor/bundle directory as your local gem source. Remember to set the path back by running bundle again.

Bundler, Rails3: how to avoid git check of edge gems in :test group during deploying?

I have such lines in Gemfile:
group :test do
...
gem 'cucumber', :git => "git://github.com/aslakhellesoy/cucumber.git"
...
end
When I try do deploy on server via bundle install --deployment --quiet --without development test, I get an error:
sh: git: command not found
** An error has occurred in git when running `git clone "git://github.com/aslakhellesoy/cucumber.git" "/home/test/rails_apps/test_app/shared/bundle/ruby/1.8/cache/bundler/git/cucumber-3eb3f1a09813a1271fada66aac31d953ef2ad625" --bare --no-hardlinks. Cannot complete bundling.
I have no git executable on server. But I don't want to use git because cucumber in :test group, and I execute bundler with "--without test"!
What should I do?
There are no way to do this. Because this is feature of bundler
Note that on bundle install, bundler
downloads and evaluates all gems, in
order to create a single canonical
list of all of the required gems and
their dependencies. This means that
you cannot list different versions of
the same gems in different groups. For
more details, see Understanding
Bundler.
http://gembundler.com/man/gemfile.5.html (see GROUPS part)
What about you haven't git or any gems at your server. You should use bundle pack. But, now bundle pack don't work with git. Then you should pack git sources manually:
cd vendor/git
git clone git://github.com/foo/foo.git
Then, in your Gemfile,
gem "foo", :path => "vendor/git/foo"
.
http://github.com/carlhuda/bundler/issues/labels/git#issue/67

Resources