DEV Community

Cover image for Heroku Review Apps: setup & configuration
Maximilien Pressensé
Maximilien Pressensé

Posted on • Updated on

Heroku Review Apps: setup & configuration

At my job at VideoRunRun, we use Github and Heroku.

We have a pipeline with a staging and a prod app, and when I joined the team few months ago, I suggested to enable Review Apps as well.

What are Review Apps ?

I'll quote the official documentation:

Review apps run the code in any GitHub pull request in a
complete, disposable Heroku app. Review apps each have a
unique URL you can share, making them a great way to
propose, test, and merge changes to your code base.

Mainly, it allows us to shorten feedback loops, especially with our Product Owner, for UI/UX considerations, for testing purposes in a production environment, for PR reviews, etc.

Overall it's very convenient for many different use cases and we just love it.

It's a killer feature.

Setting it up

In order to use Review Apps up to their potential, they must be ready-to-use as soon as they are deployed.

If you need to manually set up heroku dependencies, define some env vars, or run a script every time you need to use a review, poor child you're lost.
Alt Text

As always, automation is key.

Luckily, Review Apps are very easy to set up and documentation is pretty straight-forward.


General config happens on Heroku UI:
Alt Text

There you can enable Review Apps, define env vars, choose a URL pattern, etc.


For advanced config, you'll need to add an app.json file to your app's root folder.

Here's a working example:

# app.json
{
  "environments": {
    "review": {
      "formation": {
        "worker": {
          "quantity": 1,
          "size": "free"
        }
      },
      "addons": [
        "heroku-postgresql:hobby-dev",
        "heroku-redis:hobby-dev"
      ],
      "scripts": {
        "postdeploy": "rails db:schema:load db:seed"
      }
  }
}
Enter fullscreen mode Exit fullscreen mode

Populate your database

If your seeding scripts aren't giving you all the data you need, you might lurk at your sexy staging database.

Here's what Heroku's team has to say about it:

Alt Text

Looks like you'll have to work on that seeding then.

You don't want to ? Tell me your reasons in comments please.

Anyway I've got you covered.

  1. One could simply use his staging database both for reviews and staging environment. (bad solution imho)

  2. One could hack his way around :

# app.json
{
  "environments": {
    "review": {
      "buildpacks": [
        {
          "url": "https://github.com/heroku/heroku-buildpack-cli"
        },
        ...
      ],
      "scripts": {
        "postdeploy": "heroku pg:copy {STAGING_APP_NAME}::DATABASE DATABASE --app $HEROKU_APP_NAME --confirm $HEROKU_APP_NAME  && sleep 1s && rails db:migrate"
      }
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

It consists on installing Heroku CLI directly on every app reviews. Then the postdeploy script launchs the appropriate heroku command and runs migrations. Beware you'll need to set HEROKU_API_KEY first. RTFM !

References:

Top comments (0)