DATABASE_URL environment variable not found

Error: Prisma schema validation - (get-config wasm) Error code: P1012 error: Environment variable not found: DATABASE_URL. --> prisma/schema.prisma:8 | 7 | provider = "postgres" 8 | url = env("DATABASE_URL") | Validation Error Count: 1 [Context: getConfig] anyone else hit this error before? I am running a Dockerized Express API on an AWS EC2, and entered environment variables via the
bash
docker run -e DATABASE_URL=${{ secrets.DATABASE_URL }}
bash
docker run -e DATABASE_URL=${{ secrets.DATABASE_URL }}
-e tag in the docker run command. This is all within the context of a CI/CD pipeline I'm setting up. Currently debugging and digging around for a solution.
3 Replies
RaphaelEtim
RaphaelEtim3w ago
Hi @Alex DiGrazia Can you add a step in your pipeline to echo the DATABASE_URL to ensure it's set correctly?
echo $DATABASE_URL
echo $DATABASE_URL
You may also waqnt to check that you don't wrap the environment variable in double quotation marks as observed in this previous discussion
GitHub
error: Environment variable not found: DATABASE_URL. · prisma prism...
Bug description Hello. I'm struggling with connecting to a database running in the docker container alongside my main app (nestjs+prisma). I'm getting the following error: #0 9.627 Prisma s...
Alex DiGrazia
Alex DiGraziaOP3w ago
Hi Raphael, thanks for your response. I think the problem was stemming from not having an ENV step in my Dockerfile. My Dockerfile looks like this, and I think that by not having an ENV step in the build process, my Prisma Generate doesn't have a Database variable available to generate the client. I'm very new to DevOps and Docker, and learning as I go. As per a tutorial I was following, I was entering -e variables in the Docker run command, but I realize now that doesn't actually help me at all in building the image when my image needs the DB variable in order to generate the client. Working through a solution in that vein now
No description
Alex DiGrazia
Alex DiGraziaOP3w ago
SOLVED Turns out what I needed to do was add

ARG DATABASE_URL
ENV DATABASE_URL=$DATABASE_URL

ARG DATABASE_URL
ENV DATABASE_URL=$DATABASE_URL
which initializes a build argument DATABASE_URL and then sets it as an environment variable so it will be availabe to subsequent steps in the Dockerfile, specifically
RUN npx prisma generate
RUN npx prisma generate
Then when in my Docker build step I include the
--build-arg
--build-arg
parameter. So my build step passes the argument to the docker file like this
docker build --build-arg DATABASE_URL=${{ secrets.DATABASE_URL }} -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker build --build-arg DATABASE_URL=${{ secrets.DATABASE_URL }} -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
Thanks for the help @RaphaelEtim Very happy to be newly part of the community.
No description
Want results from more Discord servers?
Add your server