GithubHelp home page GithubHelp logo

Comments (13)

medz avatar medz commented on May 29, 2024 1

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.

from prisma-dart.

medz avatar medz commented on May 29, 2024

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

from prisma-dart.

jakub-stefaniak avatar jakub-stefaniak commented on May 29, 2024

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"]

from prisma-dart.

jakub-stefaniak avatar jakub-stefaniak commented on May 29, 2024

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

from prisma-dart.

medz avatar medz commented on May 29, 2024

@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.

from prisma-dart.

medz avatar medz commented on May 29, 2024

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.

from prisma-dart.

medz avatar medz commented on May 29, 2024

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

from prisma-dart.

medz avatar medz commented on May 29, 2024

Maybe it's really about SSL https://github.com/dart-lang/dart-docker/blob/main/Dockerfile-debian.template#L36

from prisma-dart.

medz avatar medz commented on May 29, 2024

@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

from prisma-dart.

medz avatar medz commented on May 29, 2024

image

from prisma-dart.

medz avatar medz commented on May 29, 2024

@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.

from prisma-dart.

AndryHTC avatar AndryHTC commented on May 29, 2024

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?

from prisma-dart.

medz avatar medz commented on May 29, 2024

@jakub-stefaniak https://github.com/odroe/prisma-dart/blob/main/example/simple/Dockerfile

from prisma-dart.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.