P
Prisma•this hour
aa55h

How to correctly deploy prisma into production?

So Im a bit clueless here, am I supposed to run prisma generate in my Dockerfile? Im using prisma with nextjs dockerfile and doing:
ARG DATABASE_URL
ENV DATABASE_URL=${DATABASE_URL}
RUN yarn prisma generate
ARG DATABASE_URL
ENV DATABASE_URL=${DATABASE_URL}
RUN yarn prisma generate
with:
app:
build:
context: .
args:
- DATABASE_URL=postgresql://${PG_USER}:${PG_PASS}@db:5432/riskrealm
container_name: RiskRealm
environment:
- DATABASE_URL=postgresql://${PG_USER}:${PG_PASS}@db:5432/riskrealm
env_file:
- .env.production
depends_on:
- db
ports:
- "3000:3000"
app:
build:
context: .
args:
- DATABASE_URL=postgresql://${PG_USER}:${PG_PASS}@db:5432/riskrealm
container_name: RiskRealm
environment:
- DATABASE_URL=postgresql://${PG_USER}:${PG_PASS}@db:5432/riskrealm
env_file:
- .env.production
depends_on:
- db
ports:
- "3000:3000"
but im getting DATABASE_URL was not found, where could be the issue? or am i doing the whole thing wrong?
3 Replies
Nurul
Nurul•this hour
Hello 👋 What variables have you defined in your .env.production file? Are all these variables defined?
DATABASE_URL=your_db_url
PG_USER=your_user
PG_PASS=your_password
DATABASE_URL=your_db_url
PG_USER=your_user
PG_PASS=your_password
Could you try this docker-compose.yml?
version: '3.9'
services:
app:
build:
context: .
args:
- DATABASE_URL=${DATABASE_URL}
container_name: RiskRealm
environment:
- DATABASE_URL=${DATABASE_URL}
env_file:
- .env.production
depends_on:
- db
ports:
- "3000:3000"

db:
image: postgres:16
environment:
- POSTGRES_USER=${PG_USER}
- POSTGRES_PASSWORD=${PG_PASS}
- POSTGRES_DB=riskrealm
volumes:
- postgres-data:/var/lib/postgresql/data

volumes:
postgres-data:
version: '3.9'
services:
app:
build:
context: .
args:
- DATABASE_URL=${DATABASE_URL}
container_name: RiskRealm
environment:
- DATABASE_URL=${DATABASE_URL}
env_file:
- .env.production
depends_on:
- db
ports:
- "3000:3000"

db:
image: postgres:16
environment:
- POSTGRES_USER=${PG_USER}
- POSTGRES_PASSWORD=${PG_PASS}
- POSTGRES_DB=riskrealm
volumes:
- postgres-data:/var/lib/postgresql/data

volumes:
postgres-data:
Also, here is a reference of adding docker with Prisma in a testing guide that we wrote: https://www.prisma.io/docs/orm/prisma-client/testing/integration-testing#add-docker-to-your-project
Integration testing with Prisma | Prisma Documentation
Learn how to setup and run integration tests with Prisma and Docker
aa55h
aa55hOP•23h ago
Okay I know where the issue is now, I have declared postinstall script as well, which at that time, the environment variable was not yet set from the arg, therefore failing to migrate, I have now fixed it and its working :)
Nurul
Nurul•22h ago
I am glad to hear that! 🙂
Want results from more Discord servers?
Add your server