Six Strategies for Deploying to Heroku
Tags: deploy, coding, cloud
Published: 2019-06-24 15:43:40

---
title: Six Strategies for Deploying to Heroku
published: true
tags: deploy, coding, cloud
canonical_url: https://blog.heroku.com/six-strategies-deploy-to-heroku
cover_image: https://thepracticaldev.s3.amazonaws.com/i/x5310npk9i0ed498uzc1.png
---

There are many ways of deploying your applications to Heroku—so many, in fact, that we would like to offer some advice on which to choose. Each strategy provides different benefits based on your current deployment process, team size, and app. Choosing an optimal strategy can lead to faster deployments, increased automation, and improved developer productivity.

The question is: How do you know which method is the "best" method for your team? In this post, we'll present six of the most common ways to deploy apps to Heroku and how they fit into your deployment strategy. These strategies are not mutually exclusive, and you can combine several to create the best workflow for your team. Reading this post will help you understand the different options available and how they can be implemented effectively.

## Deploying to Production with Git

Our first method is not only the most common, but also the simplest: [pushing code from a Git repository to a Heroku app](https://devcenter.heroku.com/articles/git). You simply add your Heroku app as a [remote](http://git-scm.com/book/en/Git-Basics-Working-with-Remotes) to an existing Git repository, then use git push to send your code to Heroku. Heroku then automatically builds your application and creates a new [release](https://devcenter.heroku.com/articles/releases).

Because this method requires a developer with full access to manually push code to production, it's better suited for pre-production deployments or for projects with small, trusted teams.

### Pros:

- Simple to add to any Git-based workflow
- Supports [Git submodules](https://devcenter.heroku.com/articles/git-submodules)

### Cons:

- Requires access to both the Git repository and Heroku app

## GitHub Integration

If your repository is hosted on GitHub, you can use [GitHub integration](https://devcenter.heroku.com/articles/github-integration) to deploy changes directly to Heroku. After linking your repository to a Heroku app, changes that are pushed to your repository are automatically deployed to the app. You can configure automatic deployments for a specific branch, or manually trigger deployments from GitHub. If you use continuous integration (CI), you can even prevent deployments to Heroku until your tests pass.

GitHub integration is also useful for automating [pipelines](https://devcenter.heroku.com/articles/pipelines). For example, when a change is merged into the master branch, you might deploy to a staging environment for testing. Once the change has been validated, you can then [promote](https://devcenter.heroku.com/articles/pipelines#promoting) the app to production.

### Pros:

- Automatically deploys apps and keeps them up-to-date
- Integrates with [pipelines](https://devcenter.heroku.com/articles/pipelines) and [review apps](https://devcenter.heroku.com/articles/github-integration-review-apps) to create a continuous delivery workflow
- If you use a CI service (such as [Heroku CI](https://devcenter.heroku.com/articles/heroku-ci)) to build/test your changes, Heroku can prevent deployment when the result is fail

### Cons:

- Requires administrator access to the repository, so it’s only useful for repositories you own
- Does not support Git submodules

## Heroku Review Apps

When introducing a change, chances are you want to test it before deploying it straight to production. [Review Apps](https://devcenter.heroku.com/articles/github-integration-review-apps) let you deploy any GitHub pull request (PR) as an isolated, disposable instance. You can demo, test, and validate the PR without having to create a new app or overwrite your production app. Closing the PR destroys the review app, making it a seamless addition to your existing workflows.

### Pros:

- Can automatically create and update apps for each PR
- Supports Docker images
- Supports [Heroku Private Spaces](https://devcenter.heroku.com/articles/private-spaces) for testing changes in an isolated environment

### Cons:

- Requires both [pipelines](https://devcenter.heroku.com/articles/pipelines) and [GitHub integration](https://devcenter.heroku.com/articles/github-integration) to be enabled

## Deploying with Docker

Docker lets you bundle your apps into self-contained environments, ensuring that they behave exactly the same both in development and in production. This also gives you more control over the languages, frameworks, and libraries used to run your app. To [deploy a container to Heroku](https://devcenter.heroku.com/categories/deploying-with-docker), you can either push an image to the [Heroku container registry](https://devcenter.heroku.com/articles/container-registry-and-runtime), or [build the image automatically](https://devcenter.heroku.com/articles/build-docker-images-heroku-yml) by declaring it in your app's `heroku.yml` file.

### Pros:

- Automatically generate images, or push an existing image to the container registry
- Consistency between development and production
- Compatible with [Heroku Review Apps](https://devcenter.heroku.com/articles/github-integration-review-apps)

### Cons:

- If your app doesn’t already run in Docker, you’ll need to build an image
- Requires you to maintain your own [stack](https://devcenter.heroku.com/articles/stack)
- Does not support [pipeline promotions](https://devcenter.heroku.com/articles/pipelines-using-the-platform-api#performing-a-promotion)

## Using Hashicorp Terraform

Infrastructure-as-code tools like [Hashicorp Terraform](https://www.terraform.io/) can be helpful to manage complex infrastructure. Terraform can also be used to deploy a Heroku app. Despite it not being officially supported by Heroku, Terraform is being used by many Heroku users. [Using Terraform with Heroku,](https://devcenter.heroku.com/articles/using-terraform-with-heroku) you can define your Heroku apps with a declarative configuration language called HCL. Terraform automates the process of deploying and managing Heroku apps while also making it easy to coordinate Heroku with your existing infrastructure. Plus, Terraform v0.12 now allows you to store Remote State in a PostgreSQL database. This means you can now run Terraform on a Heroku dyno storing Terraform state in a Heroku Postgres database.

For an example, check out a [reference architecture](https://devcenter.heroku.com/articles/event-driven-microservices-with-apache-kafka) using Terraform and Kafka.

### Pros:

- Automates Heroku app deployments
- Allows you to deploy Heroku apps as code
- Simplifies the management of large, complex deployments
- Allows you to configure multiple apps, Private Spaces as well as resources from other cloud providers (e.g. AWS, DNSimple, and Cloudflare) to have a repeatable, testable, multi-provider architecture.

### Cons:

- Requires learning Terraform and writing configuration if you don’t use it already

## The 'Deploy to Heroku' Button

What if deploying your app was as easy as clicking a button? With the ['Deploy to Heroku' button](https://devcenter.heroku.com/articles/heroku-button), it is! It’s great for taking an app for a test run with default settings in a single click, or to help train new developers.

This button acts as a shortcut allowing you to deploy an app to Heroku from a web browser. This is great for apps that you provide to your users or customers, such as open source projects. You can parameterize each button with different settings such as passing custom environment variables to Heroku, using a specific Git branch or providing OAuth keys. The only requirements are that your source code is hosted in a GitHub repository and that you add a valid [`app.json`](https://dev.to/scottw/heroku-appjson-487i-temp-slug-5009239) file to the project's root directory. We’ve even heard of one company that adds a button to the README for each of their internal services. This forces them to keep the deploy process simple and aids new hires getting up to speed with how services are deployed.

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/heroku/node-js-sample)<figcaption>A 'Deploy to Heroku' button.</figcaption>

### Pros:

- Easy to add to a project's README file or web page
- Easy to use: simply click the button to deploy the app
- Provides a template with preconfigured default values, environment variables, and parameters

### Cons:

- Does not support Git submodules
- Apps deployed via button do not auto-update when new commits are added to the GitHub repo from which it was deployed
- Not a good workflow for apps that you need to keep up to date because buttons can only create new apps and the deployed app is not automatically connected to the GitHub repo from which it came

## Which Should I Choose?

The method you choose depends on your specific deployment process, your requirements, and your apps. For small teams who are just getting started, deploying with Git is likely to be your first deployment due to its simplicity. The Heroku Button is equally straightforward, letting you deploy entire apps with a single click. If you use continuous integration or release frequently, integrating with GitHub can simplify this process even more by doing automated deployments when you commit your code. This is a big improvement over deploying on an IaaS system because Heroku manages the entire process automatically.

As your requirements get more sophisticated, add the other strategies as needed. When your application is running in a production environment and you need quality control, you may want to add pipelines to get the advantages of review apps, automated testing, and staging environments. If you need a custom stack, then you can do so with Docker. As you add more complex infrastructure components, then add Terraform.

Advanced teams will use a combination of strategies: For example, you may choose to deploy a Docker image by creating a review app from a GitHub pull request, testing the review app, then manually deploying the final version using `git push`.

Ready to give one of these methods a try? Sign up for a [free Heroku account](https://www.heroku.com/free) and test them out.