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?
Related
I want to get a Gem's version without running bundle install.
Which is to say I want figure out what version bundle is planning to install without actually installing the gem.
Say read it from the Gemfile.lock(and Gemfile) combined.
Is there a way I can resolve what version bundler plans to install?
I need this because I want to cache the expensive installs while running docker build.
Gems like rails(nokogiri) take a while to install and I would like to do gem install rails -v ... in a previous step before running bundle install.
For this purpose i need to get the rails version before hand
If you add a new gem to your gemfile, but don't do bundle install, it doesn't install yet. Instead, you can run bundle lock, which generates a new lock file. This includes the gem version of the new gem that would be installed.
By running bundle show new_gem, it shows it isn't actually installed.
To be sure maybe get a backup of the original Gemfile.lock before running the command though.
By default if no version is specified in the Gemfile, running bundle install will attempt to install the latest version of the gem which is compatible with the rest of the gems and ruby version in your project. This will create a Gemfile.lock file if one doesn't already exist. If a Gemfile.lock file is already committed to git repo, it should then install the versions specified in Gemfile.lock. The point of bundler is to handle dependencies to insure your stack works correctly.
To see the version of a gem bundler is currently using you can run
bundle show rails
You will probably want to specify the ruby version in the Gemfile for example
ruby '~> 2.5' #
You can specify exact version of a gem in the Gemfile like this which you should be able to rely on to be the version bundler will install so long as it's compatible with the rest of the stack. bundle install will throw errors if there are incompatible gem versions.
gem 'rails', '4.2.11' # this will always install only this version.
You may also use pessimistic operator (~>) to set for only minor updates
gem 'influxdb', '~> 0.6.1' # could go to 0.6.2 but never 0.7.0
You can also set minimum versions like this although it's probably not what you need for your question.
gem 'pg_query', '>= 0.9.0'
If you have a Gemfile.lock already in your repo you can see which version would be installed by running for example:
gem show rails
Which would show you the version and weather it or not it is currently installed.
For more info see bundle --help
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
I'm testing a gem in a Rails project.
The current Gemfile:
gem 'mygemname', path: '/path/to/my/gem'
When I edit a gem locally I can build the gem, remove the gem from Gemfile, run bundle install, add the gem back to the Gemfile and run bundle install again. Is there an easier way to do this locally?
If you use bundle config local.GEM_NAME /path/to/local/git/repository from the command line then every time you reload your application it will load the latest source from your file system.
To remove the changes (when you have pushed your code to GitHub or RubyGems), you need to run bundle config --delete local.GEM_NAME
Source: http://bundler.io/v1.10/git.html
You can bump your Gem's version. Next time you run bundle your gem will be updated to the next iteration.
VERSION = "1.0.0"
Bump the patch version to
VERSION = "1.0.1"
Now just run bundle. Bundler will notice it and log 1.0.1 (was 1.0.0) in the output.
In my Rails app, I have installed the gem sdoc from Github by specifying gem 'sdoc', github: 'voloko/sdoc' in my Gemfile. All was well until I recently updated Bundler to v1.6.0.rc.
Now I get the following error message when Bundler tries to load the gem:
There was a LoadError while loading sdoc.gemspec:
cannot infer basepath from
/Users/manuel/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/sdoc-1a0e80c2d629/sdoc.gemspec:2:in `require_relative'
Does it try to require a relative path? That's been removed in Ruby 1.9.
I've already fixed the issue and submitted a pull request, but I cannot get rid of the "broken" gem!
This is what I tried:
removing the gem from the Gemfile or setting it to a different version
removing Gemfile.lock
deleting the gem folder /Users/manuel/.rbenv/versions/2.0.0-p247/lib/ruby/gems/2.0.0/bundler/gems/sdoc-1a0e80c2d629
gem uninstall sdoc (It doesn't even appear in gem list)
Nothing helped, every time I do bundle install or bundle update afterwards, I get the same error.
Any hints?
First-off: Clarifying a few things
From the Bundler documentation:
Because Rubygems lacks the ability to handle gems from git, any gems installed from a git repository will not show up in gem list. They will, however, be available after running Bundler.setup
Also, after deleting the gem inside the . . . /bundler/gems/ directory, you also should run rbenv rehash. This should get rid of the gem for you.
Answer:
Go to the root directory of your project (where the Gemfile resides) and run bundle clean. You have to pass either --path or --force switches. This should remove gems installed via git (usually if you have those gems installed and listed by gem list).
If you have issues. Delete the directories manually as you already tried and run rbenv rehash.
If I were you I would downgrade Bundler (ie. uninstall the RC release and install the latest stable).
when i run bundle install the first time this will create a gemfile.lock for me
after this my question is :
if i run bundle install for the second time what does bundler do ?
i think it look first at gemfile.lock and check each line, and then look in the gemfile and check gems that not exist in gemfile.lock then install them !!! i'm not sure , and i which if someone can explain that to me (step by step )
second question is :
for example i add a gem like this gem 'nokogiri', '~> 1.4.2' , suppose after 1 month, version 1.4.3 is available. i think it will be installed automatically if i run bundle install again ?
can this new version "with tiny update" break things in my app ?
The duty of Gemfile.lock is to lock the versions of the gems you use.
bundle install installs all gems in your Gemfile that are not in your bundle and records the version in Gemfile.lock.
bundle install only installs the versions of your gems, that are recorder in Gemfile.lock. It will never update any gem.
For updating gems, use bundle update. It looks for new versions of your gems, installs them and records the new versions in Gemfile.lock.
If you specify a version in your Gemfile like in your example
gem 'nokogiri', '~> 1.4.2'
bundle upate would only update nokogiri to revisions < 1.5
Any update (in fact any change) might break your application, but minor updates are supposed to be completely backward compatible (stable API, only new tests, all old test pass)
From the documentation,
(...) the first time you run bundle install (and a Gemfile.lock does not exist), bundler will fetch all remote sources, resolve dependencies and install all needed gems.
If a Gemfile.lock does exist, and you have not updated your Gemfile, bundler will fetch all remote sources, but use the dependencies specified in the Gemfile.lock instead of resolving dependencies.