Btw there seems to also be an open issue for an ex...
# prisma-client
k
Btw there seems to also be an open issue for an example Dockerfile https://github.com/prisma/prisma-examples/issues/1856
r
k
Yes I checked that out though this will result in having all the devDependencies in the final image if I am not mistaken
r
Something like this then?
Copy code
FROM node:14.9.0-alpine3.12 as dev

WORKDIR /app

RUN apk add --no-cache --virtual .build-deps alpine-sdk python3

COPY package.json yarn.lock ./

COPY prisma ./prisma

RUN yarn install --frozen-lockfile

# RUN apk del .build-deps

FROM node:14.9.0-alpine3.12

WORKDIR /app

COPY --from=dev /app/package.json /app/yarn.lock /app/prisma ./

RUN yarn install --frozen-lockfile --production && \
  rm -rf node_modules/@prisma/engines

COPY . .

EXPOSE 3001

CMD [ "yarn",  "start" ]
Just an example with installing just the production dependencies in the final stage.
k
@Ryan Where are you running prisma generate ? What do you exclude using
.dockerignore
when running
COPY . .
?
r
Just
node_modules
k
Ok in which step is the client generated ?
As the code for the prisma client resided in the
node_modules
r
Prisma automatically runs
prisma generate
when you run
npm install
or
yarn
.
k
I am using an approach like this
Copy code
FROM node:14-alpine AS builder
ARG PORT

WORKDIR /usr/src/app

COPY .npmrc ./
COPY package*.json ./
COPY tsconfig*.json ./

RUN npm install

COPY src src

COPY ./prisma ./prisma
RUN npx prisma generate
RUN npm run build

FROM node:14-alpine
ENV NODE_ENV=production

WORKDIR /usr/src/app

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

RUN npm ci --only=production
RUN npm i -g prisma@2.28.0
RUN prisma generate
RUN rm -rf node_modules/@prisma/engines

COPY --from=builder /usr/src/app/dist dist

USER node
EXPOSE $PORT

CMD [ "node", "dist/server.js" ]
I have to use prisma generate 2 times one for the typescript compilation to succeed and one in the final image to have the artifacts of prisma generate. Copying them from step one did not work. Don’t know if I was doing something wrong there
r
If you move
COPY ./prisma ./prisma
before
npm install
, you don’t need to run
prisma generate
explicitly.
This setup seems fine. Only production dependencies are included in the final build.
k
Ok will do your suggestion thanks
👍 1
r
Let me know how it goes 🙂
k
@Ryan Yes this worked. I just have the global prisma in the final image. I could skip the rest of the
devDependencies
though
r
Yea
npm install --production
will skip all those 🙂