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

Precompiled engine files for aarch64-unknown-linux-musl target (Alpine Linux on ARM, e.g. M1) #8478

Closed
pantharshit00 opened this issue Jul 28, 2021 · 77 comments · Fixed by #17655
Assignees
Milestone

Comments

@pantharshit00
Copy link
Contributor

pantharshit00 commented Jul 28, 2021

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

  1. Ask user to compile the binary themselves
  2. Document use node:lts instead of node:lts-alpine which is not ideal.

Additional context

#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

@Brooooooklyn
Copy link

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 compile aarch64-unknown-linux-musl target, see https://github.com/napi-rs/package-template/blob/main/.github/workflows/CI.yaml#L79 for example.

@safareli
Copy link
Contributor

This could be "solved" by using docker build --platform linux/arm64 see this article

@jensmeindertsma
Copy link

What can I do to help get support for this implemented?

@huikaihoo
Copy link

Any plan or timeline to support this?

@artursudnik
Copy link

v3.7.0 has been released, but it seems that this issue is not fixed, is it?

@janpio
Copy link
Member

janpio commented Dec 27, 2021

The issue is not closed, hence the problem is not solved and stays open here for tracking.

@aqrln aqrln self-assigned this Jan 17, 2023
@mcbethio mcbethio added this to the 4.10.0 milestone Jan 17, 2023
@kewei5zhang
Copy link

kewei5zhang commented Jan 17, 2023

Is there a recent error message change? it is failing all docker Prisma builds with the pre-compiled prisma image workaround.

One of the requirements in my case is to run a docker image build on arm self-hosted runners to reduce the docker image build time. I was able to work it around by pre-compile prisma as the docker base image to have the stack build running on arm node, but a recent error message change failed our entire build pipeline. ( The error message was changed prob around 4hours before this comment )

Error: Prisma only supports Linux Alpine on the amd64 (x86_64) system architecture. If you're running Prisma on Docker, please use Docker Buildx to simulate the amd64 architecture on your device as explained by this comment: https://github.com/prisma/prisma/issues/8478#issuecomment-1355209706

@jkomyno

@kewei5zhang
Copy link

kewei5zhang commented Jan 17, 2023

NVM - fixed our code version to 4.8.0.

Is there a recent error message change? it is failing all docker Prisma builds with the pre-compiled prisma image workaround.

One of the requirements in my case is to run a docker image build on arm self-hosted runners to reduce the docker image build time. I was able to work it around by pre-compile prisma as the docker base image to have the stack build running on arm node, but a recent error message change failed our entire build pipeline. ( The error message was changed prob around 4hours before this comment )

Error: Prisma only supports Linux Alpine on the amd64 (x86_64) system architecture. If you're running Prisma on Docker, please use Docker Buildx to simulate the amd64 architecture on your device as explained by this comment: https://github.com/prisma/prisma/issues/8478#issuecomment-1355209706

@jkomyno

@jkomyno This change broke all pre-compiled workarounds on alpine 🥲.

@kewei5zhang
Copy link

kewei5zhang commented Jan 17, 2023

NVM - fixed the version on 4.8.0.

Is there a recent error message change? it is failing all docker Prisma builds with the pre-compiled prisma image workaround.
One of the requirements in my case is to run a docker image build on arm self-hosted runners to reduce the docker image build time. I was able to work it around by pre-compile prisma as the docker base image to have the stack build running on arm node, but a recent error message change failed our entire build pipeline. ( The error message was changed prob around 4hours before this comment )

Error: Prisma only supports Linux Alpine on the amd64 (x86_64) system architecture. If you're running Prisma on Docker, please use Docker Buildx to simulate the amd64 architecture on your device as explained by this comment: https://github.com/prisma/prisma/issues/8478#issuecomment-1355209706

@jkomyno

@jkomyno This change broke all pre-compiled workarounds on alpine 🥲.

Those who are facing the same issue as me using pre-compiled Prisma image to run Prisma on alpine arm64.

  1. Fix your prisma package to an older version other than 4.9.0. "prisma": "^4.8.1", -> "prisma": "4.8.1",
  2. Update pnpx prisma generate command to pnpx prisma@4.8.1 generate

@csulit
Copy link

csulit commented Jan 18, 2023

How to apply this with a docker-compose?

@MaxAst
Copy link

MaxAst commented Jan 23, 2023

@csulit you can do it like this:

version: "3.9"
services:
  api:
    platform: linux/amd64
    ports:
      - 4000:4000

aqrln added a commit to prisma/engine-images that referenced this issue Feb 2, 2023
aqrln added a commit to prisma/prisma-engines that referenced this issue Feb 2, 2023
Build the engines for `linux-musl-arm64-openssl-1.1.x` and `linux-musl-arm64-openssl-3.0.x`.

Ref: prisma/prisma#8478
Ref: prisma/engineer#87
Ref: prisma/engine-images#66
@aqrln
Copy link
Member

aqrln commented Feb 3, 2023

Hi 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!

@bmxpiku
Copy link

bmxpiku commented Feb 7, 2023

I tested this yesterday and works like a charm, error message is also clear finally :)
Updates I made to make it work:
package.json

"@prisma/client": "^4.10.0-dev.81",
"prisma": "^4.10.0-dev.81",

Dockerfile

-FROM node:16-alpine3.16 AS build
+FROM node:18-alpine3.17 AS build
+
+RUN apk add --update --no-cache openssl1.1-compat

schema.prisma

+binaryTargets = ["native", "linux-musl-openssl-3.0.x"]

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

@aqrln
Copy link
Member

aqrln commented Feb 7, 2023

