Docker Ruby Bundler not installing - ruby

My Dockerfile looks like below:
FROM ruby:2.5-alpine
RUN apk update add --no-cache build-base nodejs postgresql-dev
RUN mkdir /my-app
WORKDIR /my-app
COPY Gemfile Gemfile.lock ./
RUN bundle install --binstubs
COPY . .
CMD puma -C config/puma.rb
Now when I try to create an image, it gives following error:
You must use Bundler 2 or greater with this lockfile.
The command '/bin/sh -c bundle install --binstubs' returned a non-zero code: 20
The bundler version Gemfile.lock using is 2.1.4.
I did tried adding following line to Dockerfile:
RUN gem update --system
RUN gem install bundler -v 2.1.4
In that case, I get following error:
ERROR: Could not find a valid gem 'bundler' (= 2.1.4), here is why:
Unable to download data from https://rubygems.org/ - no such name (https://rubygems.org/specs.4.8.gz)
I am using Ubuntu 18.04 system. Anyone had faced this issue before? Any help appreciated.
Thank you in advance.

FROM ruby:2.5-alpine
RUN apk update add --no-cache build-base nodejs postgresql-dev
RUN mkdir /my-app
WORKDIR /my-app
RUN gem update --system
RUN gem install bundler -v 2.1.4
COPY Gemfile Gemfile.lock ./
RUN bundle install --binstubs
COPY . .
CMD puma -C config/puma.rb
So, installing bundler was fine but due IPV6 of rubygems.org is still broken and create issue while fetching inside docker. So, i ran the command using host network.
docker image build --network=host -t my-app .
And this issue was resolved.
Thanks for taking time.

I need to create an answer since I can not post this all into a comment. I realize that this is not a solution for you.
If I use this setup, It runs without an error. Can you please look where it differs from your setup and tests? (please also add this to the question)
dockerfile
FROM ruby:2.5-alpine
RUN apk update add --no-cache build-base nodejs postgresql-dev
RUN mkdir /my-app
WORKDIR /my-app
RUN gem update --system && gem install bundler && bundle --version
# installs bundler 2.1.4
COPY Gemfile Gemfile.lock ./
RUN bundle install
COPY . .
CMD /bin/sh
Gemfile
ruby '2.5.8'
source 'https://rubygems.org'
gem 'flay'
Gemfile.lock
GEM
remote: https://rubygems.org/
specs:
erubis (2.7.0)
flay (2.12.0)
erubis (~> 2.7.0)
path_expander (~> 1.0)
ruby_parser (~> 3.0)
sexp_processor (~> 4.0)
path_expander (1.0.3)
ruby_parser (3.13.1)
sexp_processor (~> 4.9)
sexp_processor (4.12.0)
PLATFORMS
ruby
DEPENDENCIES
flay
RUBY VERSION
ruby 2.5.8p224
BUNDLED WITH
2.1.4
Build and started with:
docker build . --no-cache -t foobar
docker run --it foobar

Related

Bundler 2.2.0 and Ruby 2.7.5 on Docker crashing

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.

Could not find gem 'xcode-install' in any of the gem sources listed in your Gemfile or in gems cached in vendor/cache

when I use this command to run fastlane:
bundle exec fastlane beta
shows error:
~/Documents/GitHub/cruise-open/ios on  main! ⌚ 14:59:47
$ bundle exec fastlane beta ‹ruby-3.0.0›
Could not find gem 'xcode-install' in any of the gem sources listed in your Gemfile or in gems cached in vendor/cache.
Run `bundle install` to install missing gems.
(base)
then I install xcode-install like this:
$ gem install xcode-install ‹ruby-3.0.0›
Fetching xcode-install-2.6.8.gem
Successfully installed xcode-install-2.6.8
Parsing documentation for xcode-install-2.6.8
Installing ri documentation for xcode-install-2.6.8
Done installing documentation for xcode-install after 0 seconds
1 gem installed
(base)
still not fix this problem. what should I do to fix it?
In your Gemfile you need to add this line:
gem "xcode-install"
Right after
gem "fastlane"
And run fastlane command again.

How to find native extension gems installed in ./vendor/bundle with "bundle doctor"

