"Error: Invalid Prisma endpoint provided" when using docker-compose to deploy a server alongside prisma server
Describe the bug
When using docker-compose to deploy a server (e.g. Apollo Server or graphql yoga) talking to prisma server, it is not possible to reference the prisma server container by its name because of string validation in prisma-binding module :
/app/node_modules/prisma-binding/dist/Prisma.js:44
throw new Error("Invalid Prisma endpoint provided: " + endpoint);
To Reproduce
Consider a docker-compose file:
version: "3"
services:
prisma:
image: prismagraphql/prisma:1.19
restart: always
ports:
- 4466:4466
environment:
PRISMA_CONFIG: |
port: 4466
managementApiSecret: xxxxx
databases:
default:
connector: postgres
host: postgres
port: 5432
user: postgres
password: postgres
migrations: true
postgres:
image: postgres:10.5
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- postgres:/var/lib/postgresql/data
server:
build:
dockerfile: Dockerfile.dev
context: .
volumes:
- /app/node_modules
- ./:/app
environment:
- PRISMA_MANAGEMENT_API_SECRET=xxxxx
- APP_SECRET=xxxxxx
- PRISMA_URL=prisma
- PRISMA_SECRET=xxxxx
volumes:
postgres:
the graphql server running in the server container will try initialise the prisma binding like so :
module.exports = {
prismaBinding: new Prisma({
typeDefs,
endpoint: process.env.PRISMA_URL,
secret: process.env.PRISMA_SECRET
})
};
When running docker-compose up this will throw an error when the server image is built and starts running : Error: Invalid Prisma endpoint provided: prisma
This is because it expects the prisma endpoint to start with http://
When deploying to a kubernetes cluster I am experiencing the same issue because the ClusterIP service name for my prisma server pod doesn't start with "http://". Hence the server pod can't talk to prisma server inside the cluster because it crashes with the same error.
Expected behavior I should be able to take advantage of docker-compose networking tooling with prisma (a container can reference another container's IP address using its name). Referencing the prisma server from another service by its name (e.g. "prisma") should work. Idem in k8s when referencing prisma by its service name from another pod.
Hey @n2ctech 👋,
Have you tried using localhost:4466? Also, why was this issue moved here in the first place?
cc @divyenduz
@maticzav : Because AFAIK, the issue is in prisma-binding string validation.
@divyenduz I suggest we change the error to a warning. Do you think this could brake anything?
@maticzav : Most likely no, but if someone relies on this logic for their URL validation, then their application might break. In any case, we should clearly mention this in release notes should we decide to do it.
Thanks to inlightmedia for his answer on prisma.io
In the end I found that you have to add http:// to the beginning of the service name like so: “http://prisma:4466”
This worked for me