Book Image

Heroku Cookbook

By : Mike Coutermarsh
Book Image

Heroku Cookbook

By: Mike Coutermarsh

Overview of this book

Heroku is a Platform as a Service that enables developers to rapidly deploy and scale their web applications. Heroku is designed for developer happiness, freeing developers from doing system administrative tasks such as configuring servers and setting up load balancers. Developers are able to focus on what they do best, building web applications, while leaving the details of deployment and scaling to the experts at Heroku. This practical guide is packed with step-by-step solutions to problems faced by every production-level web application hosted on Heroku. You'll quickly get comfortable with managing your Heroku applications from the command line and then learn everything you need to know to deploy and administer production-level web applications.
Table of Contents (17 chapters)
Heroku Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Installing the Heroku Toolbelt


Heroku applications are created and administered from the command line. To get started with Heroku, we need to install the Heroku Toolbelt. It contains everything we need to create and deploy new applications.

The toolbelt is an installer for three command-line tools:

  • Heroku Command Line Interface (CLI): This is an interface to the Heroku Platform API

  • Git: This is used for version control and to deploy our applications

  • Foreman: This is a tool to run Procfile-based applications

In this recipe, we will install the Heroku Toolbelt, making sure our machine is set up to use the Heroku CLI. We'll also be briefly introduced to the Heroku CLI. We'll learn about Git and Foreman later in the chapter.

Note

If you already have the Heroku Toolbelt, it might be beneficial to go through the following steps again to ensure that the latest version is installed.

Getting ready

First, we need to create a Heroku account with the following steps:

  1. Let's go to www.heroku.com and create an account if we do not already have one.

    Note

    Remember to use a strong and unique password for Heroku. This account will be able to access our source code and data, so treat it like any other sensitive set of credentials.

  2. Next, let's install the Heroku Toolbelt. Specific download and installation instructions are available at https://toolbelt.heroku.com/ for Mac, Windows, and Linux.

    Note

    Throughout this book, we will be using a $ sign to indicate that a command should be run in a terminal. The $ sign is not part of the command.

  3. Once the Heroku Toolbelt is installed, we can verify that everything is working by opening up a terminal and running the following command:

    $ heroku --version
    heroku-toolbelt/3.11.1 (x86_64-darwin10.8.0) ruby/1.9.3
    

    We should see the version of the Heroku Toolbelt we are using printed to the console.

How to do it...

Now that we have the Heroku Toolbelt installed, let's log in to our account via the CLI and authorize our computer by uploading our public key using the following steps:

  1. Let's log in by opening up a terminal and running the following command:

    $ heroku login
    Username: [email protected]
    Password (typing will be hidden):
    Could not find an existing public key.Would you like to generate one? [Yn]Generating new SSH public key.Uploading ssh public key /Users/mc/.ssh/id_rsa.pub
    

    If we do not have an existing public key, the Heroku CLI will provide us with instructions on how to create one here. This key will be uploaded to Heroku's servers and used for authentication whenever we push new code to our applications.

    Note

    We'll need to repeat this step for any other computers we use Heroku from.

  2. We can ensure that we are authenticated with the auth:whoami command. If logged in successfully, it will print our e-mail address:

    $ heroku auth:whoami
    [email protected]
    
  3. Finally, we should go to the Heroku dashboard and verify our account by adding a credit card. Having a verified account will allow us to scale our applications and install add-ons (https://dashboard.heroku.com/account).

How it works…

The Heroku Toolbelt installs all the necessary tools to create and administer our Heroku applications. It's essential for us to become comfortable with Heroku's command-line tools. Even though many tasks can be completed on Heroku's website, not everything is available through the dashboard. For full control over our applications, we have to use the CLI.

Authentication

Ever wondered how Heroku keeps us logged in to the CLI? During the login process, Heroku stores an API key for our account in our .netrc file. The .netrc file is a dotfile that lives in our home directory. It's a common file that applications use to store credentials to log in to remote hosts. The API key stored in this file is used for subsequent logins and keeps us logged in to our Heroku account. If we open our .netrc file, we'll see an entry for api.heroku.com. If we ever run the auth:logout command, it deletes the entry from our .netrc file, thus logging us out.

Note

We do not need to worry about updating Heroku Toolbelt; it will automatically check for updates for us.

See also