Anatoli Babenia
Posted on December 14, 2019
TL;DR
With Docker.
rm Gemfile.lock
docker run --rm -it -v "$PWD:/app -w /app ruby:2.7 \
bundle install
With podman
.
rm Gemfile.lock
podman run --rm -it -v "$PWD":/app -w /app \
--security-opt label=disable ruby:2.7 \
bundle install
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
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"
The rest of it came easy. Remove Gemfile.lock
and regenerate it using bundler install
.
bundler install
Heroku summary
Run this.
podman run -v "$(pwd)":"/root/app":Z -w "/root/app" -it heroku/heroku:18-build
And then inside container this.
gem install bundler --version "~> 1"
rm Gemfile.lock
bundle install
If you've got this error message.
# bundle install
Your Ruby version is 2.6.5, but your Gemfile specified ~> 2.5.7
Then do.
ā rm Gemfile.lock
ā podman run -v "$(pwd)":"/app":Z -w "/app" -it ruby:2.5 bundle install
Posted on December 14, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.