Bundler 2.2.0 and Ruby 2.7.5 on Docker crashing - ruby

I installed Ruby 2.7.5, and within the Dockerfile, specified bundler (version 2.2.0) to be installed:
RUN gem install bundler -v 2.2.0 --no-document
the output of this is:
INFO[0093] RUN gem install bundler -v 2.2.0 --no-document
INFO[0093] cmd: /bin/sh
INFO[0093] args: [-c gem install bundler -v 2.2.0 --no-document]
INFO[0093] Running: [/bin/sh -c gem install bundler -v 2.2.0 --no-document]
Successfully installed bundler-2.2.0
All seemed to be fine in that install, and bundle works as gems specified in Gemfile are installed. However, when I try to open the console, I see this:
/usr/lib/ruby/2.7.0/rubygems.rb:277:in `find_spec_for_exe': Could not find 'bundler' (2.2.0) required by your /app/Gemfile.lock. (Gem::GemNotFoundException)
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.2.0`
However, it is installed. as you can see from above. Also, when I output the version within the Dockerfile, I see:
Bundler version 2.2.0
It seemed to install fine, however, still see the error above, and it crashes immediately.
Is there something obvious I am doing wrong?

Building a Docker Image with an Updated Bundler Version
You're missing a couple of steps in your Dockerfile build for bundled gems. After you update Bundler, you also need to update your Gemfile.lock and possibly re-run bundle install. There are a lot of options involved, but here's my personal recommendation for your Dockerfile based on your post:
# Note: Don't lock your Bundler version unless you
# have a VERY good reason to do so. Update will
# install or update, as needed.
RUN gem update bundler --no-document \
&& gem clean bundler \
&& bundle update --bundler \
&& bundle install
The key here is that if you don't use bundle update --bundler then the Gemfile.lock will not contain the version of Bundler that you're expecting to call. Recent versions of Bundler will downgrade themselves to the version in the Gemfile.lock if necessary, so this is really the key to the whole thing.
In addition, if you continue to have problems after applying the recipe above, you may need to figure out where Bundler is actually being installed inside your container image. While Bundler (currently) doesn't run from inside your bundle, the required version still needs to be in GEM_HOME, GEM_ROOT, or GEM_PATH in order to be found when you invoke it.
As a final consideration, if you're building your gems locally or modifying your Gemfile.lock and then using an ADD or COPY command to place the Gemfile.lock or any vendored gems into your container image, you need to perform these activities outside of Docker rather than inside the Dockerfile. Based on your original post it doesn't look like you're doing that now, but it's another option to consider as you work on resolving this.

Related

Not able to update Bundler version

I have a gemfile.lock which requires Bundle 2.2.19 . My system has Bundle 1.11.2. Now I ran the following commands:
gem update --system
sudo gem install bundler
Has the following output:
Successfully installed bundler-2.2.31.gem
But after that, I do:
Bundler --version
I still get
Bundler version 1.11.2
And if I try to do
bundle install
I get
You must use Bundler 2 or greater with this lock file
I also tried running
bundler update --bundler
But that does not work either. I also tried uninstalling and reinstalling but while uninstalling, it only uninstalls the 2.2.31 version. Also tried something like
bundle _2.2.31_ install
But it says could not find command. Any suggestions are welcome.

Why can't bundler find rake when it's obviously installed?

