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

Could not find query engine binary for current platform "linux" in query-engine path. #55

Closed
jakub-stefaniak opened this issue Oct 26, 2022 · 13 comments

Comments

@jakub-stefaniak
Copy link

jakub-stefaniak commented Oct 26, 2022

The problem happens when I try to dockerize the app. I use prisma with dart_frog and postgres
Here's what happens when I try calling an endpoint that does some db query with prisma.

build-server-1  | [ERROR] 2022-10-26 19:17:17.623771    0:00:00.001226  POST    /auth/user
build-server-1  | PrismaClientInitializationError:
build-server-1  |   message: Could not find query engine binary for current platform "linux" in query-engine path.
build-server-1  |
build-server-1  | This probably happens, because you built Prisma Client on a different platform.
build-server-1  |
build-server-1  | Searched Locations:
build-server-1  |   - /
build-server-1  |   - /app/bin
build-server-1  |   - /app/.dart_tool/prisma
build-server-1  |
build-server-1  | You already added the platform "linux" to the "generator" block in the "schema.prisma" file as described in https://pris.ly/d/client-generator, but something went wrong. That's suboptimal.
build-server-1  |
build-server-1  | Please create an issue at https://github.com/odroe/prisma-dart/issues/new
build-server-1  |   errorCode: null
build-server-1  |   clientVersion: 2.4.0
build-server-1  |
build-server-1  | package:shelf/src/middleware/logger.dart 30  logRequests.<fn>.<fn>.<fn>
build-server-1  |
build-server-1  | ERROR - 2022-10-26 19:17:17.626072
build-server-1  | POST /auth/user
build-server-1  | Error thrown by handler.
build-server-1  | PrismaClientInitializationError:
build-server-1  |   message: Could not find query engine binary for current platform "linux" in query-engine path.
build-server-1  |
build-server-1  | This probably happens, because you built Prisma Client on a different platform.
build-server-1  |
build-server-1  | Searched Locations:
build-server-1  |   - /
build-server-1  |   - /app/bin
build-server-1  |   - /app/.dart_tool/prisma
build-server-1  |
build-server-1  | You already added the platform "linux" to the "generator" block in the "schema.prisma" file as described in https://pris.ly/d/client-generator, but something went wrong. That's suboptimal.
build-server-1  |
build-server-1  | Please create an issue at https://github.com/odroe/prisma-dart/issues/new
build-server-1  |   errorCode: null
build-server-1  |   clientVersion: 2.4.0
build-server-1  |

Here's my scheme.prisma file:

// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider        = "prisma-client-dart"
  previewFeatures = ["interactiveTransactions"]
  output          = "../lib/prisma_client.dart"
  binaryTargets   = ["native", "linux-musl"]
}

datasource db {
  provider = "postgresql"
  url      = "postgres://app_user:password@localhost:5432/app_db?schema=public"
}

model User {
  id            Int           @id @default(autoincrement())
  email         String
  passwordHash  String
  firstName     String
  lastName      String
  createdAt     DateTime      @default(now())
  updatedAt     DateTime      @updatedAt
  restaurants   Restaurant[]
  sessions      UserSession[]
}

model UserSession {
  id            Int           @id @default(autoincrement())
  userId        Int
  accessToken   String
  refreshToken  String
  expiresAt     DateTime
  createdAt     DateTime      @default(now())
  updatedAt     DateTime      @updatedAt
  
  user          User          @relation(fields: [userId], references: [id])
}

model Restaurant {
  id            Int           @id @default(autoincrement())
  userId        Int
  address       String
  meals         Meal[]
  createdAt     DateTime      @default(now())
  updatedAt     DateTime      @updatedAt

  user          User          @relation(fields: [userId], references: [id])
}


model Meal {
  id            Int           @id @default(autoincrement())
  restaurantId  Int
  name          String
  createdAt     DateTime      @default(now())
  updatedAt     DateTime      @updatedAt

  restaurant    Restaurant    @relation(fields: [restaurantId], references: [id])
}
@medz
Copy link
Owner

medz commented Oct 27, 2022

The problem seems to be in your Dockerfile where you did not generate and copy the query engine binary.

Usually to Dockerize you need to set the PRISMA_QUERY_ENGINE_BINARY environment variable in the Dockerfile (you can not set it, it is stored in .dart_tool/prisma/query-engine by default), and then copy it to the same directory as your compiled Dart file.

The following is the normal copy process:

  1. dart compiler exe <app>.dart -o /app/bin/<app> # Compile your app executable file
  2. dart run orm precache -t query # Predownload prisma query engine
  3. cp .dart_tool/prisma/query-engine /app/bin/# Copy query engine to /app/bin/ dir

@medz medz added the question label Oct 27, 2022
@jakub-stefaniak
Copy link
Author

Problem still exists after I added copy and generate steps to my dockerfile

# Official Dart image: https://hub.docker.com/_/dart
# Specify the Dart SDK base image version using dart:<version> (ex: dart:2.17)
FROM dart:stable AS build

WORKDIR /app

# Copy Dependencies

# Install Dependencies

