Hi all :wave: I can't find a way to package my pex...
# general
w
Hi all đź‘‹ I can't find a way to package my pex binary in a docker image. My idea was to use the same base image both in the environment for building the pex file and in my Dockerfile, so it would be isolated from the host running pants (could be Mac for instance). Here's an example :
Copy code
python_source(
    name="src",
    source="__main__.py",
)

pex_binary(
    name="pex",
    dependencies=[
        ":src",
    ],
    entry_point="__main__.py",
    environment="docker_x86_64",
)

docker_image(
    name="docker",
    repository="test",
    image_tags=["latest"],
    source="Dockerfile",
)
which gives me the following error :
Copy code
native_engine.IntrinsicError: Failed to make named cache(s) for local execution: "Failed to create parent directory for named cache in Docker container:
stdout:

stderr:
mkdir: cannot create directory '/pants-named-caches/pex_root': Permission denied
I can't really figure out how to overcome this, or if it's simply not a valid usecase. Has anyone else tried this ?
w
I thought we were able to use Docker as a build environment, as well as runtime containers - but I haven’t been too much into that side of the equation recently. However, is there an underlying problem just building the pex for Linux and copying it over in your docker build? That’s what I do right now
b
That error sounds like it's something specific to the permissions that container that's stopping pants from creating the directories needed for caching, when using a docker container as a build environment. Does that base container lock down permissions?
w
no it doesn’t, I just tried and created this folder myself. I also tried to set up PEX_ROOT to specify a different path, which does not change this error message. Decomposing the two operations, building the pex binary in the docker environment works. The error occurs when running
pants package
on the docker_file target.
However, is there an underlying problem just building the pex for Linux and copying it over in your docker build? That’s what I do right now
This approach would not work for me, some of the dependencies have no built wheels available
j
I know this is a older thread but were you ever able to find a solution to the permissions issue you ran into? I'm trying this same use case and was wondering if you found a way past it.
n
I too would be interested in a solution if you found one @white-jordan-40851. I opened https://github.com/pantsbuild/pants/issues/22577