I'm trying to migrate a version of Redmine from backup to a new server; I'm migrating from Redmine 3.2.3 to 3.3.0. I installed the new version of Redmine (from Bitnami Stack) on my new server and everything loads properly. When I move my old database into the new version, I have to run
bundle exec rake db:migrate
to migrate my database. But... bundler can't find rake somehow even though gem list shows it clearly installed. Can I force bundler to use the version of rake that I have installed that it says I don't?
I should mention I've done no customization at all, haven't installed any gems, or changed ruby versions or done anything. This is out of the box Redmine.
I noticed after I made the question that I had two versions of rake installed. I removed both and reinstalled rake 11.1.2 and have the same problem.
You are probably using the wrong ruby binary. Note that, the installers for Bitnami Stacks are completely self-contained and run independently of the rest of the software or libraries installed on your system.
Also, taking a look at the screenshots you have shared, you were using ruby 1.9.3 when you have executed ruby -v and the Redmine Bitnami Stacks uses ruby 2.1.9. Probably this is the reason of the issue you are having.
If you want to use the ruby (and the other components) shipped with the Bitnami Stack you need to run the following command:
cd *INSTALLDIR*
./use_redmine
This command will open a new console session with the environment configured to use the stack.
There are two things:
ruby gems available via gem list
ruby gems availbale via bundler
When you are using bundle then bundler is looking for gem from Gemfile. You can have multiple gems installed in your system, but when you are using Gemfile then gem version will be taken from Gemfile.lock
Summing up:
$ bundle exec rake ...
require to have rake gem inside Gemfile
$ rake ...
it will take the newest version of rake gem installed in system
I hope it helps you.
This is how I finally got my Redmine upgraded:
A version of ruby outside of the one provided by Bitnami somehow got installed on this machine as well as another version of bundler. The first thing I did was uninstall the apt-get version of bundler. I had to manually remove /usr/bin/bundler and /usr/bin/bundle for $ which bundle to stop finding bundler even after the removal.
I saw that the Bitnami stack's ruby was version 2.1.x but found Ruby 1.9.3 was installed to /usr/bin/ruby1.9.3/ with $ which ruby. I took the commands from here and removed that version of Ruby.
Running $ ruby -v now gave me nothing as Ruby wasn't installed anymore (even though it was in the Bitnami stack). Bitnami's Ruby then had to be (re?)added to my path in ~/.profile. $ ruby -v now gives me the correct version.
$ gem list was no longer telling me that rake was installed. I tried running $ bundle install where Gemfile is but was complaining about mime-types being locked at a lower version and wouldn't do anything. I got around that with $ bundle update but then ran into the infamous nokogiri problem where it complains that everything required by nokogiri isn't installed.
Since I'd dealt with this before (many many times) I went over to the Nokogiri Website's install page and followed the instructions for troubleshooting on Ubuntu:
sudo apt-get install build-essential patch
sudo apt-get install ruby-dev zlib1g-dev liblzma-dev
and now $ bundle update worked on my Gemfile. Redmine upgraded and my users are about as happy as users can get.

Travis reports odd message of corrupted Gemfile.lock

Im using bundler to install stuff and since I have added Gemfile.lock, travis started to complain with:
Your Gemfile.lock is corrupt. The following gem is missing from the DEPENDENCIES
section: 'echoe'
Of course, everything works locally. It also works using DeployBot. I even installed docker ubuntu and tried, still ok. My Gemfile.lock is not corrupt. Same versions of ruby and bundler is used.
What is going on?
Update
This is something related to bundler version. Im using 1.11.0, but got reports that it worked with eg. 1.8.3. ??
We've seen a very similar issue today on Buildkite due to the recent release of a new bundler version
https://rubygems.org/gems/bundler/versions/1.11.0
We got the build working by stipulating the version of bundler to install.
gem install -v 1.10.6 bundler --no-rdoc --no-ri
and forcing the use of that
bundle _1.10.6_ install
Firstly, remove the gem lock file:
rm -f Gemfile.lock
Then install the dependencies:
bundle install
You can update the dependencies to ensure that you won't get an error:
bundle update

'bundle exec' complains about gem not being installed, even after 'bundle install'

