> For the complete documentation index, see [llms.txt](https://openup.gitbook.io/wazi-ng-technical/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://openup.gitbook.io/wazi-ng-technical/testing/heroku-review-apps.md).

# Heroku Review Apps

### Creating a review app

![](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M3zapxOsLjq_qKRcmH8%2Fuploads%2FdSRsufsF0Ka97x5SYIq5%2FScreenshot_2022-05-29_16-55-42.png?alt=media\&token=f1953410-48a8-442b-affb-fd387f5dc220)

1. Login to the heroku dashboard
2. Go to the wazimap pipeline
3. Click "Create review app" for your pull request

Find the URL to the deployed review app in the pull request or by clicking "View app" in heroku.

Migrations and demodata are only loaded when the app is created. If you need to recreate the database, destroy the app and recreate it.

### Connecting a netlify frontend deploy preview to backend review app

* Copy link for frontend review app ex: [deploy-preview-542--wazimap-staging.netlify.app](https://deploy-preview-542--wazimap-staging.netlify.app/)
* Add it to the configuration in profiles for the backend review app and save\
  ![](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M3zapxOsLjq_qKRcmH8%2Fuploads%2Fbvcc28DKG9Cwo4IraY1J%2FScreenshot%202022-05-18%20at%205.42.54%20PM.png?alt=media\&token=c3326a3d-d00e-47c2-a38f-f01529ada60e)
* Go to Ui deploy preview add ?dev-tools=true to enable dev tools and add `deploy-preview-542--wazimap-staging.netlify.app` to Hostname and backend review app url to Api url `https://wazireview.herokuapp.com` and enter\
  ![](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M3zapxOsLjq_qKRcmH8%2Fuploads%2Fckuru8XfgC3cS3JDHiYn%2FScreenshot%202022-05-18%20at%205.44.34%20PM.png?alt=media\&token=7023613d-a507-458e-a115-47ddd7a198e3)

## Creating staging apps in heroku

This is probably not helpful any more now that real review apps work again, but we're leaving this here for now in case it's needed.

We were creating "review apps" in the staging "stage" of the wazimap pipeline in heroku while heroku review apps were not working due to the exfiltration of github oauth keys.

### Create a new app

We name apps according to the pull request number, e.g. wazimap-pr-1234 for PR #1234

#### Steps for creating an app via CL

* `heroku login`

In the project directory (to update your project git remotes):

* `heroku apps:create wazimap-pr-1234 --remote heroku-pr-1234`
* `heroku pipelines:add wazimap --app wazimap-pr-1234 --stage staging`

#### Steps for creating an app via GUI

* Login into Heroku Web
* Go to wazimap pipeline
* After opening wazimap pipeline there is an option to add new staging app\
  ![](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M3zapxOsLjq_qKRcmH8%2Fuploads%2FmrpHgmt3fv2Z7c4Ky8z8%2FScreenshot%202022-05-18%20at%2011.36.06%20AM.png?alt=media\&token=8438b191-a4da-4f81-8cbf-4f7ab9483544)
* Open the newly created app and go to deploy\
  ![](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M3zapxOsLjq_qKRcmH8%2Fuploads%2FrXtDl7sZy4hst8vSwhtA%2FScreenshot%202022-05-18%20at%2011.39.26%20AM.png?alt=media\&token=4deba337-43bf-4e44-8843-6e07def8ae1e)
* Copy command to add remote for existing repo and paste it to your command line inside wazi backend repo to add this app as heroku remote\
  ![](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M3zapxOsLjq_qKRcmH8%2Fuploads%2FRgYBVBaAJHHFpajwBx56%2FScreenshot%202022-05-18%20at%2011.41.56%20AM.png?alt=media\&token=340add80-0c8c-4e01-88e8-d85572c88276)

### Steps for setting up the stack

* `heroku stack:set container --app wazimap-pr-1234`
* Adding Addons:
  * `heroku addons:add heroku-postgresql:hobby-dev --app wazimap-pr-1234`
  * `heroku addons:add heroku-redis:hobby-dev --app wazimap-pr-1234`
* Adding Config vars:\
  `heroku config:set DJANGO_SECRET_KEY=3423424 AWS_ACCESS_KEY_ID=xxx AWS_SECRET_ACCESS_KEY=xxx AWS_STORAGE_BUCKET_NAME=xxx AWS_S3_REGION_NAME=xxx --app wazimap-pr-1234`

### Deploying branch

* git add and commit everything you want to deploy
* `git push heroku-pr-1234 BranchName:master`

### Post-release step

Start Worker dynos

Via CLI:

`heroku ps:scale worker=1 --app` `wazimap-pr-1234`

Via GUI:

* Go to overview on app in heroku dev center and there will option to see dyno formation\
  click on configure dyno link on right hand side\
  ![](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M3zapxOsLjq_qKRcmH8%2Fuploads%2F83KrfmQvxmrfsEEPX5At%2FScreenshot%202022-05-24%20at%201.14.55%20PM.png?alt=media\&token=32a1a422-976f-414c-83b0-2ffe4f827a80)

* Switch on the dyno to run Qcluster (click on edit and turn the toggle on)\
  ![](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M3zapxOsLjq_qKRcmH8%2Fuploads%2FZtCLKm6SdnkGDz1G0MeK%2FScreenshot%202022-05-24%20at%201.17.21%20PM.png?alt=media\&token=e2c2adfa-11e0-4e33-95c5-1f957f625777)

* `heroku run python3 manage.py migrate --app` wazimap-`pr-1234`

* `heroku run python3 manage.py loaddata demodata.json --app` wazimap-`pr-1234`

* `heroku run python3 manage.py createsuperuser --app` wazimap-`pr-1234` if you want to create new supruser

### Usefull commands

* Check configs for review app via cli\
  `heroku config --app` wazimap-`pr-1234`
* Define region while creating app\
  `heroku apps:create` wazimap-`pr-1234 --remote staging --region eu`
* Checking logs
  * worker logs : `heroku logs --dyno=worker --app` wazimap-`pr-1234 --tail`
  * web logs: `heroku logs --dyno=web --app` wazimap-`pr-1234 --tail`

### Connecting backend review app to deploy preview app

* Copy link for frontend review app ex: [deploy-preview-542--wazimap-staging.netlify.app](https://deploy-preview-542--wazimap-staging.netlify.app/)
* Add it to the configuration in profiles for the backend review app and save\
  ![](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M3zapxOsLjq_qKRcmH8%2Fuploads%2Fbvcc28DKG9Cwo4IraY1J%2FScreenshot%202022-05-18%20at%205.42.54%20PM.png?alt=media\&token=c3326a3d-d00e-47c2-a38f-f01529ada60e)
* Go to Ui deploy preview add ?dev-tools=true to enable dev tools and add `deploy-preview-542--wazimap-staging.netlify.app` to Hostname and backend review app url to Api url `https://wazireview.herokuapp.com` and enter\
  ![](https://405987915-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-M3zapxOsLjq_qKRcmH8%2Fuploads%2Fckuru8XfgC3cS3JDHiYn%2FScreenshot%202022-05-18%20at%205.44.34%20PM.png?alt=media\&token=7023613d-a507-458e-a115-47ddd7a198e3)<br>

### Destroy review apps when branches are merged

`heroku apps:destroy wazimap-pr-1234`
