Im in the process of integrating pants, and was w...
# general
c
Im in the process of integrating pants, and was wondering if the docker integration only works with pex files. Is it also possible to setup the entire sandbox as when I would run one of my projects:main.py using pants and then copy it into my docker image
e
What I've been doing is to just create a pex with that main.py as an entrypoint, and then copying that into the docker image and it ought to pick up everything you need
Does that process leave you missing something that you are looking for?
c
I have been able to do that somewhat succesfully. Besides that my application need an entrypoint using an uwsgi command (that I havent solved yet). I was wondering why the Pex files are used, and in the case of python if it would be possible to just copy the source code with all its dependencies in. This process would let me keep my current Dockerfiles as is.
e
You would need to declare in the
docker_image()
target the
dependencies
field and mention every file, so that the docker context contains them. I've found that this does not work very well since you can't use globs in the
dependencies
field. I know for a FastAPI app, I just wrote a tiny entrypoint file that does
Copy code
if __name__=="__main__":
    import uvicorn
    uvicorn.run(app)
Is there something similar that you can do for your app? (I have also seen examples using `PEX_SCRIPT=<some shell command>`but don't have any personal experience with this)
c
Thanks Luke, yes I also think that copying everything manually seems a bit counterintuitive since pants makes us the sandboxes. I was looking into the pex_scripts in the meantime aswell. I'll give your unicorn approach a try aswell. 🙂
e
Good luck!
h
You can do the source copying. If your docker_image() depends on your
main.py
and that transitively depends on everything it needs (by inference from `import`s) then it should work
you shouldn’t need to mention every file
pex is useful because then your Dockerfile can just copy that single file into the shared underlying base image
rather than the Dockerfile having to know which files to copy