Blog by Railsware

How to set up the Heroku tools for deployment with multiple accounts

set up the Heroku tools for deployment with multiple accounts

This is a guide to setting up the Heroku toolset so that you can deploy an existing Heroku app, or create a new app on Heroku.

As you may not yet know, the vanilla Heroku toolset can only work with a single Heroku account. This is fine for personal use, or maybe for minor startups, but as soon as you have to simultaneously manage and deploy Heroku applications that belong to several accounts this becomes a huge inconvenience. Fortunately there is a way to make deployment simple again.

  1. Download the Heroku Toolbelt – this is the recommended way to install Heroku utilities.
  2. Install the heroku-accounts plugin – this will let you use multiple Heroku accounts in parallel.
    heroku plugins:install git://github.com/ddollar/heroku-accounts.git
    
  3. Now you can login to your account.
    heroku accounts:add [account_name] --auto
    

    Replace [account_name] with any name that’s meaningful to you, the name is only used locally.

    Be prepared to enter the credentials to the Heroku account.

    After logging in, heroku-accounts will automatically generate an SSH key (you cannot reuse the same key for two Heroku accounts), store it at ~/.ssh/identity.heroku.[account_name], upload the public key to Heroku and create a heroku.[account_name] host record in your ssh-config that would use the correct key. Neat, huh?

  4. Go to the project folder. Time to enable deployment.
    heroku git:remote --app [app_name]
    heroku accounts:set [account_name]
    

    Here [app_name] is the public name of the Heroku app (its URL would be [app_name].herokuapp.com).

    These commands add a heroku git remote that will be used for deployment. The entire configuration is stored in .git/config.

  5. Deploy away!
    git push heroku master
    

If the app has not yet been deployed, instead of the step 4 you’d have to create the app:

heroku accounts:set [account_name]
heroku apps:create [app_name]
heroku accounts:set [account_name]

The second heroku accounts:set is needed to point the git remote URL to the hostname configured in the step 3.

Random tips

Exit mobile version