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

Deploying prisma made dart app to dockers #117

Closed
syedzainqadri opened this issue Feb 10, 2023 · 13 comments
Closed

Deploying prisma made dart app to dockers #117

syedzainqadri opened this issue Feb 10, 2023 · 13 comments
Labels
bug Something isn't working duplicate This issue or pull request already exists

Comments

@syedzainqadri
Copy link

syedzainqadri commented Feb 10, 2023

This is my Docker file i am trying to build my fine working app to a docker container

FROM dart:stable as builder
COPY . /dart_server
WORKDIR /dart_server
COPY pubspec.* ./
RUN dart pub get
RUN mkdir build
RUN dart compile exe ./bin/server.dart -o ./build/server
FROM debian:buster-slim
COPY --from=builder /dart_server/build /bin
COPY --from=builder /runtime/ /
CMD [ "server" ]

but when i run and try to hit api, i get this response.

[ERROR] 2023-02-10 07:27:27.628250      0:00:00.081866  POST    /auth/register
PrismaClientInitializationError:
  message: Could not find query engine binary for current platform "linux" in query-engine path.

This probably happens, because you built Prisma Client on a different platform.

Searched Locations:
  - /
  - /dart_server/.dart_tool/prisma

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.

Please create an issue at https://github.com/odroe/prisma-dart/issues/new
  errorCode: null
  clientVersion: 2.4.5

package:shelf/src/middleware/logger.dart 30  logRequests.<fn>.<fn>.<fn>

where as i have set the generator block to debain as mentioned in documentation over prisma official documentations.

generator client {
  provider        = "prisma-client-dart"
  binaryTargets = ["debian-openssl-1.1.x"]
}

Can you guide me how can i build it for docker container

@medz
Copy link
Owner

medz commented Feb 10, 2023

@syedzainqadri
Copy link
Author

syedzainqadri commented Feb 11, 2023

After adding the line you mentioned i have this as my current dockerfile.

FROM dart:stable as builder

# Set the working directory
WORKDIR /dart_server

RUN mkdir build

# Copy dart project files and install dependencies
COPY . .
RUN dart pub get

# Delete prisma configurator
RUN rm -rf lib/prisma_configurator.dart

# Precache query engine
ENV PRISMA_QUERY_ENGINE_BINARY=/dart_server/query-engine
RUN dart run orm precache --type=query

# Generate Prisma client
RUN dart run orm generate
RUN dart run build_runner build --delete-conflicting-outputs

# Build simple app execable
RUN dart compile exe bin/server.dart -o ./build/server

# Build a small image
FROM scratch

# Copy dart runtime
COPY --from=builder /runtime/ /
COPY --from=builder /dart_server/build /bin
COPY --from=builder /dart_server/query-engine ./build/query-engine

CMD ["server"]

but unfortunately i am getting the same response.

guide me further on this.
At this stage this is my generator block.

generator client {
  provider        = "prisma-client-dart"
}

and this is the error i am getting when hitting the api.

{email: usernew@user.com, password: 1234567}
[ERROR] 2023-02-11 08:00:24.863876      0:00:00.130999  POST    /auth/register
PrismaClientInitializationError:
  message: Could not find query engine binary for current platform "linux" in query-engine path.

This probably happens, because you built Prisma Client on a different platform.

Searched Locations:
  - /
  - /dart_server

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.

Please create an issue at https://github.com/odroe/prisma-dart/issues/new
  errorCode: null
  clientVersion: 2.4.5

package:shelf/src/middleware/logger.dart 30  logRequests.<fn>.<fn>.<fn>

ERROR - 2023-02-11 08:00:24.999121
POST /auth/register
Error thrown by handler.
PrismaClientInitializationError:
  message: Could not find query engine binary for current platform "linux" in query-engine path.

This probably happens, because you built Prisma Client on a different platform.

Searched Locations:
  - /
  - /dart_server

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.

Please create an issue at https://github.com/odroe/prisma-dart/issues/new
  errorCode: null
  clientVersion: 2.4.5

package:shelf/src/middleware/logger.dart 30  logRequests.<fn>.<fn>.<fn>

This is my server repo the current branch is version1.0.3
https://github.com/syedzainqadri/dart_server_shelf/tree/version1.0.3

@medz medz added the bug Something isn't working label Feb 11, 2023
@medz
Copy link
Owner

medz commented Feb 11, 2023

This is a bug where the Prisma query engine downloads the wrong binary engine under Linux.

@syedzainqadri
Copy link
Author

Now i am getting the connection to db error where it is working fine on local host

ERROR - 2023-02-11 20:43:24.288880
POST /auth/register
Error thrown by handler.
PrismaClientInitializationError:
message: Failed to start the query engine: Connection refused
errorCode: null
clientVersion: 2.4.5

package:shelf/src/middleware/logger.dart 30 logRequests...
any suggestion

@medz
Copy link
Owner

medz commented Feb 12, 2023

Now i am getting the connection to db error where it is working fine on local host

ERROR - 2023-02-11 20:43:24.288880 POST /auth/register Error thrown by handler. PrismaClientInitializationError: message: Failed to start the query engine: Connection refused errorCode: null clientVersion: 2.4.5

package:shelf/src/middleware/logger.dart 30 logRequests... any suggestion

repeat #74

@medz medz added the duplicate This issue or pull request already exists label Feb 12, 2023
@syedzainqadri
Copy link
Author

This seems to be a different issue than the one in #74 because in that case you can run the manual commands after running the application to build up a db connection where as this is a production environment and the application is dockerized now what could be the solution.

@medz
Copy link
Owner

medz commented Feb 12, 2023

I'm constructing new versions that allow running the query engine independently to solve this problem. Because setting up ssl and downloading the correct query engine in a blank container is a complicated thing. Small differences can lead to failure.

@medz
Copy link
Owner

medz commented Feb 12, 2023

https://github.com/odroe/prisma-dart/blob/main/lib/universal_engine.dart The universal engine allows connecting to independent query engines.

@syedzainqadri
Copy link
Author

Now what do u suggest me to do should i copy the file and add in my code or what steps should i take to make my code run can you please guide on that cause there are two servers we have developed using this package and both are now ready to go for a production test.

So kindly if you can guide me with the steps i need to take in order to send them to production.

@syedzainqadri
Copy link
Author

Now what do u suggest me to do should i copy the file and add in my code or what steps should i take to make my code run can you please guide on that cause there are two servers we have developed using this package and both are now ready to go for a production test.

So kindly if you can guide me with the steps i need to take in order to send them to production.

Because if i try to run the latest version which has the file you just shown it gets stuck on the build_runner and just keeps it self hung after doing half the tasks

@medz
Copy link
Owner

medz commented Feb 13, 2023

@syedzainqadri Can you bear to use the base image of ubuntu or other distribution system? A temporary workaround is to install Dart manually and then in a stripped-down image of the distro system can solve this problem.

I'm looking for ways to support both Dart and Prisma binary engines in scratch.

@syedzainqadri
Copy link
Author

Well i am able to run it as a fat image and deployed it as it is for now. Lets wait for your update to sort things out in scratch.

@medz
Copy link
Owner

medz commented Mar 1, 2023

@syedzainqadri I have solved this problem! This dockerfile is for your reference. https://github.com/odroe/prisma-dart/blob/main/example/simple/Dockerfile

@medz medz closed this as completed Mar 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working duplicate This issue or pull request already exists
Projects
None yet
Development

No branches or pull requests

2 participants