The docker-compose.yml example contained in the docs works great for local development where people probably have multiple services run with docker:
version: '3'
services:
prisma:
image: prismagraphql/prisma:__LATEST_PRISMA_VERSION__
restart: always
ports:
- "4466:4466"
environment:
PRISMA_CONFIG: |
managementApiSecret: __YOUR_MANAGEMENT_API_SECRET__
port: __YOUR_PRISMA_SERVER_PORT__
databases:
default:
connector: __YOUR_DATABASE_CONNECTOR__
migrations: __ENABLE_DB_MIGRATIONS__
host: __YOUR_DATABASE_HOST__
port: __YOUR_DATABASE_PORT__
user: __YOUR_DATABASE_USER__
password: __YOUR_DATABASE_PASSWORD__
mongo:
image: mongo:__LATEST_PRISMA_VERSION__
restart: always
ports:
- "27017:27017"
volumes:
- mongo:/var/lib/mongo
However, in production there is no db running in a container. Indeed we're using a DBaaS to host our db. The db we're using is Mongo.
Thus we need to switch from docker-compose up
to docker run...
for the Prisma server.
The problem we're facing is how to set all the environment variables needed for the Prisma container to run.
I see two possible options:
- Pass down single variables to the container
- Pass down just the variable
PRISMA_CONFIG_PATH
that points to an yml config file, for example,prisma_config.yml
Option 1
In the docker-compose.yml there the PRISMA_CONFIG
variable is passed as multi-line string.
Searching on the Internet I found that the corresponding list of the single variables should be:
PORT: $PORT
SCHEMA_MANAGER_SECRET: $SCHEMA_MANAGER_SECRET
SCHEMA_MANAGER_ENDPOINT: $SCHEMA_MANAGER_ENDPOINT
SQL_CLIENT_HOST_CLIENT1: $SQL_CLIENT_HOST
SQL_CLIENT_HOST_READONLY_CLIENT1: $SQL_CLIENT_HOST
SQL_CLIENT_HOST: $SQL_CLIENT_HOST
SQL_CLIENT_PORT: $SQL_CLIENT_PORT
SQL_CLIENT_USER: $SQL_CLIENT_USER
SQL_CLIENT_PASSWORD: $SQL_CLIENT_PASSWORD
SQL_CLIENT_CONNECTION_LIMIT: 10
SQL_INTERNAL_HOST: $SQL_INTERNAL_HOST
SQL_INTERNAL_PORT: $SQL_INTERNAL_PORT
SQL_INTERNAL_USER: $SQL_INTERNAL_USER
SQL_INTERNAL_PASSWORD: $SQL_INTERNAL_PASSWORD
SQL_INTERNAL_DATABASE: $SQL_INTERNAL_DATABASE
CLUSTER_ADDRESS: $CLUSTER_ADDRESS
SQL_INTERNAL_CONNECTION_LIMIT: 10
CLUSTER_PUBLIC_KEY: $CLUSTER_PUBLIC_KEY
BUGSNAG_API_KEY: ""
ENABLE_METRICS: "0"
JAVA_OPTS: "-Xmx1G"
docker
All those var are set in an env file
docker run -p 4466:4466 --env-file prisma.env prismagraphql/prisma:1.25
They seem to work fine for SQL databases, but not for Mongo.
Either I set the wrong values or the variables names when using Mongo differ.
Option 2
Passing a single env var like PRISMA_CONFIG_PATH=prisma.config.yml
when running the container:
docker run -p 4466:4466 -e PRISMA_CONFIG_PATH=prisma.config.yml prismagraphql/prisma:1.25
I'm gettting the following error
Exception in thread "main" java.lang.RuntimeException: Unable to load Prisma config: java.io.FileNotFoundException: prisma_config.yml (No such file or directory)
I do not know what is the working directory for the prisma docker image. I guess that would solve it.
EDIT
I was able to make it work with Option#2
docker run \
-e PRISMA_CONFIG_PATH="/prisma.yml" \
-v "$(pwd)/env/prisma_config.yml":"/prisma.yml" \" \
-p 4466:4466 \
prismagraphql/prisma:1.25
prisma_config.yml
port: 4466
databases:
default:
connector: mongo
uri: __YOUR_MONGO_URI__
database: __YOUR_MONGO_DB__