oven-sh / bun

Incredibly fast JavaScript runtime, bundler, test runner, and package manager – all in one
https://bun.sh
Other
72.33k stars 2.58k forks source link

Bun doesn't run prisma generate or prisma migrate inside docker containers or WSL #5320

Closed sum117 closed 4 months ago

sum117 commented 10 months ago

What version of Bun is running?

1.0.1+31aec4ebe325982fc0ef27498984b0ad9969162b

What platform is your computer?

Microsoft Windows NT 10.0.22621.0 x64

What steps can reproduce the bug?

Docker:

FROM oven/bun AS builder

WORKDIR /tmp/app

COPY package.json .
COPY bun.lockb .

RUN bun install

COPY src ./src
COPY tsconfig.json .

# This would be the optimal solution but it doesn't work, so I'm gonna use a hack here until I figure out how to fix it
#   RUN bunx prisma:generate
#   COPY prisma/schema.prisma ./prisma/schema.prisma
COPY node_modules/.prisma ./node_modules/.prisma

RUN bun run build

FROM oven/bun AS runner

ARG DEFAULT_DATABASE_URL= "file:./deploy.db"
ENV DATABASE_URL=$DEFAULT_DATABASE_URL

WORKDIR /app

COPY --from=builder /tmp/app/package.json /app/package.json
COPY --from=builder /tmp/app/bun.lockb /app/bun.lockb
RUN bun install -p

# Refer to the comment above
#   COPY --from=builder /tmp/app/prisma/schema.prisma ./prisma/schema.prisma
#   RUN bun run prisma:generate
COPY --from=builder /tmp/app/node_modules/.prisma /app/node_modules/.prisma

#   These commands aren't working either. The prisma:migrate has to be done in the external machine
#   RUN bun add prisma
#   RUN bun run prisma:migrate

COPY --from=builder /tmp/app/build /app/build

CMD ["bun", "start"]

WSL:

Install WSL normally...

wsl --install

Make bun installation inside Ubuntu.

Try to follow this exact guide: https://bun.sh/guides/ecosystem/prisma

What is the expected behavior?

Prisma installs normally

What do you see instead?

This, download never finishes:

root@7fa00e64baa1:/app# bun run prisma:deploy
$ bunx prisma migrate deploy
Downloading Prisma engines for Node-API for debian-openssl-1.1.x [===                 ] 15%root@7fa00e64baa1:/app#

Additional information

No response

neilsong commented 4 months ago

With bun 1.0.31, prisma generate does not work with a non-trivial schema already in docker context, hanging without exiting.

# bunx prisma generate
Prisma schema loaded from prisma/schema.prisma

All subsequent prisma generate commands after interrupting the first process exit silently.

ThallesP commented 3 months ago

@Jarred-Sumner I'm still getting issues where Prisma silently fails, shouldn't this issue be open? image no output or anything. is there anything that Bun can do to atleast show some info while this isnt fixed? i've spent 2hours today trying to debug this. and also can confirm, with node binary prisma works without any problem.

zackify commented 2 months ago

yeah, there is no output running bunx prisma migrate deploy still.

fzn0x commented 2 months ago

I wasted so many times on this, I hope we can get better solutions soon 😄

roobr commented 2 months ago

I am also having this issue

the-dream-machine commented 1 month ago

This issue is still present in v1.1.13. @Jarred-Sumner can we reopen this?

the-dream-machine commented 1 month ago

If anyone is looking for a sample Dockerfile to use before this is fixed, this one worked for me:

# Set Bun and Node version
ARG BUN_VERSION=1.1.13
ARG NODE_VERSION=20.12.2
FROM imbios/bun-node:${BUN_VERSION}-${NODE_VERSION}-slim

# Set production environment
ENV NODE_ENV="production"

# Bun app lives here
WORKDIR /app

# Copy app files to app directory
COPY . .

# Install node modules
RUN bun install

# Generate Prisma Client
RUN bun prisma generate

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD [ "bun", "run", "start" ]

This image contains both bun and node.js. The slim variant strips out all the unnecessary files. Good luck traveler :)

amir-s commented 1 month ago

I can confirm this is still an issue. bunx prisma -v, bunx prisma generate and most other commands fail silently. Adding COPY --from=node:20 /usr/local/bin/node /usr/local/bin/node to the docker file solved the issue for now.

cholasimmons commented 1 month ago

I believe it works starting from version 1.1.13 up to .16. Remember Prisma is a devDependency so trying to run that code in production should fail.

amir-s commented 1 month ago

Remember Prisma is a devDependency so trying to run that code in production should fail.

Mostly yes. But the migrations are also a production concern and bunx prisma migration deploy fails as well.

cholasimmons commented 1 month ago

Well yes but you're still trying to use a program that's non existent due to the environment you're in (Prisma in production). One way could be to copy the migrations SQL file(s) to a location where you can directly execute it into the database. This is usually what happens when deploying to the cloud anyways

Jarred-Sumner commented 1 month ago

To those of you running into this issue in more recent versions of Bun -- please provide some kind of reproduction and open a new issue. The original cause was fixed (and I've manually verified it continues to work in a simple case), but that means we need more information in order to address any new issues you're running into.

Also, if you're using Alpine Linux, it will likely not work until #918 is addressed.