Deploy Rails app from Github to Heroku

Recently I found deploying your Rails code which already on Github to Heroku is very useful. You can use this to show your work to your customers, friends …. Let’s start

= GITHUB

== Generate a keypair

cd ~/.ssh
ssh-keygen -t rsa -C “your@mail.com”
(enter at first prompt)

Then go to your github account then add that key in id_rsa.pub. Should use a text editor then ctrl-A to select all.

== Test if key works

ssh git@github.com

If you see “successfully authenticated”, everything’s on rails.

== Create a new repo

Click on the link “New Repository”, follow the on-screen instruction.
Go to your Rails root directory:
git init
git add *
git commit -m “Initial commit.”
git remote add origin git@github.com:/.git
git push origin master

Okay, your code is now on Github.

= HEROKU

Make sure you have install heroku gem on your machine (gem install heroku)
Go to your Rails root directory:

== Create app

heroku create
(this will create an address for you app at http://.heroku.com
your git address will be git@heroku.com:.git)

== Prepare for your gems

Because you can’t install gems yourself, you need to create a list of gems you need so that heroku can install them for you.
In your Rails app root directory, create a file named “.gems”. Each line of this gem will be in this format:

hpricot [–version ‘>= 0.2’] [–source code.whytheluckystiff.net]

== Deploy app

git push heroku master

This will install all gems listed in .gems, then deploy your code on Github to heroku server, and your app will run in production environment.

== Re-deploy app

When you make changes to your code, you have to push your new code to github first, then run
git push heroku master

your app will be deployed again on heroku

== Create database

heroku rake db:migrate
heroku rake db:seed

= USERFUL HEROKU COMMANDS

heroku rename
heroku logs

= REFERENCES

http://gitref.org/
http://docs.heroku.com

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 )

Google+ photo

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

Connecting to %s