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

Netlify: Document why we need a specific configuration #1086

Closed
divyenduz opened this issue Dec 9, 2019 · 2 comments
Closed

Netlify: Document why we need a specific configuration #1086

divyenduz opened this issue Dec 9, 2019 · 2 comments

Comments

@divyenduz
Copy link
Contributor

divyenduz commented Dec 9, 2019

To make Prisma Client JS work with Netlify Functions, we need the following configuration:

generator client {
  provider = "prisma-client-js"
  binaryTargets = ["native", "rhel-openssl-1.0.x"]
}

This is because the netlify runtime is similar to AWS lambda which powers it and rhel linux is expected.

This might be a bit confusing to the users if they try to log the OS in the netlify's build step which is Ubuntu. But we don't need to make any configurational changes to make Prisma CLI (I think the only build step use case?) work as it is freshly installed on that platform.

We may want to document this behavior.

Related issue: prisma/prisma-client-js#324

(Note that you might need additional steps to ensure that this binary is bundled with netlify because netlify CI as of February 2020 uses an older version of ZISI which does not include this fix netlify/zip-it-and-ship-it#77)

@2color
Copy link
Contributor

2color commented Feb 26, 2020

I'm trying to better understand the two approaches for documentation and examples purposes.
I've looked at prisma/ecosystem-tests#46 (comment) and the e2e tests code.

I can't get either approach to work when deploying from the command line.

From what I understand, there are two possible build-approaches with Netlify:

  1. The default uses zip-it-and-ship-it when netlify deploy is called which packages the functions into a zip so that they can be deployed to Lambda by Netlify.
  2. Using the new Netlify Build. Provides more customisation options for build lifecycle. Currently in beta status.

Both approaches use the Netlify Build Image during build time which is different to the Lambda runtime. That's why we want to be able to run the build in the same image as the runtime (see netlify/build#730) so we don't have to explicitly define the binaryTargets in the schema.prisma for the runtime.

Approach 2 (Netlify Build) uses a different version of netlify/zip-it-and-ship-it by default, which solves the missing binary

Open questions

  1. Do both approaches use netlify/zip-it-and-ship-it for packaging the functions and their dependencies?

Answer: Yes according to this comment


  1. Why do we do the zipping our selves in a bash script?

Potential answer: Because the old version of netlify/zip-it-and-ship-it doesn't package the binaries with it.


  1. How does the build process differ (netlify/zip-it-and-ship-it version?) when running locally vs. on Netlify's build environment/CI with Github integration?

Current challenges

Binary missing at runtime

  • When deploying from the CLI both approach 1 and 2 result in the same error:
Query engine binary for current platform rhel-openssl-1.0.x could not be found.
Prisma Client looked in /var/task/node_modules/@prisma/client/runtime/query-engine-rhel-openssl-1.0.x but couldn't find it.
Make sure to adjust the generator configuration in the schema.prisma file:
generator client {
  provider      = "prisma-client-js"
  binaryTargets = ["native", "rhel-openssl-1.0.x", "rhel-openssl-1.0.x"]
}
Please run prisma2 generate for your changes to take effect.
Note, that by providing `native`, Prisma Client automatically resolves `rhel-openssl-1.0.x`.
Read more about deploying Prisma Client: https://github.com/prisma/prisma2/blob/master/docs/core/generators/prisma-client-js.md
    at PrismaClientFetcher.request (/var/task/node_modules/@prisma/client/index.js:91:17)
3:00:19 PM: Duration: 28.49 ms	Memory Usage: 80 MB	Init Duration: 208.06 ms	
3:00:30 PM: 2020-02-26T14:00:30.952Z	25b0dc16-60ca-4bd2-8a89-49dd557c8c77	ERROR	PrismaClientInitializationError: 
Invalid `prisma.profiles.deleteMany()` invocation in
/var/task/seed.js:6:39

There's an ongoing discussion about why this is happening locally: netlify/zip-it-and-ship-it#81

  • Works when deploying with Github integration (and ensuring the new version of netlify/zip-it-and-ship-it is used)

Getting both approaches to work with zero-config

  1. With both approaches, we still need to specify the binaryTargets.
  2. With approach 1 we need to set the ZISI_VERSION env var to make sure the latest version of netlify/zip-it-and-ship-it is used which fixes the missing binary problem.

@janpio janpio changed the title Document why we need a specific configuration on netlify Netlify: Document why we need a specific configuration Feb 28, 2020
@janpio janpio modified the milestones: Preview 23, Preview 24 Mar 3, 2020
@divyenduz divyenduz modified the milestones: Preview 24 Old, Preview 25 Mar 13, 2020
@2color
Copy link
Contributor

2color commented Mar 27, 2020

This is addressed in the new deployment guide.

It’s also encoded in the deployment example https://github.com/prisma/deployment-example-netlify/blob/master/netlify.toml

@2color 2color closed this as completed Mar 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants