Dynamic environments for Review apps

What is the feature?

A way to create Environments dynamically to target dynamic apps.

What problem does this solve for you?

We are using Review apps (something akin to Review Apps (New) | Heroku Dev Center).

We’d like to be able to use ForestAdmin against Review apps.

Who else would be using this feature?

Developers and product managers

Hello @leo_elevo,

Sorry the de delayed response.

Interesting, I understand the need as Review apps from Heroku generate custom URL.

I think you can still do something like that today by having a pool of staging environments and just change the variables manually in heroku and in the app to have the right endpoint URL.

Nethertheless, I will push this request to our team so it can be prioritize (or not) in the future.

Kind regards,
Morgan

Hello @leo_elevo,

I have some good news. After all, it seems totally feasible.

You will need to create a new environment for each Review App created, that can easily be done by the forest CLI. The only difficult part will be the set the proper Heroku variables.

Here is an example on how to do it (I couldn’t totally test it myself so any feedback are welcome).

  1. First thing first, change the URL pattern of your review apps make it predictable ! (this will help a lot when creating the environment)

  2. Set some new review apps environments variables

  • Configure a new variable to know when running a review app
    IS_REVIEW_APP=1
  • Configure your Forest project ID, it can be retrieve by using the forest CLI manually forest environments:create (a prompt will let you see your projects name and IDs) or by contacting our Customer Success team)
    PROJECT_ID=< Your Forest project ID >
  • Configure a Forest Admin application tokens that you can create from your Account settings
    APPLICATION_TOKEN=< Your generated token >
  1. Define a postdeploy script for review apps ( postinstall script could be an option)

app.json

"scripts": {
  "postdeploy": "script/setup-forest-env"
},

script/setup-forest-env

#!/bin/bash
#!/bin/zsh

# Only run this on review app
if [[ $IS_REVIEW_APP -ne 1 ]]; then
    exit 0
fi

# Install forest-cli
npm install -g forest-cli &> /dev/null

# Login to forest CLI using an application token
forest login -t $APPLICATION_TOKEN

# Install create a new environment for this review app
envs=$(forest environments:create -p $PROJECT_ID -n $HEROKU_APP_NAME -u https://$HEROKU_APP_NAME.herokuapp.com/ -format json)

FOREST_ENV_SECRET=$(node -e "JSON.parse($envs).secretKey")
FOREST_AUTH_SECRET=$(node -e "JSON.parse($envs).authSecret")

# Generate environment variables for forest 
export FOREST_ENV_SECRET
export FOREST_AUTH_SECRET

Let me know if it helps.

Kind regards,
Morgan