# Resolve app dependencies.
COPY pubspec.* ./
RUN dart pub get

# Copy app source code and AOT compile it.
COPY . .
# Ensure packages are still up-to-date if anything has changed
RUN dart pub get --offline

RUN dart run orm generate

RUN dart compile exe bin/server.dart -o bin/server

RUN dart run orm precache -t query
COPY .dart_tool/prisma/query-engine /app/bin/


# Build minimal serving image from AOT-compiled `/server` and required system
# libraries and configuration files stored in `/runtime/` from the build stage.
FROM scratch
COPY --from=build /runtime/ /
COPY --from=build /app/bin/server /app/bin/


# Start server.
CMD ["/app/bin/server"]

@medz
Copy link
Owner

medz commented Oct 27, 2022

https://github.com/odroe/prisma-dart/blob/main/example/simple/Dockerfile Maybe it will help you

In the simple example it fails when it runs, because using SQLite in the scratch benchmark image seems to be a bit of a problem, and my attempts to connect to MySQL and PG are both successful.

@jakub-stefaniak
Copy link
Author

Thanks @medz! Now it looks like the problem with query-engine has been resolved. However, there is another issue:

build-server-1  | PrismaClientInitializationError:
build-server-1  |   message: Failed to start the query engine: Connection refused
build-server-1  |   errorCode: null
build-server-1  |   clientVersion: 2.4.0

My first guess was that I have wrong connection uri in the scheme.prisma:

datasource db {
  provider = "postgresql"
  url      = "postgres://app_user:password@localhost:5432/app_db?schema=public"
}

but it looks good.

Here's also my docker-compose file

version: '3'
services:
  server:
    image: app/app_server
    ports:
      - "8080:8080"
    depends_on:
      - db
    links:
      - db:db
    networks:
      - pgnetwork
  db:
    image: postgres
    ports:
      - "5432:5432"
    environment:
      POSTGRES_DB: app_db
      POSTGRES_USER: app_user
      POSTGRES_PASSWORD: password
    networks:
      - pgnetwork
  # Uncomment this if you want to persist the data.
  # volumes:
  #   - "./pgdata:/var/lib/postgresql/data"

networks:
  pgnetwork:
      driver: bridge

@medz
Copy link
Owner

medz commented Oct 28, 2022

@jakub-stefaniak Your DATABASE_URL is indeed wrong, I'm not familiar with compose so I'm not sure how to solve your problem. Since I have postgres installed locally I have no problem connecting to my local postgres in the container.

@medz
Copy link
Owner

medz commented Oct 28, 2022

You can try replacing the URLs in schema.prisma with environment variables, and then configuring the correct environment variables in the compose configuration file may solve it.

@medz
Copy link
Owner

medz commented Oct 28, 2022

Maybe something to do with SSL, I'll keep testing it.

@medz
Copy link
Owner

medz commented Oct 28, 2022

@medz
Copy link
Owner

medz commented Oct 28, 2022

@jakub-stefaniak I rewrote the Dockerfile through ubuntu:latest and it seems to solve the problem, I guess the scratch benchmark image is missing something necessary for the Prisma query engine. At present, through your error message, I presume it is SSL (OpenSSL or LibSSL). It seems we can fix it by manually installing an SSL for the sights.

see: https://github.com/odroe/prisma-dart/blob/main/example/simple/Dockerfile.ubuntu

@medz
Copy link
Owner

medz commented Oct 28, 2022

image

@medz
Copy link
Owner

medz commented Nov 3, 2022

@jakub-stefaniak Has this been resolved? Is there any further help needed, the result of my current tests is that OpenSSL needs to be installed. Unable to connect because the target image does not have OpenSSL or LibSSL.

@AndryHTC
Copy link

AndryHTC commented Dec 7, 2022

Thanks @medz! Now it looks like the problem with query-engine has been resolved. However, there is another issue:

build-server-1  | PrismaClientInitializationError:
build-server-1  |   message: Failed to start the query engine: Connection refused
build-server-1  |   errorCode: null
build-server-1  |   clientVersion: 2.4.0
PrismaClientInitializationError:
  message: Failed to start the query engine: Connection refused
  errorCode: null
  clientVersion: 2.4.5
#0      BinaryEngine._createProcess (package:orm/src/engine_core/binary/binary_engine_io.dart:441:7)
<asynchronous suspension>
#1      BinaryEngine.start (package:orm/src/engine_core/binary/binary_engine_io.dart:333:17)
<asynchronous suspension>
#2      BinaryEngine.request (package:orm/src/engine_core/binary/binary_engine_io.dart:290:5)
<asynchronous suspension>
#3      ModelDelegate.findMany (package:package_name/prisma_client.dart:55755:42)
<asynchronous suspension>
...

Same error here. The database is PlanetScale, so I don't have any Docker compose file to set up with SSL or other...
Running the Dart Server locally I have no problems, but in staging/production gives me that error (the connection strings are the same).

@medz Anything to suggest?

@medz
Copy link
Owner

medz commented Mar 2, 2023

@medz medz closed this as completed Mar 2, 2023
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

3 participants