Skip to content

Take off checklist: deploy Ruby on Rails application to Heroku

August 14, 2011

Have you ever seen an Airplane Pilot go through his or her checklist before take off? I bet that Pilot has gone through the same procedure thousands of times during training and during actual flight time. But low and behold, every time they go through the take off routine they methodically iterate through all preflight checks, in bigger planes they even double check the list with a co-pilot.

And interestingly, a large percentage of airplane accidents seem to be directly or indirectly correlated to not following proper pre-flight procedures.

Well I have learned that Ruby on Rails deployment is the same. Although tedious, going through a deployment checklist reduces errors and embarrassing production errors. It also helps instill discipline, because you may want to run into deployment issues before you move to production. In any case, this is a condensed checklist I put together for my own use. (The overall steps were based largely on the Ruby on Rails Tutorial written by Michael Hartl). I have separated the checklist into new and existing RoR applications.

New RoR application

You need to have installed the following packages previously for all of this to work smoothly:

  • Ruby 1.9.2
  • Rails 3.0.9
  • GitHub account (free)
  • Git 1.2.5 or later for Mac OS X Leopard or Lion
  • Sqlite3 3.3.x or later
  • RVM (not required but very handy)

You also need working versions of:

  • Text editor, such as Text Mate, Text Wrangler, TextEdit or whatever else you like to use.
  • Terminal application, such as the default terminal application that comes with your OS or a third party app like iTerm.

Create new RoR application directories

Navigate into the path where you like to add your RoR applications, for example $HOME/railsapps/.

$ rails new <appname>

Navigate into app path

$ cd $HOME/<appname>

Configure gem versions for application

Modify Gemfile (within application directory root) as needed with your favorite text editor.

$ bundle install

**For starters this probably isn’t necessary. But you may need to edit your Gemfile to add specific versions of application dependencies, the ‘bundle install’ command installs everything in one swoop.

Start rails server

$ rails server

Initialize Git repository

If you haven’t signed up for GitHub, go ahead and do so now.

From application directory root:

$ git init

Modify .gitignore file in the Rails app root directory

Add the following files, which are changed frequently:

.bundle
db/*.sqlite3*
log/*.log
*.log
/tmp/
doc/
*.swp
*~
.project
.DS_Store

*This helps ignore files that are commonly changed so that Git doesn’t commit unnecessary changes to the repo.

Add and Commit application code to GitHub

From the application root directory:

$ git add .
$ git status
$ touch README
$ git add README
$ git commit -m 'first commit' (or whatever other comment makes sense: “Initial commit”, “My First commit”)
$ git remote add origin git@github.com:/.git
$ git push -u origin master

* The ‘git remote add origin git@github.com:/.git’ command substitutes having to add the repo directly in your GitHub website repo settings.

Change README using the Branch, Edit, Commit and Merge steps.

It’s a good idea to change the README to add your own text instead of the derault RoR text and to do it by branching the file.

Branch

$ git checkout -b modify-README
$ git branch

Edit

$ git mv README README.markdown
$ mate README.markdown

Add appropriate text to README file, taking out the default RoR text.

Commit

$ git commit -a -m "Improved the README file"

*Use the “git add .” command first if you have added any new files.

Merge

$ git checkout master
$ git merge modify-README

*You can delete branch with: $ git branch -d modify-README

Push updated code to GitHub

From application directory root:

$ git push

Set up Heroku **Optional, if you already have a Heroku installation skip to the next step

Go to the Heroku site and sign up for a free account.

$ gem install heroku
$ heroku keys:add

*If you don’t have RSA public keys set up, do so now.

Deploy application on Heroku

From application root directory:

$ heroku create
$ git push heroku master
$ heroku rake db:migrate

Open and test with browser

$ heroku open

You should see the Welcome aboard web page.

Rename your Heroku site via command line:

$ heroku rename

Example: change Heroku designated name to your own, like freezing-night-530.heroku.com to myapp.heroku.com

**Sub-domain must be available.

—–

Existing application

Add changed code to existing GitHub repository. For example if you modify a file on your development environment and want to push the code to Heroku to test.

$ git add .
$ git commit -a -m "[Comment]" //*Add any comment you want, such as “Second commit” or “Milestone 3 commit”
$ git push

Now deploy to Heroku:

$ heroku create
$ git push heroku master
$ heroku rake db:migrate //*Migrate database changes to Heroku.

About these ads
2 Comments
  1. Hey there! I know this is kinda off topic however I’d figured I’d
    ask. Would you be interested in exchanging links or maybe guest writing a
    blog post or vice-versa? My blog goes over a lot of the same
    topics as yours and I believe we could greatly benefit from each other.
    If you might be interested feel free to send me an email.

    I look forward to hearing from you! Great blog by the way!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 79 other followers

%d bloggers like this: