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

BinaryNotFoundError When Running in Docker #835

Open
mdavish opened this issue Nov 5, 2023 · 5 comments
Open

BinaryNotFoundError When Running in Docker #835

mdavish opened this issue Nov 5, 2023 · 5 comments

Comments

@mdavish
Copy link

mdavish commented Nov 5, 2023

Bug description

I'm trying to use Python Prisma in Docker container, but when I try to initialize Prisma() I get a BinaryNotFoundError. It prompts me to run prisma py fetch to solve this, but that doesn't seem to download the binary correctly either.

How to reproduce

Using this Dockerfile:

FROM python:3.11

WORKDIR /app

RUN pip install pipenv

RUN pip install --no-cache-dir -U prisma


COPY ./prisma/schema.prisma ./

RUN python -m prisma generate

# This is currently not solving the problem...
RUN python -m prisma py fetch 

COPY ./python ./python

COPY ./python/Pipfile ./python/Pipfile.lock ./

RUN pipenv install --deploy --ignore-pipfile


ENV AUTONOMOUS_ROOT = "/app"
ENV PYTHONPATH "${PYTHONPATH}:/app/python"
ENV PATH="/home/prisma/.local/bin:${PATH}"

# It's possible we may need to set this manually.
# ENV PRISMA_QUERY_ENGINE_BINARY=...

CMD ["pipenv", "run", "python", "/app/python/scripts/test_prisma.py"]

... and this schema.prisma ...

generator tsClient {
  provider      = "prisma-client-js"
  output        = ".././node_modules/.prisma/client"
  binaryTargets = ["debian-openssl-1.1.x"]
}

generator pythonClient {
  provider             = "prisma-client-py"
  recursive_type_depth = 5
  interface            = "sync"
  output               = ".././python/prisma"
}

... the Docker Image builds successfully, I get this traceback when I run the container:

Traceback (most recent call last):
  File "/app/python/scripts/test_prisma.py", line 22, in <module>
    asyncio.run(main())
  File "/usr/local/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/app/python/scripts/test_prisma.py", line 11, in main
    await prisma.connect()
          ^^^^^^^^^^^^^^^^
  File "/app/python/prisma/client.py", line 301, in connect
    self.__engine.connect(
  File "/app/python/prisma/engine/query.py", line 135, in connect
    self.file = file = self._ensure_file()
                       ^^^^^^^^^^^^^^^^^^^
  File "/app/python/prisma/engine/query.py", line 123, in _ensure_file
    return utils.ensure(BINARY_PATHS.query_engine)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/python/prisma/engine/utils.py", line 117, in ensure
    raise errors.BinaryNotFoundError(
prisma.engine.errors.BinaryNotFoundError: Expected /app/prisma-query-engine-debian-openssl-3.0.x, /root/.cache/prisma-python/binaries/5.4.2/ac9d7041ed77bcc8a8dbd2ab6616b39013829574/prisma-query-engine-debian-openssl-3.0.x or /Users/mdavish/autonomous-commerce/node_modules/prisma/query-engine-darwin-arm64 to exist but none were found or could not be executed.
Try running prisma py fetch

However, even adding prisma py fetch to the Dockerfile doesn't solve the problem.

Expected behavior

I am expecting the Prisma binary to be installed under /root/.cache/prisma-python/binaries/5.4.2/ac9d7041ed77bcc8a8dbd2ab6616b39013829574/prisma-query-engine-debian-openssl-3.0.x but when I go into the container's shell, I'm not able to find it at that path, and running prisma py fetch does not seem to put it there.

Prisma information

See above for Prisma schema

Environment & setup

  • All of the above works on my local machine (Mac OS), but not in Docker
  • Postgres database
  • Prisma version 5.4.2
  • Prisma Client Python version 0.11
  • Python 3.11
@abbazs
Copy link

abbazs commented Nov 7, 2023

Set the PATH ENV to look at /root/.local/bin/:${PATH} instead of /home/prisma/.local/bin:${PATH} shall work.

@mdavish
Copy link
Author

mdavish commented Nov 8, 2023

Hey thanks @abbazs but sadly that didn't work either. Still getting the same error. Any other ideas? Do you have any examples of a working Docker image?

@wengcan
Copy link

wengcan commented Dec 12, 2023

set this environment variable before run prisma generate

RUN PRISMA_BINARY_CACHE_DIR=/.binaries prisma generate

@jos-bek
Copy link

jos-bek commented Apr 16, 2024

Hey @mdavish,
could you find any solution? I have the same issue. I also tried this:

RUN PRISMA_BINARY_CACHE_DIR=/.binaries prisma generate

It seems to me that it generally does not load the binary target regardless of the specified binary path.
Can it be possible to generate the missing query engine with "prisma-client-js" as provider?

@prabir-vora
Copy link

Facing the same issue. Could anyone find a solution to this?

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

5 participants