skip to content
Pandurang Waghulde

Want to deploy your Ruby on Rails application on openshift? then follow these steps,

  1. Go to http://www.openshift.com and create an account

  2. Click MY APPS > Create an application https://openshift.redhat.com/app/console/application_types and select Ruby on rails as the type of the application.

  3. Put a name for your application. If this is your first time… make sure that you have a unique namespace. You can change it here: https://openshift.redhat.com/app/account

  4. Clone your git repo into your local machine via the ssh codes provided…

Example:

Terminal window
git clone ssh://cb46d233933f4e79eddc@railsapp-appsource.rhcloud.com/~/git/railsapp.git/
cd railsapp/
  1. or I recommend to use rhc client tool to create app on openshift
Terminal window
sudo gem install rhc (first install gem rhc)
rhc app create -a railsapp -t ruby-1.9
  1. Then to add cartridge to your rails application use
Terminal window
rhc cartridge add -a railsapp -c mysql-5.1
  1. Then pull your code from github,
Terminal window
git remote add upstream -m master git://github.com/openshift/rails-example.git
git pull -s recursive -X theirs upstream master
  1. Then you will need to change, your database.yml put this config for production only…
production:
adapter: mysql2
encoding: utf8
database: <%=ENV['OPENSHIFT_APP_NAME']%>
pool: 5
host: <%=ENV['OPENSHIFT_MYSQL_DB_HOST']%>
port: <%=ENV['OPENSHIFT_MYSQL_DB_PORT']%>
username: <%=ENV['OPENSHIFT_MYSQL_DB_USERNAME']%>
password: <%=ENV['OPENSHIFT_MYSQL_DB_PASSWORD']%>
socket: <%=ENV['OPENSHIFT_MYSQL_DB_SOCKET']%>

Leave the development and test ENV under mysql adapter.

  1. Now in your application directory look for .openshift folder

    there you will find .openshift/action_hooks/deploy file

Terminal window
pushd ${OPENSHIFT_REPO_DIR} > /dev/null
bundle exec rake db:migrate RAILS_ENV="production"
popd > /dev/null

commands written between pushd and popd lines will get executed automatically after code is updated on openshift,so if you have any other commands like starting resque, or copying some files after deploy then you can add it here.

  1. Now that we have made our changes… push it!
Terminal window
git add
git commit -m “configures database.yml,gemfile and adds .openshift files”
git push
  1. That’s all, now check url for your rails app.

  2. https://www.openshift.com/page/openshift-environment-variables here you will find all enviroment variables details that are available in openshift.

  3. If you want to associate your own domain name eg. (www.yourdomain.com) with your openshift rails app url then you will need to create url alias as shown below

Terminal window
rhc alias add railsapp www.yourdomain.com

then change cname records in your DNS provider account. cname openshift dns alias

  1. If your application require some persistent directory for your data then you can use directory (app-root/data/) you can access this directory in your application using enviroment variable OPENSHIFT_DATA_DIR

  2. If you want to remove a cartridge

Terminal window
Format:
$rhc cartridge remove shortname –app appname –confirm
Sample:
$rhc cartridge remove mysql2 –app railsapp –confirm