Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove puppeteer dependency when outputting mermaid markdown #176

Open
mo-ayala opened this issue Feb 17, 2023 · 5 comments
Open

Remove puppeteer dependency when outputting mermaid markdown #176

mo-ayala opened this issue Feb 17, 2023 · 5 comments
Labels
enhancement New feature or request

Comments

@mo-ayala
Copy link

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
Copy link
Owner

keonik commented Feb 20, 2023

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 keonik added the enhancement New feature or request label Feb 20, 2023
@keonik
Copy link
Owner

keonik commented Feb 20, 2023

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
Copy link

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
Copy link
Owner

keonik commented Mar 22, 2023

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
Copy link
Owner

keonik commented Mar 22, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants