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

Prisma binary query engine not ready #356

Open
PrzemyslawPluszowy opened this issue Apr 11, 2024 · 10 comments
Open

Prisma binary query engine not ready #356

PrzemyslawPluszowy opened this issue Apr 11, 2024 · 10 comments

Comments

@PrzemyslawPluszowy
Copy link

PrzemyslawPluszowy commented Apr 11, 2024

Sorry guys, i have another problem when I shot postman i get .
im using mac m1
Found query engine binary in /Users/przemyslawnowak/Documents/my_project/prisma-query-engine POST /user Error thrown by handler. Exception: Prisma binary query engine not ready package:orm/engines/binary.dart 114:13 BinaryEngine._serverEndpoint.<fn> package:retry/retry.dart 131:24 RetryOptions.retry

Can you help me?

@medz
Copy link
Owner

medz commented Apr 15, 2024

It seems like this is a repetitive problem, but there are many reasons that cause unpreparedness. I will look for an existing issue, hoping it will be helpful to you,

@medz
Copy link
Owner

medz commented Apr 15, 2024

#322
#161

@SL-Pirate
Copy link

Sorry for jumping right in but are you using sqlserver by any chance?
Because for some reason I got the exact same error. Despite the sort of unhelpful error message I suspected this should have something to do with the connection string so I started searching for a way to validate the connection string. And it also looked pretty fine. Finally I tried npx prisma migrate dev
Then it complained Error: P1011: Error opening a TLS connection: The TLS settings didn't allow the connection to be established. Please review your connection string. (error: error:1416F086:SSL routines:tls_process_server_certificate:certificate verify failed:ssl/statem/statem_clnt.c:1919: (self signed certificate))
After this point it was a breeze to debug.

I found my answer here

I had to add encrypt=false;trustServerCertificate=true to my DATABASE_URL. I'm not sure the encryption parameter is required but trustServerCertificate=true was the real fix.

PS: I'm not sorry if I sound disrespectful. I was stuck there for a few hours.

@medz
Copy link
Owner

medz commented Apr 25, 2024

@SL-Pirate I'm glad you found the problem 😊, I don't feel offended. Thank you for your reply. The same errors in different databases may come from different reasons.

Prisma's errors are not so open and transparent, so it is difficult for me to cover all the errors. But I will make it better in my limited time. Friendly error messages are also one of them. There are almost no contributors to this project. Although it is not satisfactory, I have been trying my best.

@SL-Pirate
Copy link

Yes, I totally understood that. I also contribute to open source so I understand your situation. I was on edge but knowing your situation I was trying my best to keep my cool.
Now that I'm cool I want to thank you for maintaining and developing this package. I'm really glad this exists and if it didn't I wouldn't know what to do.

Again sorry if I was even a bit rude :)

@kerimamansaryyev
Copy link
Contributor

Yesss, FINALLY, I solved the same issue. I am using Mac M1. Here are the things that you need to check @PrzemyslawPluszowy @SL-Pirate

  1. Make sure that you run npx prisma db push. So you have updated schema on your database.
  2. Make sure to give host name to your database container and set DATABASE_URL with the host name as envirionment variable, don't use localhost when containerizing.

These fixed my issue

@kerimamansaryyev
Copy link
Contributor

kerimamansaryyev commented May 22, 2024

I am working on an open-source project so I can post my DockerFike and docker-compose there. By the way, how I detected the fixes? When the dart frog server runs inside the container it tells: Running on http://:::8080. Fore sure, it has ip within InternetAddress object but not the host name. So, maybe, the containers do not come with default localhost host name.

Here is the docker compose:

version: "3"
services:

  # Launch the db first
  ribbit_database:
    container_name: ribbit_database
    hostname: ribbitdb
    image: mysql:latest
    restart: unless-stopped
    ports:
      - "3306:3306"
    environment:
      MYSQL_ROOT_PASSWORD: myPassword123
      MYSQL_DATABASE: hellav
      MYSQL_USER: kerim
      MYSQL_PASSWORD: myPassword123

  # Launch this after
  ribbit_main_service:
    container_name: ribbit_main_service
    build:
      dockerfile: ./ribbit_main_service/Dockerfile
      args:
        - DATABASE_URL=mysql://kerim:myPassword123@ribbitdb:3306/hellav
    ports:
      - "8080:8080"
    environment:
      - PORT=8080
      - JWT_SECRET=MyBiggestS3cr3t
      - DATABASE_URL=mysql://kerim:myPassword123@ribbitdb:3306/hellav

networks:
  ribbit:
    external: true

Here is the DockerFile:

FROM dart:stable AS build

# Download npm to work with prisma within the build phase involving Dart
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | bash - &&\
    apt-get install -y nodejs

# Copying middle-end package
WORKDIR /app/ribbit_middle_end

COPY ribbit_main_service/ribbit_middle_end/pubspec.* ./
RUN dart pub get

COPY ribbit_main_service/ribbit_middle_end/. .

WORKDIR /app/ribbit_server

# Copying the server package
COPY ribbit_main_service/ribbit_server/pubspec.* ./
RUN dart pub get

COPY ribbit_main_service/ribbit_server/. .


# Expose DATABASE_URL as build-time env variable for prisma
ARG DATABASE_URL

# Generate prisma-related files
RUN npm install prisma
RUN npx prisma generate

# Generate other Dart classes
RUN dart pub run build_runner build

# Bundle the project
RUN dart pub global activate dart_frog_cli
RUN dart pub global run dart_frog_cli:dart_frog build

# Generate executable
RUN dart pub get --offline
RUN dart compile exe build/bin/server.dart -o build/bin/server

# Configure runtime for prisma
RUN FILES="libz.so libgcc_s.so libssl.so libcrypto.so"; \
    for file in $FILES; do \
    so="$(find / -name "${file}*" -print -quit)"; \
    dir="$(dirname "$so")"; \
    mkdir -p "/runtime${dir}"; \
    cp "$so" "/runtime$so"; \
    echo "Copied $so to /runtime${so}"; \
    done


FROM scratch

# Copy runtime from previous build phase
COPY --from=build /runtime/ /

# Copy the source to review it within the Docker Container later
COPY --from=build /app/ribbit_server/. /app/source/

# Copy executable from the previous phase
COPY --from=build /app/ribbit_server/build/bin/server /app/bin/
# Copy executable the binary engine
COPY --from=build /app/ribbit_server/prisma-query-engine /app/bin/

# Prepare to execute the server within /app/bin/
WORKDIR /app/bin/

# Add required environment variables
ENV JWT_SECRET = "default-secret"
ENV PORT = 8080
ENV DATABASE_URL = ""

# Execute the server executable
CMD ["/app/bin/server"]

@kerimamansaryyev
Copy link
Contributor

@medz I think I could contribute into the docs about containerizing the Prisma since I'd been gathering the info into a whole for 3 days. I will read the guide

@medz
Copy link
Owner

medz commented May 22, 2024

@kerimamansaryyev Thank you very much, your PRs are always welcome❤️

@kerimamansaryyev
Copy link
Contributor

@medz It's ready, you can check #363. I made it detailed and clarified

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

No branches or pull requests

4 participants