You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I don't think we documented that .cache directory anywhere, so let's first do an internal documentation of what it is and how it works before we change it.
I did some work to reduce the size of prisma in production. The build is intended for Linux. And a Docerfile that works for me is:
RUN rm -rf node_modules/.cache/
RUN rm -rf node_modules/@prisma/engines/
RUN rm -rf node_modules/.prisma/client/query_engine-windows.dll.node
RUN rm -rf node_modules/prisma/
This results in a total size of 44MB:
41M .prisma
2.9M @prisma
The build only queries the database and I do not use migration in production.
Reacted by Joël Galeran, Thada Wangthammang and Samim Ozcan
(In our release 4.8.0 we have made significant improvements, average decrease of 50%, on the size of our engine files. That should ease the pain, but we will continue looking into other solutions of course. Expect more updates from us in this direction soon.)
#################### BUILD FOR PRODUCTION###################FROM node:18 As build
RUN curl -f https://get.pnpm.io/v6.16.js | node - add --global pnpm
WORKDIR /app
COPY --chown=node:node . .
RUN pnpm install --frozen-lockfile
RUN pnpx nx run remote-state-server:build-esbuild
USER node
#################### PRODUCTION#################### Not Natively support ARM64 (M1)FROM alpine:3.17 As production
ENV PORT=3333
ENV NODE_VERSION 18.12.1-r0
ENV NPM_VERSION 9.1.2-r0
ENV OPENSSL_COMPAT_VERSION 1.1.1s-r0
WORKDIR /app
COPY --chown=node:node package.json .
COPY --chown=node:node apps/remote-state-server/prisma ./prisma/
COPY --chown=node:node --from=build /app/dist/apps/remote-state-server .
RUN apk add --update --no-cache nodejs=$NODE_VERSION
RUN apk add --update --no-cache \
# For getting node-prune
curl \
# For Prisma client in Alpine# Fix "Error: Unable to establish a connection to query-engine-node-api library. It seems there is a problem with your OpenSSL installation!"# Ref: https://github.com/prisma/prisma/issues/14073
openssl1.1-compat=$OPENSSL_COMPAT_VERSION \
npm=$NPM_VERSION \
# npx will look the local node_modules first, if not it will install globally# Ref: https://stackoverflow.com/questions/22420564/install-only-one-package-from-package-json
&& PRISMA_CLIENT_VERSION=$(node -pe "require('./package').dependencies['@prisma/client']") \
&& PRISMA_VERSION=$(node -pe "require('./package').dependencies['prisma']") \
# We don't need package.json anymore
&& rm -rf package.json \
&& npm install @prisma/client@$PRISMA_CLIENT_VERSION \
&& npm install -D prisma@$PRISMA_VERSION \
# We don't have the existing sqlite file# So, we will create a fresh sqlite every time when build# This migration should be run every time when build
&& npx prisma migrate deploy \
# Prepare prisma library# If we don't have package.json, prisma will create for you, and create a local node_modules
&& npx prisma generate \
# Prune non-used files
&& npm prune --production \
# Clean Prisma non-used files https://github.com/prisma/prisma/issues/11577
&& rm -rf node_modules/.cache/ \
&& rm -rf node_modules/@prisma/engines/ \
&& rm -rf node_modules/@prisma/engines-version \
&& rm -rf node_modules/prisma \
# Remove cache
&& rm -rf /root/.cache/ \
&& rm -rf /root/.npm/ \
# Remove all unused dependecies
&& apk del openssl1.1-compat npm curl
EXPOSE ${PORT}
# Create a group and userRUN addgroup -g 1000 node \
&& adduser -u 1000 -G node -s /bin/sh -D node
USER node
CMD [ "node", "main.js" ]
Activity
Jolg42 commentedon Feb 2, 2022
The
.cachedirectory is used for downloading the binaries by the@prisma/enginesnpm package, the code lives here https://github.com/prisma/engines-wrapperI don't think we documented that
.cachedirectory anywhere, so let's first do an internal documentation of what it is and how it works before we change it.jsardev commentedon Sep 19, 2022
Any updates on this? I think things got even worse since this report, as having just the
@prisma/clientin dependencies ends up adding ~250mb of size:And that's apart from the
.cache, which adds additional ~153mb:Dockerizing an app using prisma (just the client) increases the image size by a total of ~400mb 😭
JardarTemalogic commentedon Dec 8, 2022
I did some work to reduce the size of prisma in production. The build is intended for Linux. And a Docerfile that works for me is:
This results in a total size of 44MB:
The build only queries the database and I do not use migration in production.
janpio commentedon Dec 20, 2022
(In our release 4.8.0 we have made significant improvements, average decrease of 50%, on the size of our engine files. That should ease the pain, but we will continue looking into other solutions of course. Expect more updates from us in this direction soon.)
mildronize commentedon Dec 24, 2022
I use Prisma 4.8.0 and remove unused files from this issue, finally i've got 17 MB of Prisma library ( from my blog post: https://thadaw.com/s/c2tcmvl/ (Note: sorry I'm writing in Thai))
fix(fetch-engine): prefer APPDATA over cwd-relative cache dir on Wind…
Update prisma monorepo to v7.9.0 (#30)
fix(fetch-engine): prefer APPDATA over cwd-relative cache dir on Wind…