keonik / prisma-erd-generator

Generate an ER Diagram based on your Prisma schema every time you run npx prisma generate
https://www.npmjs.com/package/prisma-erd-generator
MIT License
879 stars 48 forks source link

Remove puppeteer dependency when outputting mermaid markdown #176

Open mo-ayala opened 1 year ago

mo-ayala commented 1 year ago

Hello, we would love to use this plugin, but we are having an issue with the puppeteer dependency needed in order to generate the images, would it be possible to only generate the markdown text without the puppeteer dependency? thanks

keonik commented 1 year ago

Could you share the issue you're having with the puppeteer dependency? I'm not opposed to this at all. It would simplify so many of the issues associated with this project. Removing the dependency would break a lot of existing functionality for others though. Depending on the issue you're having it may be time to split this project off to have a prisma-to-markdown-erd generator

keonik commented 1 year ago

If you can install puppeteer and you are targeting a .md file as your output it should be able to bypass that dependency and run as a headless mermaid cli command

RPDeshaies commented 1 year ago

Hey @keonik ! I'm a colleague of @mo-ayala, so I'll share some more context around the issue we are having.

So technically, we don't have an issue per-say with the fact that the package has a dependency on puppeteer. Things work out perfectly, and we just had to configure some other things to make everything work. So in development mode, everything is fine.

That being said, when we run our npm ci command inside our Docker image that is used to deploy the service that uses Prisma, npm tries to install and configure puppeteer as well.

So the reason why we are reaching out here is that we feel like puppeteer is quite a heavy package, and installing it within our production Docker image feels like quite a waste of memory.

The alternatives we've considered include things like: running commands to delete the puppeteer node module directory before the image is finished, run a npm ci --omit=dev command and play around with the order in which things are executed, and similar things.

If you have another suggestion, we're all ears. That being said, I agree with you that having a package prisma-to-markdown-erd-generator feels very nice to me. But obviously, my opinion on this subject is very biased 😅

keonik commented 1 year ago

I have the same issue. Puppeteer is a beast of a project. Here is an example of what I do to remove package dependencies. It does require a second install and the --omit=dev command you have above. I also just remove the ERD generator because I don't want to generate it in my docker container. That's what you'll see with my sed command removing lines for the generator. It doesn't remove puppeteer though so you still need to run npm ci --omit=dev.

###########################################
# build
###########################################
ARG NODE_VERSION=16-alpine
FROM docker.io/node:${NODE_VERSION} as builder
RUN apk update && apk add bash

WORKDIR /usr/src/app
COPY . .

# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH

# remove and replace unnecessary generators (erd generator)
# Deletes lines 9-12 from prisma/schema.prisma
RUN sed -i '9,12d' prisma/schema.prisma

# install and cache app dependencies
COPY package* /usr/src/app/
RUN npm i --prefer-offline --no-audit --progress=false --silent
# Script to run `prisma generate` only if the prisma folders are missing
RUN scripts/generate.sh

# Package and build app
ENV NODE_ENV production
RUN npm run build

# Remove dev dependencies before we finish build stage
RUN npm ci --omit=dev --no-audit --silent
# rebuild prisma client only if the prisma folders are missing
RUN scripts/generate.sh

# Production image
FROM docker.io/node:${NODE_VERSION} as runner
RUN addgroup --system --gid 1001 nodejs
RUN adduser --system --uid 1001 nodeuser
USER nodeuser

# add `/app/node_modules/.bin` to $PATH
ENV PATH /usr/src/app/node_modules/.bin:$PATH

WORKDIR /usr/src/app

# Copy needed files for production
COPY --chown=nodeuser:nodejs --from=builder /usr/src/app/node_modules/ ./node_modules/ 
COPY --chown=nodeuser:nodejs --from=builder /usr/src/app/dist/ ./dist/ 
COPY --chown=nodeuser:nodejs --from=builder /usr/src/app/prisma/ ./prisma/ 
COPY --chown=nodeuser:nodejs --from=builder /usr/src/app/package.json ./package.json

# Our app will run on port 3000
EXPOSE 3000
# Stage 2
CMD ["./scripts/start.sh"]
keonik commented 1 year ago

There is a chance a dbml version of this repository is made on a different branch. TBD. I'm not sure if that one includes puppeteer or not but it was being proposed to support higher fidelity representations initially.