Rails container build but no start - macbook M1 - ruby-on-rails

I have an app that I can build the container, but not able to start
The error message when I try to start it:
Activating bundler (~> 2.3) failed:
Could not find 'bundler' (2.3.18) required by `$BUNDLER_VERSION`.
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.3.18`
Checked in 'GEM_PATH=/root/.gem/ruby/2.5.0:/usr/local/lib/ruby/gems/2.5.0:/usr/local/bundle' , execute `gem env` for more information
To install the version of bundler this project requires, run `gem install bundler -v '~> 2.3'`
The Dockerfile already has:
FROM --platform=linux/amd64 ruby:2.5.9-slim-stretch
(...)
ENV BUNDLER_VERSION 2.3.18
RUN gem update --system 3.2.3
RUN gem install bundler -v "$BUNDLER_VERSION"

I had to manually run the bundler install, even it should run on build
docker run bundle install

Related

Error while following GKE tutorial to run rails on GKE

While following https://cloud.google.com/solutions/migrating-ruby-on-rails-apps-on-heroku-to-gke I get the error:
"/usr/local/lib/ruby/2.6.0/rubygems.rb:283:in find_spec_for_exe': Could not find 'bundler' (2.2.15) required by your /usr/src/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.15`
from /usr/local/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
from /usr/local/bin/bundle:23:in `<main>'"
when I try to run: docker build -t ruby-app .
Anybody know what's wrong?
Adding the line
RUN gem install bundler
in the Dockerfile before the line
RUN bundle install
did the trick.

Could not find 'bundler' (2.1.4) required by your /home/rails/webapp/Gemfile.lock. (Gem::GemNotFoundException) running docker build

I've been running into this problem whenever I try to run docker build -t ruby-app ., I get the following error:
Step 6/8 : RUN bundle install
---> Running in daa149748210
/usr/local/lib/ruby/2.6.0/rubygems.rb:283:in `find_spec_for_exe': Could not find 'bundler' (2.1.4) required by your /home/rails/webapp/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.1.4`
from /usr/local/lib/ruby/2.6.0/rubygems.rb:302:in `activate_bin_path'
from /usr/local/bin/bundle:23:in `<main>'
The command '/bin/sh -c bundle install' returned a non-zero code: 1
My Dockerfile is the following:
#Dockerfile
FROM ruby:latest
ENV HOME /home/rails/webapp
RUN apt-get update -qq && apt-get install -y build-essential libpq-dev nodejs
WORKDIR $HOME
ADD Gemfile* $HOME/
RUN bundle install
ADD . $HOME
CMD ["rails", "server", "--binding", "0.0.0.0"]
My bundler versions installed on my machine are the following:
➜ gem list bundler
*** LOCAL GEMS ***
bundler (2.1.4)
bundler-unload (1.0.2)
rubygems-bundler (1.4.5)
And my Gemfile.lock was generated by the following versions of Ruby and Bundler
#Gemfile.lock
RUBY VERSION
ruby 2.7.0p0
BUNDLED WITH
2.1.4
Any help would be very much appreciated!
add
RUN gem install bundler
before you invoke bundler, that should do the trick.
Run sudo gem install bundler:2.1.2 -n /usr/local/bin before you invoke

Dokku fails due to bundler version

