This repository showcases how to deploy Prisma to Heroku.
- A Heroku account.
- Heroku CLI installed.
- Docker installed.
-
Clone this repo
-
Log the Heroku CLI into Heroku:
heroku login
-
Log into the Heroku docker registry:
heroku container:login
- If you face issues, try
docker login --username=_ --password=$(heroku auth:token) registry.heroku.com
-
Create a Heroku app via the web interface or via CLI:
heroku create
. This will return an app name if you didn't specify one, likeendless-sand-123456
. We need this name in the next steps. -
Execute the build script with the app name and desired Prisma version as args, for example:
./build.sh 1.8.4 endless-sand-123456
. This does 2 things:- It takes the Prisma docker image as a base and adds a prerun hook that renders the Prisma config required to run the app, and adds a CMD docker directive to the image that Heroku requires all images to have.
- It tags the image correctly for the Heroku registry and pushes it.
- This does NOT deploy the app.
-
Optionally you can use Heroku Postgres for your database. If you would like to use Heroku to manage your Postgres database, first
- Create a new Postgres instance with:
heroku addons:create heroku-postgresql:hobby-dev -a <your_app_name>
- Get the connection string for your new database:
heroku config -a <your_app_name>
- Then you can extract the details for the next step from that string in the form
postgres://<DB_USER>:<DB_PASSWORD>@<DB_HOST>/<DB_NAME>
- Create a new Postgres instance with:
-
Now we need to configure the env vars:
- Either set them one by one via the CLI with
heroku config:set <key>=<value> -a <your_app_name>
... - ...or navigate to the web interface and set them under
settings
- Set the config vars:
DB_HOST
to your database hostDB_PASSWORD
to your database passwordDB_PORT
to your database portDB_USER
to your database userDB_HOST
to your database namePRISMA_CONFIG_PATH
to/app/config.yml
- Note: This example repo uses PostgreSQL. To change that, simply change the
connector: postgres
toconnector: mysql
inprerun_hook.sh
.
- Either set them one by one via the CLI with
-
Finally, deploy the app with
heroku container:release web -a <your_app_name>
-
Open the app with
heroku open -a <your_app_name>
(this can take a bit, depending on the Dyno startup for example)
If you want to change the Prisma config, for example to add authentication (recommended), look at the prerun_hook.sh
file and edit the config there. It is recommended to follow the existing pattern there and use env var interpolation with Heroku config vars to not accidentially commit secrets.