Test driving Heroku

What fun is it to see a Ferrari and not drive it? So, let us put on our seatbelts and take Heroku for a spin. We assume that we are running the Heroku client on a Windows 7 machine. We assume that we have the Windows version of the Heroku toolbelt (download instructions in the prerequisites section). We have also created and added the SSH key to our Heroku account.

In this section, we will create a barebones Rails 3 app on the Heroku platform. You can use any other supported language, yet the steps won't change except for the language specific details (buildpack used). First and foremost, we need a few things up and running before we can create our first app on Heroku. These requirements are specific to the language we use here.

So, before we get started:

  1. Ensure you have certain prerequisites for the Rails 3 example. You need:
  2. Check if the Heroku client is installed and in the path open the command prompt and type:
    $ heroku
    

    You will get the Heroku usage help as follows:

    Test driving Heroku
  3. Log in using the e-mail address and password you used when creating your Heroku account:
    $ heroku login
    Enter your Heroku credentials.
    Email: xxxx@yyyy.com
    Password:
    Could not find an existing public key.
    Would you like to generate one? [Yn]
    Generating new SSH public key.
    Uploading ssh public key /users/xxxx/.ssh/id_rsa.pub
    

    Press enter at the prompt to upload your ssh key or create a new one.

  4. Write a simple Rails 3 application:
    $ rails new sampleapp_rails3
    $ cd sampleapp_rails3
    
  5. Edit your Gemfile (Gemfile is a file that contains the list of names of libraries/gem files your application needs to function correctly) and change gem 'sqlite3' to gem 'pg'.

    This change enables the application to use the newly introduced Heroku PostgreSQL database instead of SQLite.

  6. Re-install your dependencies (to generate new Gemfile.lock):
    $ bundle install
    
  7. Create your app in Git as shown in the following figure:
    Test driving Heroku
  8. To open a Heroku app, type the open command on the Heroku CLI:
    $ heroku open
    Opening pink-poppies-786… done
    
  9. Check the status of running Heroku processes, type the ps (process status) command as follows:
    $ heroku ps
    === web: `bundle exec rails server –p $PORT`web.1: up for 5s
    
  10. To support more concurrent users, you need to scale up your application. Increase the web dyno count from the Heroku command line. Use the ps:scale command to scale up the web processes to 2 as follows:
    $ heroku ps:scale web=2
    
  11. If you encounter any issues while running the Heroku app, you can use the logs command to get the details of most recent messages and use the information to troubleshoot pertinent issues as shown in the following figure:
    Test driving Heroku

That completes our test drive of Heroku. We created a Heroku account, added our SSH key to Heroku, and wrote a barebones Rails3 app and deployed it on Heroku. Finally, to troubleshoot, we used the logs command to see what was going on behind the scenes just in case something needed attention.