Can't find secrets in docker build

I am trying to use an environment variable to set my database url for Prisma ORM to use. I followed this article Using Secrets with Docker | Render to set up my url as a secret with the name DATABASE_URL in the Render dashboard and also set up my Dockerfile accordingly. However, my deploys are failing at the RUN step where Prisma uses the environment variable. I also tested out deploying with the environment variable hard coded in my Dockerfile which worked fine, so I know the issue is that my Prisma schema file is not able to access the secret as an environment variable.

Render log:

Sep 25 12:15:39 AM  ------
Sep 25 12:15:39 AM  Dockerfile:17
Sep 25 12:15:39 AM  --------------------
Sep 25 12:15:39 AM    15 |
Sep 25 12:15:39 AM    16 |     RUN npm i -g prisma
Sep 25 12:15:39 AM    17 | >>> RUN npx prisma migrate deploy
Sep 25 12:15:39 AM    18 |
Sep 25 12:15:39 AM    19 |     ENV PORT=5000
Sep 25 12:15:39 AM  --------------------
Sep 25 12:15:39 AM  error: failed to solve: process "/bin/sh -c npx prisma migrate deploy" did not complete successfully: exit code: 1

Dockerfile:

# syntax = docker/dockerfile:1.2

FROM node:18

WORKDIR /app

COPY package*.json ./
COPY prisma ./prisma

RUN npm install

COPY . .

RUN  --mount=type=secret,id=DATABASE_URL,dst=/etc/secrets/DATABASE_URL

RUN npm i -g prisma
RUN npx prisma migrate deploy

ENV PORT=5000
EXPOSE 5000

CMD [ "npm", "start" ]

Prisma schema (uses env("DATABASE_URL)):

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model User {
  id             Int     @id @default(autoincrement())
  username       String  @unique
  password       String
  firstName      String
  lastName       String
  iconColorHex   String
  reportedIssues Issue[] @relation("Reported")
  assignedIsuees Issue[]
}

model Issue {
  id           Int      @id @default(autoincrement())
  summary      String
  description  String
  type         String
  status       String
  reportedBy   User     @relation("Reported", fields: [reportedById], references: [id])
  reportedById Int
  assignedTo   User[]
  createdAt    DateTime @default(now())
  updatedAt    DateTime @updatedAt
}

Hi there,

Thanks for reaching out.

Using secret files in Docker, are just that, files. They are not automatically parsed into environment variables.

You would need to add something to take the /etc/secrets/DATABASE_URL file and read it into an environment variable.

Kind regards

Alan

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.