Skip to content

Instantly share code, notes, and snippets.

@i8ramin
Last active November 23, 2018 14:08
Show Gist options
  • Save i8ramin/f4202e7c234c059f9b6f75e20d3bf09c to your computer and use it in GitHub Desktop.
Save i8ramin/f4202e7c234c059f9b6f75e20d3bf09c to your computer and use it in GitHub Desktop.
Prisma on Heroku via Docker
package.json
node_modules
package-lock.json
VERSION=1.21.0
HEROKU_APP=your-prisma-app

Prisma on Heroku

First time setup

  • Install Heroku CLI (https://devcenter.heroku.com/articles/heroku-cli)

  • Login to Heroku CLI

  • Login to Heroku's container registry:

    • heroku container:login
    • If you face issues, try docker login --username=_ --password=$(heroku auth:token) registry.heroku.com
  • Create a new Heroku app and add Postgres DB add-on

  • Define your desired Prisma image VERSION and set the HEROKU_APP varirables in a local .env

  • Insert the ENV variables required in prerun_hook.sh in the config for your Heroku app. Define the following:

    • PRISMA_MANAGEMENT_API_SECRET
    • DB_HOST
    • DB_NAME
    • DB_USER
    • DB_PASSWORD
    • PRISMA_CONFIG_PATH (set this to /app/config.yml)
    • JAVA_OPTS (set this to -Xmx358m)

    NOTE: The DB_* fields can be derived from the DATABASE_URL ENV var set in Heroku when you add the Postgres DB. ie, postgres://<DB_USER>:<DB_PASSWORD>@<DB_HOST>:5432/<DB_NAME>

    Also, no need to set the PORT, as it is dynamically defined by Heroku during deployment

  • Run yarn deploy

How to deploy

  • Have the Heroku CLI installed
  • Be logged in to an account that has access to the projects
  • Run yarn deploy
  • Profit

Changing version of Prisma

Change the version VERSION ENV var in .env and run yarn deploy again

#! /bin/bash
set -e
VERSION=$(grep VERSION .env | cut -d '=' -f2)
APP=$(grep HEROKU_APP .env | cut -d '=' -f2)
docker build --build-arg tag=${VERSION} -t registry.heroku.com/${APP}/web .
docker push registry.heroku.com/${APP}/web
echo "Image pushed successfully. Release with heroku container:release web -a ${APP}"
ARG tag
FROM prismagraphql/prisma:$tag
COPY ./prerun_hook.sh /app/prerun_hook.sh
RUN chmod a+x /app/start.sh
RUN chmod a+x /app/prerun_hook.sh
CMD bash /app/start.sh
{
"name": "prisma-server",
"license": "UNLICENSED",
"private": true,
"scripts": {
"deploy": "yarn stage && yarn release",
"stage": "sh ./build.sh",
"release": "sh ./release.sh"
}
}
#! /bin/bash
set -e
printf "
port: ${PORT}
managementApiSecret: ${PRISMA_MANAGEMENT_API_SECRET}
databases:
default:
connector: postgres
host: ${DB_HOST}
port: 5432
database: ${DB_NAME}
user: ${DB_USER}
password: ${DB_PASSWORD}
migrations: true
" >> ${PRISMA_CONFIG_PATH}
#! /bin/bash
set -e
VERSION=$(grep VERSION .env | cut -d '=' -f2)
APP=$(grep HEROKU_APP .env | cut -d '=' -f2)
heroku container:release web -a ${APP}
echo "Image released successfully to ${APP}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment