Skip to content
This repository has been archived by the owner on Jun 22, 2023. It is now read-only.

dpetrick/prisma-heroku

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Prisma on Heroku example

This repository showcases how to deploy Prisma to Heroku.

Prerequisites

  1. A Heroku account.
  2. Heroku CLI installed.
  3. Docker installed.

Step-by-step example deployment

  1. Clone this repo

  2. Log the Heroku CLI into Heroku: heroku login

  3. Log into the Heroku docker registry:

    1. heroku container:login
    2. If you face issues, try docker login --username=_ --password=$(heroku auth:token) registry.heroku.com
  4. 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, like endless-sand-123456. We need this name in the next steps.

  5. 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:

    1. 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.
    2. It tags the image correctly for the Heroku registry and pushes it.
    3. This does NOT deploy the app.
  6. Optionally you can use Heroku Postgres for your database. If you would like to use Heroku to manage your Postgres database, first

    1. Create a new Postgres instance with: heroku addons:create heroku-postgresql:hobby-dev -a <your_app_name>
    2. Get the connection string for your new database: heroku config -a <your_app_name>
    3. 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>
  7. Now we need to configure the env vars:

    1. Either set them one by one via the CLI with heroku config:set <key>=<value> -a <your_app_name>...
    2. ...or navigate to the web interface and set them under settings
    3. Set the config vars:
      1. DB_HOST to your database host
      2. DB_PASSWORD to your database password
      3. DB_PORT to your database port
      4. DB_USER to your database user
      5. DB_NAME to your database name
      6. PRISMA_CONFIG_PATH to /app/config.yml
    4. Note: This example repo uses PostgreSQL. To change that, simply change the connector: postgres to connector: mysql in prerun_hook.sh.
  8. Finally, deploy the app with heroku container:release web -a <your_app_name>

  9. Open the app with heroku open -a <your_app_name> (this can take a bit, depending on the Dyno startup for example)

Additional notes

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.

About

Example repository to show how to deploy Prisma to Heroku.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published