When upgrading from one major rails release to the next it is very helpful to run your code base on both versions in parallel.
Currently rails 6 is just around the corner. Lets give it a try.
Installed gems and their versions are managed by bundler
within the Gemfile
.
To be able to install different sets of module versions we can use multiple
Gemfile
:
cp Gemfile Gemfile_rails6
This would duplicate everything. To avoid duplication we create an additional Gemfile.common
to include gems that are common to both:
cp Gemfile Gemfile.common
Gemfile:
source 'https://rubygems.org'
# the gems that differ
gem 'rails', '~> 5.2'
gem 'ransack'
# common gems go there
eval_gemfile 'Gemfile.common'
Gemfile_rails6:
source 'https://rubygems.org'
# different gems required for rails6
gem 'rails', '6.0.0.rc2'
gem 'ransack', git: 'https://github.com/activerecord-hackery/ransack'
# common gems go there
eval_gemfile 'Gemfile.common'
All the rest goes to Gemfile.common
.
Now you can switch between rails version using the BUNDLE_GEMFILE
environment variable:
export BUNDLE_GEMFILE="Gemfile_rails6"
cp Gemfile.lock Gemfile_rails6.lock
bundle install
This will start with your existing gems versions and upgrade to rails 6.
You may skip the step of copying the lock file to start with the latest gems.
If you’re using a dockerized environment you can use it the following way.
Dockerfile:
ARG BUNDLE_GEMFILE
ENV BUNDLE_GEMFILE=${BUNDLE_GEMFILE:-Gemfile}
# COPY Gemfile*
# RUN bundle install
docker-compose.yml
version: '3'
services:
web:
build:
args:
- "BUNDLE_GEMFILE=${BUNDLE_GEMFILE}"
context: .