Tips for Migrating Ruby on Rails Applications to Bluemix

Share this post:

Ruby_on_Rails.svgWho doesn’t love some Ruby? Bluemix definitely loves Ruby on Rails! Sometimes running a Ruby on Rails app can be a little tricky, so I have included some tips and tricks for migrating your Ruby on Rails app to Bluemix. They will include:

  • Required gems
  • Code tweaks
  • Accessing external databases
  • Deploying your app

Required gems

If you are using PostgreSQL you need to include pg. Sqlite3 is included to get local development working as well. Add the following line to your Gemfile.

gem 'pg'
gem 'sqlite3'

Additionally there are two more gems you should include as well. These gems will be included by some Ruby buildpacks but we should include them just in case.
gem "cf-autoconfig", "~> 0.2.1"
gem 'rails_12factor', group: :production

Code tweaks & external databases

When you deploy your app to Bluemix, the Ruby buildpack will overwrite your database.yml file to pull in the attached DB service. You should have a database.yml file if you are running locally. Below is a pretty standard one:

If you are using Redis and PostgreSQL, it can be a little tricky to use two databases. Here is the config for using Redis with Resque (a task scheduler that is backed by Redis). This file is specific to resque and its located at config/initializers/resque.yml.

Deploy your app!

To deploy your app, you need to create some services in Bluemix for your app. We will do this with the Cloud Foundry command line.


cf create-service elephantsql turtle postgres-myapp
#postgres-myapp is the name of your service, you can name this whatever you want

cf create-service rediscloud 25mb redis-myapp
#redis-myapp is the name of your service, you can name this whatever you want

Prepare your app

Cloud Foundry requires a file called manifest.yml to help bind services to your app and defining memory limits, CPU limits, and the number of instances required. Belows is an example file I used. The name of the app is the unique identifier of your app that will be in your account. Hostname is the hostname of the app, it will be or if you are running in London it will be The command is pretty important, it says it will run the db:setup everytime the app is deployed, this should probably be changed to db:migrate instead though.

Push your app

So we are on the final step, time to push our app! If you are using Ruby 2.2.0, it’s not officially supported by Cloud Foundry, but there is a buildpack that is part of the Cloud Foundry community github that we can use. It tracks pretty close to the latest Ruby and Rails. For my app I used Ruby 2.2.0 and Rails 4.2.0:

cf push -b

One last little tip…

One last little tweak if you are familiar with Git it will make your life in Cloud Foundry land a little better. There is a file called .cfignore that goes in the root of your project, it basically acts like .gitgnore and prevents files being updated to Cloud Foundry. So for Ruby on Rails you probably would want your vendor folder here and etc. I have put one below that I use.

If you have any issues please reach out to us on StackOverflow! In the top righthand corner click “Ask Question”.

IBM Cloud Kubernetes Service - Core Dev Lead

More stories
May 7, 2019

We’ve Moved! The IBM Cloud Blog Has a New URL

In an effort better integrate the IBM Cloud Blog with the IBM Cloud web experience, we have migrated the blog to a new URL:

Continue reading

May 1, 2019

Two Tutorials: Plan, Create, and Update Deployment Environments with Terraform

Multiple environments are pretty common in a project when building a solution. They support the different phases of the development cycle and the slight differences between the environments, like capacity, networking, credentials, and log verbosity. These two tutorials will show you how to manage the environments with Terraform.

Continue reading

April 29, 2019

Transforming Customer Experiences with AI Services (Part 1)

This is an experience from a recent customer engagement on transcribing customer conversations using IBM Watson AI services.

Continue reading