Automatically deploy to Heroku from GitHub

While starting on a new project the other day I decided to automate as much as possible. One of those tasks was deploying to Heroku when pushing the master branch to Github. It took me some time to figure certain parts out, even though the documentation is quite extensive; guess it being a beta feature didn't help.

  1. Start by going into the Settings > Webhooks & Services view and add the HerokuBeta Service.
  2. Create the app on Heroku via the command line heroku create myapp
  3. Fill in myapp as the Name in the HerokuBeta settings view and leave GitHub api url empty.
  4. Then for the Heroku token, you'll need your Heroku api token, which you get via heroku auth:token (eg. token123) and your email address you're using to login to Heroku (eg. Then convert the two into a base64 hash for the Authorization header by issuing this command on a Unix system echo "" | base64 (eg. base64-123).
    curl -X POST \
    -H "Accept: application/vnd.heroku+json; version=3" \
    -H "Authorization: Basic base64-123" \
    -H "Content-Type: application/json" \
    -d "{\"description\":\"direct token description (preferably meaningful)\"}"
  1. For the GitHub token follow the instructions and head to where you can click Create new token, then give it a name and leave the default settings before hitting Generate token. Then copy this token and fill it into the form.
  2. Save the configuration with Add service.
  3. I first thought the hook is already working, however it's only working with GitHub deployment events, which you can add by adding another service called GitHub Auto-Deployment.
  4. Repeat step 5 to acquire a new GitHub token and add it there, save and from now on your automatic Heroku deployment should be fully working.

Published: 2014-10-06

Tagged: Heroku GitHub