Deploying Mattermost To Heroku

At Mozilla, we've been using Mattermost to facilitate communication between employees and contributors for the better part of this year. Mattermost is an open source (more like open core - but the team edition is still awesome), self hosted Slack alternative. It's been really great so far, and Mattermost has really improved its stability and features over this time period.

I'd like to take the time today to share with you how I've deployed a reliable Mattermost instance to Heroku (200+ users and going strong!), so your teams can benefit from Mattermost just like we have!


If you have a Heroku account, click the button below and you'll have a custom Mattermost instance in less than one minute


You're welcome. Read the docs to customize further!

How it works

The Heroku app is configured to use two cusom buildpacks:

  1. cadecairos/nginx-buildpack - a fork of beanieboi/nginx-buildpack that installs NGINX and configures it as a reverse proxy to Mattermost. The fork modifies the NGINX config to expect a connection on a port and not on a socket. The NGINX proxy will automatically 301 http connections to https. Hooray!

  2. mozilla/mattermost-heroku - a fork of tommyvn/mattermost-heroku which improves on the build process and adds in a large variety of configuration options over the original.

Both of these forks are interested in having their changes upstreamed.

Getting Mattermost to run on Heroku

The mechanics of the buildpack are what allows Mattermost to run on Heroku. Mattermost uses file based configuration, which is a big issue when you try to run it on Heroku - there's no way to tell Mattermost how it's configured using only environment variables. Enter the inline buildpack: A buildpack that you deploy to Heroku, which uses itself as a buildpack.

This affords one major capability: We can provide a template config, and render in environment variables before we run the Mattermost executable, pointing it to the fresh configuration file. This means that no matter what, it's always got the latest settings from your environment.

Unfortunately, that means you can't use the Mattermost admin console to change environment variables, because they'll be written to disk, and if the dyno reboots (which it will every 24 hours) - you lose that config setting due to the ephemeral nature of the dyno's filesystem.

Another awesome feature of the buildpack is the ability to run enterprise Mattermost on Heroku. Just set the MATTERMOST_TYPE="enterprise" on your environment and build/rebuild the app. You can then install your license for Mattermost e10/e20 as per the instructions here

One more thing

The easiest way to deploy new versions of Mattermost using the above setup is to go to the "Deploy" tab of your Heroku app and link the app to mozilla/mattermost-heroku. You'll then be able to deploy specific branches from that repo. I've set up branches that point to the same commits as their tag counterparts (minus the 'v').

Another strategy is to use the build API:

 curl -n -X POST$APP_ID_OR_NAME/builds \
  -d '{
  "buildpacks": [
      "url": ""
      "url": ""
  "source_blob": {
    "url": "",
    "version": "v1.0.3"
}' \
  -H "Content-Type: application/json" \
  -H "Accept: application/vnd.heroku+json; version=3"

Next up

I'll be following up this post sometime in the future with details on how to get your Mattermost instance a kick-ass Chat bot that can do whatever your mind can make it do!