prisma: Precompiled engine files for `aarch64-unknown-linux-musl` target (Alpine Linux on ARM, e.g. M1)
Problem
Right now you can’t use Prisma on Docker alpine on M1 mac as it requires aarch64-unknown-linux-musl
binaries. As M1 will see more adoption, people will run into this frequently.
Suggested solution
Provide precompiled binaries for aarch64-unknown-linux-musl
target like we have precompiled binaries for x86-linux-musl
Alternatives
- Ask user to compile the binary themselves
- Document use
node:lts
instead ofnode:lts-alpine
which is not ideal.
Additional context
https://github.com/prisma/prisma/issues/7755
Naming as unknown
is intended like that, see more information internally: https://prisma-company.slack.com/archives/C016KUHB1R6/p1627469574008300?thread_ts=1626873669.001400&cid=C016KUHB1R6
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 77
- Comments: 77 (16 by maintainers)
Links to this issue
Commits related to this issue
- [skip ci]: chore: link to https://github.com/prisma/prisma/issues/8478 — committed to prisma/ecosystem-tests by jkomyno a year ago
- feat: docker os support followup (#3343) * chore: remove useless "yarn install" in host machine It increases the latency and the context size being shared with Docker, without actually being used.... — committed to prisma/ecosystem-tests by jkomyno a year ago
- Add cross-compile images for Alpine ARM64 (#66) Add cross-compile images for ARM64 musl. Ref: https://github.com/prisma/prisma/issues/8478 Ref: https://github.com/prisma/engineer/pull/87 — committed to prisma/engine-images by aqrln a year ago
- Update engineer to 1.47 to build ARM64 musl binaries (#3656) Build the engines for `linux-musl-arm64-openssl-1.1.x` and `linux-musl-arm64-openssl-3.0.x`. Ref: https://github.com/prisma/prisma/issu... — committed to prisma/prisma-engines by aqrln a year ago
This could be “solved” by using
docker build --platform linux/arm64
see this articleHi everyone! Native support for Alpine Linux on ARM64 CPUs is now merged and will be released in Prisma 4.10.0 on Tuesday. You shouldn’t need any workarounds like running the image in emulation or building the engines yourselves starting with 4.10.0. Please let us know if you have any feedback!
Yeah, this has become an issue for our engineers using M1s - is there any indication as to whether this item is any sort of priority?
nobody assigned on this? it would be great to get prisma working without sucking my entire m1 pro battery in 3h because of the x86 emulation inefficiency 😕
Hopefully this will help in the interim:
We have this in our radar and hope to work on a solution soon, sadly, thanks to the way our build process work and the complexities of cross compilation and MUSL we cannot give yet a release date for this feature, sorry. I will keep posted and update when this is done and available.
Here is what I have working on M1 @exsesx
How can we help get this prioritised?
Any update on this?
Any plan or timeline to support this?
We published an image because of how long it takes to build the prisma binaries, will make the workaround faster:
what can we do to help? Our org security policy prevents us to use node lts or slim and alpine is the only option.
Hey everyone, Alberto from Prisma here. Please notice that this issue is about providing compiled Prisma engines for Linux images using the
musl
C standard library onaarch64
/arm64
architectures. This could be particularly useful to users on macOS with M1/M2 CPUs running Docker images based on Linux Alpine.While we’re working on our end to support this natively, most of you can already overcome this problem by using Docker Buildx, which supports a custom
--platform
flag.For example, given an example
Dockerfile
likeyou can build it with
which acts as if you’re running Docker on an
x86_64
architecture.Note:
buildx
from the command above, like so:@zackdotcomputer, @bb-centrum, please refer to https://github.com/prisma/prisma/issues/16553#issuecomment-1353302617 for a working solution to the problems you’ve mentioned.
TL/DR, you have two choices:
Use a Node.js Docker image based on Alpine 3.16, like
node:alpine3.16
,node:lts-alpine3.16
,node:18.12.1-alpine3.16
(encouraged)Install OpenSSL 1.1.x via the
openssl1.1-compat
package, e.g., by addingto your Dockerfile before installing Prisma
Notes:
libc
/libc6-compat
on Linux Alpine to fix the problem. Please DON’T do this, as it could cause other unexpected errors.My workaround is just to rely on
node:xx-slim
instead ofnode:xx-alpine
.What can I do to help get support for this implemented?
I got this working on 4.4.0 with the following dockerfile:
@csulit you can do it like this:
@jkomyno Small suggestion as it seems many people are running into this issue (alpine is popular). Maybe there is a way to detect alpine is being run and for Prisma to give a nice error message.
@ateethk thank you!
I was also able to get this working on M1 Mac by using the
node:18-slim
image and installing OpenSSL.@brizandrew Keystone depends on
"@prisma/client": "3.12.0"
whilepositivly/prisma-binaries:latest
only works with 3.9.Yeah, emulating amd64 is working. Luckily M1 is so fast it doesn’t matter all that much. One can do this in the
docker-compose.yml
also/instead:Thanks @aleccool213, we’re tracking the idea of improving the error messages in https://github.com/prisma/prisma/issues/16970, which we’m working on. A first big step in that direction is preparing several different scenarios where Prisma can be installed and run. (You can take a sneak peek in here ☺️)
I’m maintaining Docker images for cross compile: https://github.com/orgs/napi-rs/packages/container/package/napi-rs%2Fnodejs-rust. The
ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-alpine
is for compileaarch64-unknown-linux-musl
target, see https://github.com/napi-rs/package-template/blob/main/.github/workflows/CI.yaml#L79 for example.I tested this yesterday and works like a charm, error message is also clear finally 😃 Updates I made to make it work: package.json
Dockerfile
schema.prisma
Just fyi - in my case, it seems we were building docker images on different architecture then running them, hence I had to add a binary target. Also, we wanted to upgrade node to 18, which was failing before, and without a clear error message I didn’t wanted to invest time in playing with building it FROM prisma source.
So thanks @aqrln 😃 great update
Thanks for the detailed response but running
docker buildx build --load -f Dockerfile --platform=linux/amd64
won’t help if you’re trying to build an image to run on arm64 e.g. a M1 Mac or Raspberry Pi in my case.It will help if you want to build an x86 image on arm64 hardware.
You can check this discussion: https://github.com/prisma/prisma/issues/16553#issuecomment-1353302617
I’m getting the same result as @ggohierroy with a similar Dockerfile:
Error:
and I definitely do not have any
binaryTargets
specified in myPrisma.schema
:This is my Dockerfile right now, but it still fails with the same error when
npx prisma generate
is runError: Unknown binary target linux-arm64-openssl-undefined in generator client.
Hi @ggohierroy
This should be fixed if you replace line 5:
With:
(also removed
--jobs 1
as per comment above to make it run faster)I use
amd64/node:16-alpine
image in the case of M1 Mac. But, this solution can not solve the essential problem.@Sakub did you regenerate the client after that? If it doesn’t help, please open a new issue with reproduction, or a new discussion if you don’t think you’re hitting a bug and just need help. This issue is already fixed and is unrelated to your problem, and posting here sends an email to more than 50 people that were subscribed to it.
Hey @bb-centrum, re:
Prisma natively supports
arm64
for most Linux distros, but not for Linux Alpine. If you need to run Prisma on a Docker container running on e.g. Raspberry Pi, please usenode:18-slim
ornode:lts-slim
as a base image (which runs on Linux Debian Bullseye and usesopenssl-1.1.x
).If you really want to keep Linux Alpine, please use Docker Buildx
--platform
as detailed in this comment. Thank you!Hey @bb-centrum sorry - added an edit above to clarify that this is a specific additional issue for Alpine and needs to be done in addition to sorting out the arm64 vs amd64 issues.
The latest version of Alpine includes only openssl 3.x, which appears to be incompatible with Prisma’s usage - as pointed out in this comment.
I was able to fix this issue without downgrading alpine, adding the platform emulation flag, or abandoning alpine in favor of vanilla debian. In my case, adding
RUN apk add --update --no-cache openssl1.1-compat
to the start of my Dockerfile fixed the issue.EDIT: This is not the only issue with using Prisma on M1 macs inside of an Alpine docker container. This is just one of the issues present and a new one at that which might be the culprit if you have had your build suddenly break like mine did.
I’m using
node:18-alipine
, upgraded from prisma3.14
to4.3.1
and now I experience the same issue…PS: I’m not running this via compose - but deploy image to AWS ECS (fargate) and it doesn’t want to work there
It is similar to what was posted above:
Built with
docker buildx build --platform=linux/amd64,linux/arm64 --push -t positivly/prisma-binaries:latest -f Dockerfile.prisma .
For some reason I couldn’t get the build to work on an intel machine, on an M1 it builds for both platforms but the cross compilation takes forever.
Yes they are built from prisma-engine 3.9, and openssl is required still (openssl-dev should not be needed, though)
@aqrln Hi, nothing like that in my schema file. It’s just the one from the tutorial for NextJS + Prisma.
@aqrln ahh that’s probably it. I couldn’t get the so lib to load so I just switched to the binary, let me try that change.