Jumpstart Lab Curriculum

Environment & Source Control

Heroku Configuation & Setup

Heroku is an application platform in the cloud which takes care of managing servers, deployment, and scaling, allowing you to focus your attention solely on your application code. We love deploying code to Heroku because the whole system was built to be easy. There are just a few steps to get going.

SSH Keys

Heroku authenticates using SSH keys.

On Windows

If you’ve used RailsInstaller then it generated and saved SSH keys for you; there’s nothing to do!

MacOS and Linux

If you’re on MacOS or Linux there’s a decent chance you’ve already created a set of SSH keys. Look in ~/.ssh/ and if you see files like id_rsa and id_rsa.pub then you’re good to go!

If those files aren’t present, generate new keys like this:

Terminal

$
ssh-keygen -t rsa

If you choose to use a passphrase, you’d better remember it. If you forget it then you can’t use your keys and you might not be able to access important resources like your code and server!

Once that setup completes you’re ready to continue.

Heroku Gem

Heroku has created a gem (https://github.com/heroku/heroku) that makes it ridiculously easy to interact with their service. If you use Heroku for all your projects, consider adding it to your global gemset (in ~/.rvm/gemsets/global.gems). Here’s how you use it:

Terminal

$
$
$
rvm gemset use globalgem install herokubundle install

Authenticate

Now you’re ready to submit your credentials to Heroku. Start by attempting to list your applications:

Terminal

$
heroku list

You’ll be prompted for your Heroku.com username and password. If you don’t have one, create one: http://www.heroku.com/signup

Once those credentials are entered, you should upload your SSH keys to allow password-less access in the future:

Terminal

$
heroku keys:add

Once that upload completes, you can try heroku list again and it should complete without asking for a username/password.

Heroku Basics

Here are some of the most common commands you’ll use on Heroku:

Terminal

$

$
heroku create [] # create a new app; if you omit the 'name' one will be provided for youheroku list            # list your apps

Within the root directory of a project you can use the following heroku commands:

Terminal

$
 
 
 
 
 
 
 
 
info                         # show app info, like web url and git repoopen                         # open the app in a web browserrename              # rename the apprake                # remotely execute a rake commandconsole                      # start an interactive console to the remote appconfig                       # display the app's config vars (environment)config:add key=val [...]     # add one or more config varsdb:pull []     # pull the app's database into a local databasedb:push []     # push a local database into the app's remote

For more information use heroku help or heroku help TOPIC (e.g. heroku help config). You can also check out the full list on Cheat (http://cheat.errtheblog.com/s/heroku/) or install the Cheat gem (gem install cheat) then display it with cheat heroku.

Heroku Deployment

Applications are deployed to Heroku through git. In order to push to Heroku, you’ll need to add it as a remote (repository):

Terminal

$
git remote add heroku git@heroku.com:appname.git

If you don’t know what your "appname" is, you can find it easily:

Terminal

$
heroku info --app appname

Now when you’re ready to deploy, simply push to your heroku remote’s master branch:

Terminal

$
git push heroku master

You can push any number of branches to Heroku:

Terminal

$
git push heroku my_topic_branch:my_topic_branch

This will create a new "remote" branch in your heroku repository. The my_topic_branch:my_topic_branch bit means "push my local branch named ‘the-branch-name -before-the-colon’ and name it ‘the-branch-name-after-the-colon’". Most often when you push remote branches those two names will be identical.

Importantly, only the master branch on your heroku remote triggers deployment. All other branches are essentially ignored by Heroku.

Feedback

Have Feedback?

Did you find an error? Something confusing? We'd love your help:

Thanks!