DEV Community

Anatoli Babenia
Anatoli Babenia

Posted on • Updated on

Regenerate Gemfile.lock

TL;DR

With Docker.

rm Gemfile.lock
docker run --rm -it -v "$PWD:/app -w /app ruby:2.7 \
    bundle install
Enter fullscreen mode Exit fullscreen mode

With podman.

rm Gemfile.lock
podman run --rm -it -v "$PWD":/app -w /app \
    --security-opt label=disable ruby:2.7 \
    bundle install
Enter fullscreen mode Exit fullscreen mode

For info specific to Heroku scroll down.

Backstory

Some time ago I've got a request from my friend to edit information on his website for which the original developer had gone. The web site was written in Ruby on Rails and it was deployed on Heroku using their cedar-14 stack running on Ubuntu 14.

With no experience with Rails or Ruby or Heroku it took almost two weeks to get that app properly backed up and code running on newer heroku-18 base. The first thing I had to do is to brine dependencies in Gemfile.lock up-to-date to close security bugs and possible glitches on newer OS.

Since then I repeated the operation several times for different Ruby projects and recorded it on dev.to for reference.

I didn't want to ruin anything in my friend's existing deployment, so I made a copy of the web site both on new Heroku heroku-18 plan and on local machine. My local machine is using Fedora, and to avoid configuration drift (and keep my system clean) I did all work in a Linux container.

Creating Linux container

There are many tools to work with Linux containers. I use podman.

Make sure you are in your project dir, because it will be shared with the software in container.

NAME=$(basename "$PWD")
podman run -v "$(pwd)":"/root/$NAME":z -w "/root/$NAME" -it heroku/heroku:18-build
Enter fullscreen mode Exit fullscreen mode

NAME= takes the name of the current dir. -v makes the current dir available inside /root directory in container, and makes it the current dir when container starts. -it allows to type commands when container starts.

As I used Heroku, it was important to find an image with all development libraries, needed to compile and install some gems. At first I used just heroku:18 where I had to spend a day or two to find out and install all the dependencies. Then I found the reference to heroku:18-build image at https://devcenter.heroku.com/articles/heroku-18-stack#heroku-18-docker-image

Updating Gemfile.lock

The next problem I spent a day or two was a problem with bundler installer. It is not included in herokiu:18-build image, and I discovered that the latest bundler 2.x doesn't work on Heroku. I found a way to install 1.x.

gem install bundler --version "~> 1"
Enter fullscreen mode Exit fullscreen mode

The rest of it came easy. Remove Gemfile.lock and regenerate it using bundler install.

bundler install
Enter fullscreen mode Exit fullscreen mode

Heroku summary

Run this.

podman run -v "$(pwd)":"/root/app":Z -w "/root/app" -it heroku/heroku:18-build
Enter fullscreen mode Exit fullscreen mode

And then inside container this.

gem install bundler --version "~> 1"
rm Gemfile.lock
bundle install
Enter fullscreen mode Exit fullscreen mode

If you've got this error message.

# bundle install
Your Ruby version is 2.6.5, but your Gemfile specified ~> 2.5.7
Enter fullscreen mode Exit fullscreen mode

Then do.

rm Gemfile.lock
✗ podman run -v "$(pwd)":"/app":Z -w "/app" -it ruby:2.5 bundle install
Enter fullscreen mode Exit fullscreen mode

Top comments (0)