I have a website using Jekyll with Github Pages. After previously messing about with versions and RVM on another computer, on this one I opted to stick with just one version of Ruby and per-project environments using bundler.
I have a pretty simple Gemfile:
[$]> cat Gemfile
source 'https://rubygems.org'
gem 'github-pages'
and bundler config:
[$]> cat .bundle/config
---
BUNDLE_PATH: env
BUNDLE_DISABLE_SHARED_GEMS: '1'
When I run any command (jekyll, gem, irb) through bundle exec, I get a dependency error:
[$]> bundle exec jekyll
Could not find RedCloth-4.2.9 in any of the sources
Run `bundle install` to install missing gems.
However, the bundle is already installed:
[$]> bundle install
Using RedCloth 4.2.9
Using i18n 0.6.11
Using json 1.8.1
[snip]
Using github-pages 29
Using bundler 1.7.7
Your bundle is complete!
It was installed into ./env
I'm at a bit of a loss as to how bundler can think the gems are installed when using one subcommand, but think they're missing when using another.
[$]> which ruby
/usr/local/bin/ruby
[$]> which bundler
/usr/local/bin/bundler
[$]> ruby --version
ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin14]
[$]> bundler --version
Bundler version 1.7.7
After deleting the env directory and reinstalling, I noticed it created subdirectories for two Ruby versions - 2.1.0 and 2.2.0. The latter was my current version of Ruby, but the directory was empty (all the gems were installed into the env/ruby/2.1.0/gems directory). This, combined with Oliver's answer about rbenv, got me thinking about mismatched versions.
I reinstalled bundler with a simple gem install bundler, reran bundle install, and all is good.
It seems in general the answer is to sort out issues with bundler installing for a different version of Ruby than you're actually using. It seems strange to me it would use one thing for bundle install and another for bundle exec, but *shrug* whatever.
I had exactly the same problem after installing rbenv as my Ruby manager. In the end I solved the problem with:
rbenv rehash
(additionally you may need to restart terminal, as per #joel-glovier's comment)
That fact it's complaining about Redcloth 4.2.9 is actually a red herring. Bundler probably can't find any of the gems but Redcloth is the first one it looks for and so it exits imediately with that error.
Basically I'd installed rbenv and ruby 2.2.2 and changed to that version with rbenv global 2.2.2 but I'd forgotten to run rbenv rehash. So I'm guessing when running bundle install it was looking at my previously used version of ruby (system ruby) to see what gems were installed but when running bundle exec jekyll serve it was looking at my new ruby version and not finding any of the gems.
I had to open ./.bundle/config and set
BUNDLE_DISABLE_SHARED_GEMS to true for bundle the gems to be properly locally stored.
I had defined BUNDLE_GEMFILE = /home/app/current/Gemfile in .bashrc file. That broke the bundle exec while deploying a new version to the server. Check with env that you don't have the BUNDLE_GEMFILE defined in your environment variables.
I added the BUNDLE_GEMFILE into the .bashrc file to ease with monit commands. Now I just define the variable in the beginning of the monit command.

Bundler::GemfileNotFound whenever I try to run bundle install

I'm working in kali-linux (a linux distro witch is the continuation of Back-Track, based in Ubuntu, just that now is based on Debian wheezy) for some penetration testing. Everything was working just fine, until I decided to update my systems tools. Now whenever I try to run a tool based on ruby, it trows me:
Could not find gem 'ruby-progressbar (>= 1.1.0) ruby' in the gems available on this machine.
Run `bundle install` to install missing gems.
I proceed to run bundle install but then it comes with Bundler::GemfileNotFound error.
Kali use by default ruby, for using gems. The software don't 'require' any other package but ruby seems not-fully-configured/installed for the problem at hand.
$ ruby --version
ruby 1.9.3p194 (2012-04-20 revision 35410) [i486-linux]
$ rvm
bash: rvm: command not found
$ rbenv
bash: rbenv: command not found
I faced the same problem when I was trying to bundle install without realizing that I was not in the project directory. Make sure you're in the current project directory.
to avoid this error you should be at the root of your application and create GemFile and specify all gems needed in there, and run bundle install
The problem was that for some weird motive Ruby didn't detected that bundler was installed, although the package manager says so.
$ apt-cache policy bundler
bundler:
Installed: 1.3.5-2
Candidate: 1.3.5-2
$ bundle --version
Bundler::GemfileNotFound
I simply run gem install bundler then bundler install as root in the tool root path and everything works as charm.
Do you use rvm or rbenv? If so, make sure you are using a particular ruby version.
For rvm, rvm list and look for an indication next to your ruby version. If the correct one is not listed, run rvm install x.y.z. If the correct one is not selected, run rvm use x.y.z
If you want to segregate your gems for a given project, create a gemset. Otherwise, you should be good to go.
Run gem install bundler. You should not have to do this as sudo. This will install bundler in either the Default rvm gemset, or the selected gemset.
Bundler should now be available and can be run using bundle. This is the same as bundle install.
Try this:
sudo ln -s /var/lib/gems/1.8/bin/bundle /bin/bundle
sudo ln -s /var/lib/gems/1.8/bin/bundler /bin/bundler
Worked for me in debian.

Resources