https://pantsbuild.org/ logo
#general
Title
# general
a

ancient-rose-27306

08/25/2022, 8:19 PM
Hi guys, I am building a
pex_binary()
with following definition:
pex_binary(
name="greeter_server",
entry_point="greeter_server.py:main",
)
It builds fine and I am able to use it on my local machine. Moving a step ahead, I am building a
docker_image()
with this pex:
docker_image(
name="docker-server",
dependencies=[":greeter_server"],
)
and the contents of Dockerfile are:
Copy code
FROM python:3.7
RUN mkdir /app
WORKDIR /app
COPY src.server/greeter_server.pex /app/
EXPOSE 50051
CMD ["/app/greeter_server.pex"]
The Docker build works fine too but when I do
docker run -it docker-server
, I end up in an error and the pex doesn’t execute:
Copy code
(pants) [root@9a5752857756 pants-training]# docker run -it docker-server
Failed to find compatible interpreter on path /usr/local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin.

Examined the following interpreters:
1.) /usr/local/bin/python3.7 CPython==3.7.13
2.)       /usr/bin/python3.9 CPython==3.9.2

No interpreter compatible with the requested constraints was found:

  A distribution for grpcio could not be resolved for /usr/local/bin/python3.7.
  Found 1 distribution for grpcio that do not apply:
  1.) The wheel tags for grpcio 1.47.0 are cp37-cp37m-macosx_10_10_x86_64 which do not match the supported tags of /usr/local/bin/python3.7:
  cp37-cp37m-manylinux_2_31_x86_64
  ... 535 more ...
(pants) [root@9a5752857756 pants-training]#
I could provide the
platforms
arg for
pex_binary()
target but want to understand the reason that pex was working directly but not inside a container on the same machine. Could you please help?
h

hundreds-father-404

08/25/2022, 8:21 PM
Hi, this is actually a major feature we at Toolchain decided to work on this week: https://github.com/pantsbuild/pants/issues/13682 🎉 Indeed, the current Docker integration is that the PEX gets built locally, and then Pants copies that file over to the Docker container In the meantime to #13682, the solution is to use
platforms
a

ancient-rose-27306

08/25/2022, 8:23 PM
Ok, so
platforms=['current']
would accomplish what I am trying to do?
h

hundreds-father-404

08/25/2022, 8:23 PM
no, because `current `means macOS when you're running on macOS. You'll want a Linux value like
linux_x86_64-cp-37-cp37m
a

ancient-rose-27306

08/25/2022, 8:24 PM
Ok, because it is running inside a container?
h

hundreds-father-404

08/25/2022, 8:31 PM
No, nothing currently is ever run in the container. The build happens on your local machine.
platforms
allows Pex/pip to be build for foreign platforms. So even though you're building on your mac, you can build it to work with Linux
a

ancient-rose-27306

08/25/2022, 8:33 PM
I meant when I build it into a Docker image and when I build a container from that image, that container has “linux” environment and the pex is running inside that container. Using the environment you suggested actually made it work.
h

hundreds-father-404

08/25/2022, 8:35 PM
I don't think I totally follow. Maybe this helps? • Pants builds the PEX on your local machine (mac). But it can be set to be Linux compatible via
platforms
• Pants copies that PEX into the Docker image, which will be Linux because it's Docker • When you run that Docker image, it will thus be Linux and will need a Linux-compatible Pex
a

ancient-rose-27306

08/25/2022, 8:36 PM
Yeah, that’s what I meant. Sorry I was not able to make it clear. I know
package
goal doesn’t run inside a container.