@bmxpiku fyi you don't have to install openssl1.1-compat — Prisma supports OpenSSL 3 on Alpine since 4.8.0 (and it's better to use OpenSSL 3 when using Node.js 18 so you don't have two different versions of OpenSSL loaded in memory)

@bmxpiku
Copy link

bmxpiku commented Feb 7, 2023

oh, right - thanks 👍
I'll test it out once 4.10 is released

@Romanchuk
Copy link

@aqrln @bmxpiku

ARG ALPINE_VERSION=alpine3.17
ARG NODE_VERSION=18.14.0
prisma: 4.10.1

binaryTargets = ["native", "linux-musl-openssl-3.0.x"]

It is not working even if i add

RUN apk add --update --no-cache openssl1.1-compat

to my Dockerfile

2023-02-15 20:59:13 Error: Query engine library for current platform "linux-musl-openssl-3.0.x" could not be found.
2023-02-15 20:59:13 You incorrectly pinned it to linux-musl-openssl-3.0.x
2023-02-15 20:59:13 
2023-02-15 20:59:13 This probably happens, because you built Prisma Client on a different platform.
2023-02-15 20:59:13 (Prisma Client looked in "/app/node_modules/@prisma/client/runtime/libquery_engine-linux-musl-openssl-3.0.x.so.node")
2023-02-15 20:59:13 
2023-02-15 20:59:13 Searched Locations:
2023-02-15 20:59:13 
2023-02-15 20:59:13   /app/node_modules/.prisma/client
2023-02-15 20:59:13   /app/node_modules/@prisma/client
2023-02-15 20:59:13   /app/node_modules/@prisma/client
2023-02-15 20:59:13   /app/node_modules/.prisma/client
2023-02-15 20:59:13   /app/apps/plotform-server/prisma
2023-02-15 20:59:13   /tmp/prisma-engines
2023-02-15 20:59:13   /app/node_modules/.prisma/client
2023-02-15 20:59:13 
2023-02-15 20:59:13 
2023-02-15 20:59:13 To solve this problem, add the platform "linux-musl-openssl-3.0.x" to the "binaryTargets" attribute in the "generator" block in the "schema.prisma" file:
2023-02-15 20:59:13 generator client {
2023-02-15 20:59:13   provider      = "prisma-client-js"
2023-02-15 20:59:13   binaryTargets = ["native", "linux-musl", "linux-musl"]
2023-02-15 20:59:13 }
2023-02-15 20:59:13 
2023-02-15 20:59:13 Then run "prisma generate" for your changes to take effect.
2023-02-15 20:59:13 Read more about deploying Prisma Client: https://pris.ly/d/client-generator
2023-02-15 20:59:13     at DefaultLibraryLoader.getLibQueryEnginePath (/app/node_modules/@prisma/client/runtime/index.js:27476:13)
2023-02-15 20:59:13     at DefaultLibraryLoader.loadLibrary (/app/node_modules/@prisma/client/runtime/index.js:27394:33)
2023-02-15 20:59:13     at LibraryEngine.loadEngine (/app/node_modules/@prisma/client/runtime/index.js:27713:24)
2023-02-15 20:59:13     at LibraryEngine.instantiateLibrary (/app/node_modules/@prisma/client/runtime/index.js:27667:5)
2023-02-15 20:59:21 No errors found.

@aqrln
Copy link
Member

aqrln commented Feb 15, 2023

@Romanchuk this just looks like the expected Query Engine library file is not present in the generated client directory for whatever reason. The "You incorrectly pinned it to linux-musl-openssl-3.0.x" part is misleading, sorry about this, it's a known issue.

Could you please open a new issue or discussion and provide your Dockerfile? Thank you!

@Sakub
Copy link

Sakub commented Dec 27, 2023

Hi, I'm still facing the issues, none of the given fixes work for me.

Here's my Dockerfile:

FROM node:alpine

WORKDIR /app

COPY package.json /app/package.json

RUN apk add openssl3
RUN npm install

COPY . /app
RUN npx prisma generate

EXPOSE 3000
CMD ["npm", "run", "start"]

and my schema.prisma:

generator client {
  provider      = "prisma-client-js"
  binaryTargets = ["native", "linux-musl-openssl-3.0.x"]
}

test-1 | PrismaClientInitializationError: Prisma Client could not locate the Query Engine for runtime "linux-musl-arm64-openssl-3.0.x".
test-1 |
test-1 | This happened because Prisma Client was generated for "darwin-arm64", but the actual deployment required "linux-musl-arm64-openssl-3.0.x".
test-1 | Add "linux-musl-arm64-openssl-3.0.x" to binaryTargets in the "schema.prisma" file and run prisma generate after saving it:
test-1 |
test-1 | generator client {
test-1 | provider = "prisma-client-js"
test-1 | binaryTargets = ["native", "linux-arm64-openssl-3.0.x", "linux-musl-arm64-openssl-3.0.x"]
test-1 | }

Even if I provide the suggested targets from the error message problem still occurs. I use the M2 processor. Right now I can manage to not display this error by using the node-slim image but I would really want to use the node-alpine. Could somebody help me up with this?

@aqrln
Copy link
Member

aqrln commented Dec 27, 2023

@Sakub you added linux-musl-openssl-3.0.x and not linux-musl-arm64-openssl-3.0.x to your schema.

@Sakub
Copy link

Sakub commented Dec 27, 2023

@aqrln Even if I add linux-musl-arm64-openssl-3.0.x to my schema I'm still getting the PrismaClientInitializationError: Prisma Client could not locate the Query Engine error.

@aqrln
Copy link
Member

aqrln commented Dec 27, 2023

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.