reflex icon indicating copy to clipboard operation
reflex copied to clipboard

Bun not found when using Docker

Open HellAmbro opened this issue 2 years ago β€’ 5 comments

Describe the bug I was trying to run an app with docker but i got this error

──────────────────────────── Starting Pynecone App ─────────────────────────────
───────────────────────── Installing frontend packages ─────────────────────────
Traceback (most recent call last):
  File "/app/venv/bin/pc", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/app/venv/lib/python3.11/site-packages/typer/main.py", line 214, in __call__
    return get_command(self)(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
    return self.main(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.11/site-packages/click/core.py", line 1055, in main
    rv = self.invoke(ctx)
         ^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.11/site-packages/click/core.py", line 1657, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
    return ctx.invoke(self.callback, **ctx.params)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.11/site-packages/click/core.py", line 760, in invoke
    return __callback(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.11/site-packages/typer/main.py", line 532, in wrapper
    return callback(**use_params)  # type: ignore
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/app/venv/lib/python3.11/site-packages/pynecone/pc.py", line 131, in run
    frontend_cmd(app.app, Path.cwd(), frontend_port)
  File "/app/venv/lib/python3.11/site-packages/pynecone/utils/exec.py", line 78, in run_frontend_prod
    setup_frontend(root)
  File "/app/venv/lib/python3.11/site-packages/pynecone/utils/build.py", line 133, in setup_frontend
    prerequisites.install_frontend_packages(web_dir)
  File "/app/venv/lib/python3.11/site-packages/pynecone/utils/prerequisites.py", line 269, in install_frontend_packages
    subprocess.run(
  File "/usr/local/lib/python3.11/subprocess.py", line 548, in run
    with Popen(*popenargs, **kwargs) as process:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/subprocess.py", line 1024, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "/usr/local/lib/python3.11/subprocess.py", line 1917, in _execute_child
    raise child_exception_type(errno_num, err_msg, err_filename)
FileNotFoundError: [Errno 2] No such file or directory: '/home/pynecone/.bun/bin/bun'

To Reproduce I'm using the same Dockerfile in the example folder pcconfig.py bun_path="/app/.bun/bin/bun",

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

** Specifics (please complete the following information):**

  • Python Version:
  • Pynecone Version:
  • OS:
  • Browser (Optional):

Additional context Add any other context about the problem here.

HellAmbro avatar May 16 '23 17:05 HellAmbro

Are you using the docker image we provide or your own?

Alek99 avatar May 16 '23 22:05 Alek99

Are you using the docker image we provide or your own?

My own. I'm trying to deploy a pynecone app with Docker but i got that error.

HellAmbro avatar May 18 '23 11:05 HellAmbro

Are you using the docker image we provide or your own?

My own. I'm trying to deploy a pynecone app with Docker but i got that error.

can you share what your docker file looks like?

ElijahAhianyo avatar May 18 '23 15:05 ElijahAhianyo

Give this Dockerfile a shot

FROM python:3.11-slim as base
RUN adduser --disabled-password pynecone

FROM base as build
RUN mkdir /app && chown pynecone:pynecone /app
USER pynecone
WORKDIR /app
ENV VIRTUAL_ENV=/app/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
COPY . .
RUN pip install wheel \
  && pip install -r requirements.txt

FROM base as runtime
RUN apt-get update && apt-get install -y \
  curl \
  && curl -fsSL https://deb.nodesource.com/setup_19.x | bash - \
  && apt-get update && apt-get install -y \
  nodejs \
  unzip \
  && rm -rf /var/lib/apt/lists/*
ENV PATH="/app/venv/bin:$PATH"

FROM runtime as init
USER pynecone
WORKDIR /app
COPY --chown=pynecone --from=build /app/ /app/
RUN pc init

FROM runtime
COPY --chown=pynecone --from=init /app/ /app/
COPY --chown=pynecone --from=init /home/pynecone/.bun/ /home/pynecone/.bun/
USER pynecone
WORKDIR /app

CMD ["pc", "run", "--env", "prod", "--loglevel", "info"]

EXPOSE 3000
EXPOSE 8000

If you don't want to set the bun_path="/app/.bun/bin/bun", setting in your pcconfig.py file like myself (Makes development clunky to switch it back and forth), the Dockerfile in the example in the repo won't work. This will let Bun install itself to the default ~/.bun/ of the user that is running pc init and things are working for me now.

jdoss avatar May 22 '23 06:05 jdoss

Recently,I had the same issue. The resean why bun not found is installation failure of bun when pc run which auto trigger curl -fsSL https://bun.sh/install | bash. There will be no installation failure info.

The approach that Pynecone auto download and install bun remotely is not so suitable, instead, just ask for it as a runtime component, same as Pynecone needs Python but not install python automatically.

What I did is explicitly install bun before pc run, put command curl -fSL https://bun.sh/install | bash -x just next to nodejs is a good option. By this way, u can see the installation process.

evandeng2009 avatar Jun 28 '23 01:06 evandeng2009