Heroku Cloud Application Development
上QQ阅读APP看书,第一时间看更新

The Heroku feature set

Heroku is a fully featured PaaS that provides a complete stack of "true" PaaS features. The following are some of the core features available in Heroku:

  • Heroku runtime features:
    • It enables flexible process control; scalable web and worker (type) processes (called dynos) run from a Procfile.
    • It allows a new process type to be defined such as web or worker type.
    • Process isolation—anything you store on your web process will be isolated from all other web processes.
    • Heroku even lets you run processes during the maintenance mode while serving the application users static page(s).
    • It provides fully functional multiple language support.
  • Configuration:
    • Heroku does not use property files or hardcoded configuration variables to read system or application-specific global parameters; instead, it uses configuration variables or environment variables.
    • Heroku prefers convenience over configuration, hence the configuration architecture is intentionally simplistic to use.
  • Effective releases:
    • Whenever new code, add-ons, or a configuration is in place, Heroku creates a new release automatically.
    • Heroku provides a rich set of capabilities to manage app releases from creating a release and listing available releases to rolling back to previous releases.
  • Logging:
    • Heroku's Logplex facility provides you with an aggregated view of your application runtime behavior.
    • Heroku also has provisions to filter log records based on a certain source, process, or both.
  • Security:
    • Heroku provides the ability to set up an SSL endpoint for your application to enable secure communication to your deployed application.
    • Heroku also supports SSH keys to enable a secure transfer of developer code to/from the platform.
  • Real-time status:
    • Through a web URL, Heroku provides its users with an ability to verify the running status of the application(s) on a time-range basis. You can go back in time to check for failures and steps undertaken for their resolution.
  • Git-based deployment:
    • Heroku uses Git as the primary method to deploy apps. Git is a popular open source code revision control system that enables shared access to a managed source code environment.
    • While managing apps for the Heroku platform using Git, a developer can do the following:
      • Build and track the app
      • Create remote repositories of code
      • Deploy the application in multiple environments (development, staging)
      • Use other version control systems side by side and Git only for deployment
  • Polyglot platform:
    • Though Heroku started off being a Ruby-only web application platform, it has evolved over the years and started supporting many other popular programming languages including Java, Node.js, Scala, Clojure, Python, and the Play framework including the latest releases.
  • Buildpacks:
    • Heroku's support for a language is enabled by creating a buildpack for that language. A buildpack is a set of scripts required to identify the source code language and provide instructions to build it into executable code. For example, the Ruby (https://github.com/heroku/heroku-buildpack-ruby) buildpack is one of the most commonly used buildpacks on Heroku.
  • Add-ons:
    • Heroku offers a growing number of add-ons via its add-on provider program. Additional services, such as error tracking, reporting, e-mail services, hosted NoSQL databases, and full-text search among others are available instantly via a few clicks or commands on the Heroku CLI prompt.
    • There is a provision to add and remove add-ons using the Heroku API.
  • The Heroku command-line tool (CLI):
    • The Heroku command-line tool is an interface to the Heroku web API. The tools provide an easy to use command-line interface to do things such as creating/renaming apps, running one-off processes, taking backups, and configuring add-ons.
    • This tool is usually installed with the toolbelt program. It also has a plugin architecture that allows developers to extend the functionality of the command as needed.
    • It is purposely kept similar to UNIX shell commands to reduce the learning curve for system administrators or users of the Heroku API.
  • A fully featured Platform API
    • The Heroku Platform API is a standard list of functions that allow you to programmatically call the Heroku backend and perform various operations such as creating an app or deleting it. It helps the developer gain complete control of the app.
  • Managed, multitenant architecture:
    • Heroku's platform architecture provides a managed process execution environment and a high degree of isolation between running apps, all of which are transparent to the application client.

Let's play Heroku

Now that we have a basic understanding of what Heroku is and what it has to offer for developers planning to build and deploy cloud-based apps, let us take Heroku for a quick test drive. You are going to love it.

Getting ready for the ride – the prerequisites

There are a few prerequisites before you start using Heroku. You need to perform the following steps:

  1. Get a Heroku account (https://www.heroku.com).
  2. Install Heroku toolbelt client (https://toolbelt.heroku.com/).
  3. Set up SSH for your user account.

    An SSH key is an encrypted token that your machine and your Heroku account share to validate the authenticity of the user invoking a command on the Heroku platform.

In the next part, we will learn the actions required to set up a Heroku client on your local machine.

Signing up

To start using Heroku, you will need to sign up for a Heroku account. The following screenshot shows the sign up page to create a new Heroku account:

Signing up

Once you have entered an e-mail address, you need to validate your credentials by logging in to your e-mail account and verifying your account credentials for Heroku. Consider the following screenshot:

Signing up

Once you validate your account credentials, you will be redirected to the Heroku password-setting page, where you need to enter a valid password and confirm it, as shown in the following screenshot:

Signing up

After successful password confirmation, you will be redirected to the Heroku dashboard. Since you are a new user, it will not contain any deployed applications yet. Consider the following screenshot:

Signing up

Installing the Heroku toolbelt

The Heroku toolbelt is the client software required to work with the Heroku platform. It can be downloaded from https://toolbelt.heroku.com/ for Windows, Debian/Ubuntu, Mac OS X, and standalone platforms. For our example, we will use the Windows version as shown in the following screenshot:

Installing the Heroku toolbelt

Install the Heroku toolbelt by double-clicking on the downloaded executable and following the instructions.

The Heroku toolbelt contains the following components:

  • Heroku client: This is the command-line tool to help create and manage apps.
  • Foreman: This is a utility to give you the flexibility of running applications locally, especially sometimes when you want to troubleshoot.
  • Git: This is the revision control system and relevant utility program that helps you push your code to Heroku or download it from remote repositories. You can also download a client specific Git UI to your operating system if you want a user interface to issue Git commands.

Logging in and generating a new SSH key

After installing the toolbelt, you can issue Heroku commands from the Heroku client command prompt. These commands (or code) are sent to the Heroku server and executed on the Heroku platform. However, Heroku needs to verify that the commands and code being sent to it are from an authentic user. Hence, you need to create a public/private key pair to push the code to Heroku.

Follow these steps to create the key and upload it to your Heroku account:

  1. Generate the key on the local machine using the ssh-keygen tool (available at http://www.openssh.com/).
  2. Add this key to the related Heroku account using the keys:add Heroku command.
    • In order to add the key manually, consider the following figure:
      Logging in and generating a new SSH key
    • You can log in to the Heroku dashboard (https://dashboard.heroku.com/account) and add the key manually too, as shown in the following screenshot:
    Logging in and generating a new SSH key

In our example, we use the Heroku command-line interface to create the key and add it to the Heroku account. If you have previously uploaded an SSH key to Heroku, Heroku will assume that you will keep using it and will not prompt you to create a new one.