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

Add support for ARM architecture for CLI binaries #236

Closed
RobertCraigie opened this issue Jan 20, 2022 · 5 comments · Fixed by #454
Closed

Add support for ARM architecture for CLI binaries #236

RobertCraigie opened this issue Jan 20, 2022 · 5 comments · Fixed by #454
Labels
kind/improvement An improvement to existing feature and code. level/advanced priority/medium topic: external Tracking issues in other repositories

Comments

@RobertCraigie
Copy link
Owner

RobertCraigie commented Jan 20, 2022

Problem

Currently the CLI binary targets are: windows, linux and darwin. We should also build for targets such as node12-linux-arm64

Suggested solution

We do not currently have control over CLI binary building as this is handled and published by Prisma themselves. We will need to submit a PR in the Prisma Client Go repository.

The list of possible targets can be found here: https://github.com/vercel/pkg#targets.

Additional context

#195 (comment)

This is also more relevant now that we are adding support for ARM engine binaries in #233

@RobertCraigie RobertCraigie added the kind/improvement An improvement to existing feature and code. label Jan 20, 2022
@RobertCraigie RobertCraigie added the topic: external Tracking issues in other repositories label Jan 21, 2022
@tday
Copy link

tday commented Feb 1, 2022

I ran into this trying to generate the prisma client in the docker container on a M1 macbook. Surprisingly, it does build outside docker on my M1 (not sure how to explain that, but maybe something to do with the darwin target)

Workarounds I can think of:

  1. generate the prisma package on mac and version control it
  2. build the docker images using the --platform flag to target x86. This won't run locally on my M1 macbook, but will run in my production environments.

Any other ideas? I do see that vercel has arm targets so I'm not sure what's missing to get this unblocked. Also-- the prisma client go package has a deprecation notice so does it make sense to submit PRs there?

@tday
Copy link

tday commented Feb 1, 2022

generate the prisma package on mac and version control it

This doesn't work since the container still relies on the binaries in the current design of the python client

@RobertCraigie
Copy link
Owner Author

RobertCraigie commented Feb 1, 2022

Surprisingly, it does build outside docker on my M1

@tday It builds outside of docker because of Rosetta 2 which enables some cross-compatibility which I also only recently discovered lol steebchen/prisma-client-go#717 (comment)

Any other ideas? I do see that vercel has arm targets so I'm not sure what's missing to get this unblocked.

There is nothing that I'm aware of that is blocking this, the work just needs to be done.

Also-- the prisma client go package has a deprecation notice so does it make sense to submit PRs there?

Yes, the Go Client has been deprecated but the binaries will still be updated: https://github.com/prisma/prisma-client-go/tree/main/binaries#community-members

A better solution would be to roll our own binaries however I don't want to have to pay for any hosting costs.

generate the prisma package on mac and version control it

This doesn't work since the container still relies on the binaries in the current design of the python client

Currently, ARM engine binaries are not downloaded, however that is going to be fixed by #233.

You could download these binaries using the following script which should work:

set -eux

mkdir -p bin

curl https://binaries.prisma.sh/all_commits/34df67547cf5598f5a6cd3eb45f14ee70c3fb86f/darwin-arm64/prisma-fmt.gz -o bin/prisma-fmt
curl https://binaries.prisma.sh/all_commits/34df67547cf5598f5a6cd3eb45f14ee70c3fb86f/darwin-arm64/introspection-engine.gz -o bin/introspection-engine
curl https://binaries.prisma.sh/all_commits/34df67547cf5598f5a6cd3eb45f14ee70c3fb86f/darwin-arm64/migration-engine.gz -o bin/migration-engine
curl https://binaries.prisma.sh/all_commits/34df67547cf5598f5a6cd3eb45f14ee70c3fb86f/darwin-arm64/query-engine.gz -o bin/query-engine

chmod +x bin/prisma-fmt
chmod +x bin/introspection-engine
chmod +x bin/migration-engine
chmod +x bin/query-engine

You could then copy these binaries into the docker image and configure Prisma Python to use them by setting env variables:

PRISMA_QUERY_ENGINE_BINARY=bin/query-engine
PRISMA_MIGRATION_ENGINE_BINARY=bin/migration-engine
PRISMA_INTROSPECTION_ENGINE_BINARY=bin/introspection-engine
PRISMA_FMT_BINARY=bin/prisma-fmt

Also another potential solution is to use the Node CLI through npx however I don't know how well this would work within a docker container.

@tday
Copy link

tday commented Feb 1, 2022

I was able to get this working using the --platform flag on M1, actually. I like the npx idea though, that would be less hacky. I may give that a try if I have time to come back to this to clean up.

Here's what my dockerfile looks like in case others stumble onto it:

FROM --platform=linux/amd64 python:3.9

# Copy code
RUN mkdir /data-service
WORKDIR /data-service
COPY Pipfile .
COPY Pipfile.lock .
COPY prisma .
COPY src src/

# Install dependencies
RUN curl https://raw.githubusercontent.com/pypa/pipenv/master/get-pipenv.py | python
RUN pipenv install --system --deploy --ignore-pipfile
RUN prisma generate

# Start service
CMD ["python3", "src/app.py"]

Side note: Thanks so much for being so responsive and helpful. This package has so much potential and it inspires confidence to see how you have structured and maintained it! I'm looking to get a production app running with this to see if it performs well at scale. I hope I can have time to contribute enhancements as I get further along, but right now I'm in prototyping stage for my company.

@RobertCraigie
Copy link
Owner Author

Side note: Thanks so much for being so responsive and helpful. This package has so much potential and it inspires confidence to see how you have structured and maintained it! I'm looking to get a production app running with this to see if it performs well at scale.

Thank you so much! That means a lot to me :)

I hope I can have time to contribute enhancements as I get further along, but right now I'm in prototyping stage for my company.

Your contributions would be more than welcome and that is really exciting! Please let me know how it goes for you and if there are any improvements I could make!

Also feel free to join the community discord server if you have any questions / need any additional support :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/improvement An improvement to existing feature and code. level/advanced priority/medium topic: external Tracking issues in other repositories
Projects
Development

Successfully merging a pull request may close this issue.

2 participants