Hey guys, I'm trying to build a docker container w...
# general
p
Hey guys, I'm trying to build a docker container without pex, but still using the pants dependancy resolution for 3rd party and local packages, how can I do this?
e
Could you tell more about your goal? How do you want the dependency resolution to affect your docker image?
p
I have a single python file as the entrypoint (which cant be from inside a pex) , I want it to be copied over along with all of the local source code it depends on (as determined by pants) along with a list of all 3rd party dependacies (for example in a requirements.txt or similar) which can be copied over and installed in the docker image build.
e
Is the issue just that you need to have raw files in your image? You may be interested in
pex_binary(layout="loose")
which will generate the pex as a directory full of files.
single python file as the entrypoint (which cant be from inside a pex)
Why can't it be inside a pex? It seems like almost exactly what you want is
pex_binary(entry_point="entrypoint.py")
which will create a pex with that file, all the local source code it depends on, and all the 3rd party dependencies it needs. You can use
execution_mode="venv"
to make pex install a venv from the 3rd party dependencies on first run, if you need the 3rd party deps available separately.
p
Thank you so much for your help Luke. Sorry I misspoke, the entrypoint for my application is a command line invocation like this:
Copy code
CMD [ "marimo", "run", "app.py", "--host", "0.0.0.0", "-p", "8080" ]
Essentailly its spinning up a web server to host an app, I don't know if it is possible/ how to do this within a pex
Perhaps there is another way of doing this forgive my ignorance
image.png
e
I had something similar with a
fastapi
app before. Normally run (as a shell command) with
CMD [ "fastapi", "dev", "main.py" ]
, I was able to run it as a python command like
uvicorn.run(app, host=host, port=port)
, put this in a python script, and then my entrypoint was standard python code, so it worked with pex. I'm not familiar with
marimo
, but perhaps it supports something similar? If it does not, you may be able to use PEX options to configure either the build process or the install process (into the dockerfile) to give you a standard-looking venv so you can do something like
Copy code
CMD [ "path/to/venv/bin/marimo", "run", "app.py", "--host", "0.0.0.0", "-p", "8080" ]
❤️ 1
p
Yes this is what I'm coming to realise there will be a way to invoke the server from within a python file I'm sure!
👍 1
Thank you so much for your help Luke
e
No problem! For those curious, you could get at the original ask by doing something like
pants dependencies --transitive /path/to/my/entrypoint | grep src/
to find first party sources and
pants dependencies --transitive /path/to/my/entrypoint | grep 3rdparty/
to find 3rd party requirements (depending on how your repo is organized), but I think that will get painful pretty quickly.
p
Yeah I started implementing a hacky solution like this in a script, but it felt like I was defeating the point of using pants as a build system in the first place 😁