I had a Ruby on Rails app up and running with Dokku. When I tried to deploy it again today, I received the following error:
--> Installing dependencies using bundler 2.0.1
Running: bundle install --without development:test --path vendor/bundle --binstubs vendor/bundle/bin -j4 --deployment
Activating bundler (2.0.2) failed:
Could not find 'bundler' (2.0.2) required by your /tmp/build/Gemfile.lock.
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.0.2`
Checked in 'GEM_PATH=vendor/bundle/ruby/2.5.0', execute `gem env` for more information
To install the version of bundler this project requires, run `gem install bundler -v '2.0.2'`
Bundler Output: Activating bundler (2.0.2) failed:
Could not find 'bundler' (2.0.2) required by your /tmp/build/Gemfile.lock.
To update to the latest version installed on your system, run `bundle update --bundler`.
To install the missing version, run `gem install bundler:2.0.2`
Checked in 'GEM_PATH=vendor/bundle/ruby/2.5.0', execute `gem env` for more information
To install the version of bundler this project requires, run `gem install bundler -v '2.0.2'`
!
! Failed to install gems via Bundler.
Not sure how to resolve this and was unable to find any references to this type of problem with Dokku.
The update didn't change the Bundler version for me.
I solved this by changing the buildpack. Syntax for dokku is:
$ dokku config:set --no-restart YOUR_APP BUILDPACK_URL=https://github.com/heroku/heroku-buildpack-ruby.git#v227
#227 gives Bundler 2.2.16 which works with my installed version 2.2.20.
Here is a list of available buildpacks.
I solved this by updating Dokku using their official documentation. After the update, I had no trouble deploying.

How to make bundler work again for non root users ? (after mistakenly using it with root)

I am new to Rails , I ran bundler as root by mistake & now it is not working correctly. I tried to use gem uninstall bundler then gem install bundler but still it is not fixed.
How to make bundler work again for non root users (after mistakenly using it with root)?
Note:
I have installed and use rbenv, but after installing some gems on the system directly
The error that happens is that bundle doctor shows correct missing gems but sudo bundle doctor doesn't as shown below
~/my_ruby_projects/myblog3$ bundle doctor
The latest bundler is 1.16.0.pre.1, but you are currently running 1.15.4.
To update, run `gem install bundler --pre`
The following gems are missing
* execjs (2.7.0)
* coffee-script (2.4.1)
* coffee-rails (4.2.2)
* font-awesome-rails (4.7.0.2)
* temple (0.8.0)
using sudo
~/my_ruby_projects/myblog3$ sudo bundle doctor
The latest bundler is 1.16.0.pre.1, but you are currently running 1.15.4.
To update, run gem install bundler --pre
The Gemfile's dependencies are satisfied
No issues found with the installed bundle
Thanks for your help
update:
I knew that bundle with sudo is correct since it gave the real gems that rails tells me they are missing , if I use bundle install without sudo it gives error as below (even if change it to chmod 777)
~/my_ruby_projects/myblog3$ bundle install
The latest bundler is 1.16.0.pre.1, but you are currently running 1.15.4.
To update, run `gem install bundler --pre`
There was an error while trying to write to `/home/usrname/.bundle/cache/compact_index/rubygems.org.443.29b0360b937aa4d161703e6160654e47/versions`. It is likely that you
need to grant write permissions for that path.
for sudo bundle install it says all is installed but then rails throws error that I need to install gems (which bundle doctor gave without sudo)
/my_ruby_projects/myblog3$ sudo bundle install
The latest bundler is 1.16.0.pre.1, but you are currently running 1.15.4.
To update, run `gem install bundler --pre`
Don't run Bundler as root. Bundler can ask for sudo if it is needed, and installing your bundle as root will break this application for all non-root users on this machine.
Using rake 12.0.0
Using concurrent-ruby 1.0.5
# many other gems
Using redis-rails 5.0.2
Using rails_admin 1.2.0
Bundle complete! 30 Gemfile dependencies, 98 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
Update 2:
rails s was giving error that gem files are missing
but **sudo** rails s worked without errors
You should try changing the owner and setting the correct permissions for your ~/.bundle.
Try:
sudo chown -R <youruser> ~/.bundle
Followed by:
sudo chmod -R 655 ~/.bundle

Downgrading gem version

I have a application I am trying to host on the cloudcontrol server, but the issue is I need the gem -v to be 1.3.7.
I have tired:
cctrlapp APPNAME/default run "gem install rubygems-update -v 1.3.7
cctrlapp APPNAME/default run "gem update --system 1.3.7
But after all this on running cctrlapp APPNAME/default run "gem -v I get 1.8.24.
So my question is, how do I downgrade my gem version?
cloudControl is using bundler to manage the gems.
You need to specify the version in your Gemfile. Make sure it's also used in Gemfile.lock after running the 'bundle install' command.
Note that the Gemfile.lock needs to be included in your git repository.
When you push the next time, this version will be used. You can see this in push command's output, e.g. 'Installing rubygems-update (1.3.7)'.
After the next deploy, you can also verify it via run command (e.g. cctrlapp APPNAME/default run 'gem list').

Resources