We use a Docker image to run CI builds. The Docker image has a system-installed Ruby. The Docker container has the content of gem env and bundle env as indicated in the gist linked files:
[root#045ce9939883 code]# which ruby
/usr/local/bin/ruby
[root#045ce9939883 code]# ruby -v
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-linux]
[root#045ce9939883 code]# bundle -v
Bundler version 2.0.2
We ran the following commands in the Docker container to install the gems at ./vendor/bundle:
bundle config --local path vendor/bundle
bundle install --jobs 5 --retry 3
We then tarred the entire directory, including ./vendor/bundle so that we can deploy the contents later using capistrano. On the deployment machines, we first untarred the tar file and then ran the cap deploy commands.
bundler on the deployment machines can't seem to locate gems which are built with native extensions in ./vendor/bundle. It seems to find all the other gems just fine:
[jenkins#tel-web-sob-r01-n01 2.1.10]$ bundle doctor
The following gems are missing
* nokogiri (1.10.9)
* nio4r (2.5.2)
* websocket-driver (0.7.2)
* bindex (0.5.0)
* byebug (9.0.6)
* puma (3.9.1)
* ffi (1.9.18)
Install missing gems with `bundle install
[jenkins#tel-web-sob-r01-n01 2.1.10]$ ls -l ./vendor/bundle/ruby/2.5.0/gems/ | grep nokogiri
drwxr-xr-x 7 jenkins jenkins 157 Jun 22 13:05 nokogiri-1.10.9
The deployment machine's gem env and bundle env contents are as linked
What I know so far:
I found that all the extensions are installed in ./vendor/bundle/ruby/2.5.0/extensions/x86_64-linux/2.5.0-static/. If I rename that directory to 2.5.0, it works.
Might be related to this issue.
The Dockerfile with which we are setting up ruby & bundler is similar to this one.
The machines where we deploy the bundled gems are RHEL machines and install ruby from the software collections repositories.
It seems like the deployment machines ruby is built with the --enable-shared=yes flag.
We changed our Dockerfile to configure the ruby build the same way, ./configure --enable-shared=yes. That solved our issue.

Gemfile error when deploying GitHub repo to Heroku

I'm trying to push my GitHub repo to Heroku.
Apparently my Gemfile is incorrect. I've checked it twice, and find no typos or anything, but it complains about rb-inotify being added and removed.
Here's the log:
Ruby app detected
Compiling Ruby
Using Ruby version: ruby-2.2.4
Installing dependencies using bundler 1.11.2
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
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 added to the Gemfile:
* rb-inotify
You have deleted from the Gemfile:
* rb-inotify
Bundler Output: 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 added to the Gemfile:
* rb-inotify
You have deleted from the Gemfile:
* rb-inotify
!
! Failed to install gems via Bundler.
!
! Push rejected, failed to compile Ruby app

Ruby 'bundle install' error when following 'Heroku getting started': Failed to build gem native extension

I followed Heroku getting started from the beginning up to 'bundle install' (step #declare-app-dependencies) and saw an error. Some dependencies seem missing but I don't know how to find what they are. Can anybody tell what I should do?
$ bundle install
Fetching gem metadata from https://rubygems.org/...........
Resolving dependencies...
Using rake 10.3.2
Using i18n 0.6.9
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby2.0 extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
Gem files will remain installed in /tmp/bundler20140919-3839-1mafrop/json-1.8.1/gems/json-1.8.1 for inspection.
Results logged to /tmp/bundler20140919-3839-1mafrop/json-1.8.1/gems/json-1.8.1/ext/json/ext/generator/gem_make.out
An error occurred while installing json (1.8.1), and Bundler cannot continue.
Make sure that `gem install json -v '1.8.1'` succeeds before bundling.
Environment =
linuxmint 64bit as VM guest
ruby 2.0.0p299 (2013-08-29) [x86_64-linux-gnu]
gem -v = 2.0.7
gem list --local = bundler (1.7.3), i18n (0.6.9), rake (10.3.2)
installed Heroku Toolbelt
using the example code as in the instructions
After hours of trial I could finally bundle install. I did
sudo apt-get purge ruby*
sudo apt-get install ruby
sudo apt-get install ruby-dev
sudo gem install bundler
After these, bundle install passed json-1.8.1 without error. Then error came
...
You need to install postgresql-server-dev-X.Y for building a server-side extension or libpq-dev for building a client-side application.
...
so I did
sudo apt-get install libpq-dev
Then bundle install again. And it read Your bundle is complete!.
For your reference, I did the following as well. I do not know if the Heroku getting started example really needs them.
sudo apt-get install postgresql postgresql-contrib
sudo apt-get install libmagickwand-dev python-dev

Resources