Hello all. I am looking for some help with buildi...
# orm-help
r
Hello all. I am looking for some help with building the client for my docker container. The container is an Alpine based custom container. To that end I have added
linux-musl
to my
binaryTargets
in my schema. I added native (not sure if it is necessary) for the local build, on Ubuntu 18.04.
Copy code
datasource db {
  provider      = "postgresql"
  binaryTargets = ["native", "linux-musl"]
  url           = env("DATABASE_URL")
}
OK, so my assumption it that on running the client generation script, the binary should get downloaded into the output directory. The only engine binary that is copied to the output directory is
libquery_engine-debian-openssl-1.1.x.so.node
which satisfies the
native
option, but nothing for
linux-musl
. Checking the directory
node_modules/@prisma/engines/
I also see that only the
*-debian-*
engines are present. I guess my question is, how do I get the client generator to download the binaries required by the
biaryTargets
array? Or is there something I am missing here? I have searched here for a solution but no-one appears to have the same issue.
r
@Russell Ormes 👋 If you’re building on Alpine, then only
native
is needed.
r
Hi Ryan, I am building on the host, which is Ubuntu. I did copy the schema to the docker image and build the client on that image, however, I had the same issue, with the
linux-musl
binary not being downloaded. I will try that again. Given that I am generating the client on a machine using Ubuntu 18.04, do you have any insight why it might ignore the
linux-musl
requirement?
r
I don’t think the host machine matters in this case. I am building for Alpine on a Mac and the
linux-musl
binary gets downloaded as I have
native
set in
binaryTargets
. Just tried it on the latest version of Prisma and works fine.
Does the
linux-musl
binary get downloaded on your Ubuntu machine if you have it mentioned in
schema.prisma
?
r
No, that is the issue I am referring to. I added it to the
binaryTargets
and call
prisma generate
on the Ubuntu machine and nothing gets downloaded. I have my schema file in a custom directory and I have a custom output, so might that have an effect?
Copy code
datasource db {
  provider      = "postgresql"
  binaryTargets = ["native", "linux-musl"]
  url           = env("DATABASE_URL")
}

generator client {
  provider = "prisma-client-js"
  output   = "../../../../node_modules/.prisma/my-app"
}
then run
Copy code
prisma generate --schema ./apps/my-app/src/prisma/schema.prisma
r
Let me check with a custom output directory. Does it work when you remove the
output
field and let it generate in the the default folder i.e.
node_modules
?
r
No, I tried that one too 😕
It appears to ignore all but the native requirement
r
When building the Alpine image, could you check if it works by just using
native
?
r
Ok, will do (sorry, was on a call)
Copy code
node_modules/.prisma/my-client/
index-browser.js                    index.js                            runtime
index.d.ts                          libquery_engine-linux-musl.so.node  schema.prisma
ok, so it worked building inside the container with native
So I have a solution, thanks @Ryan, although I do not know why it won't work on my Ubuntu machine using the
binaryTargets
array...
💯 1
Appreciate the help @Ryan Very responsive 🦸
r
I think that is due to the default being N-API, you only get the binary for your system.
r
Ok. This is a reasonable work flow to build the client on each platform it is needed. I am using a mono-repo and so have some additional challenges with using the custom settings, due to the requirement of having multiple schema (and hence clients) so was attempting to build in a custom way. The docs don't mention that binaryTargets don't have an effect in library mode, although now you say it, it makes sense! The clue is in the name.. 😆