Hello, I am new to pants and trying to monorepo my...
# general
m
Hello, I am new to pants and trying to monorepo my backend services built using FastAPI. But FastAPI internally required Pydantic. And resolving this dependency has been an issue for me for the past 1 week. it runs on my mac, but when I create a docker_image and then run the code it gives the following error:
Copy code
No interpreter compatible with the requested constraints was found:

  A distribution for pydantic could not be resolved for /usr/local/bin/python3.8.
  Found 1 distribution for pydantic that do not apply:
  1.) The wheel tags for pydantic 1.9.1 are cp38-cp38-macosx_10_9_x86_64 which do not match the supported tags of /usr/local/bin/python3.8:
  cp38-cp38-manylinux_2_31_aarch64
w
Could you show your relevant BUILD file or a snippet of your Dockerfile? I haven't used the docker capabilities of Pants too much, but just reading that message, it sounds like you might be trying to pull in the macos version of pydantic in a linux docker base image. This post (from yesterday) might be of interest as well: https://blog.pantsbuild.org/optimizing-python-docker-deploys-using-pants/
h
+1 on BUILD file being useful. I wonder if you want to be setting either
platforms
or
complete_platforms
on the
pex_binary
https://www.pantsbuild.org/docs/reference-pex_binary#codeplatformscode
m
Here is the build file. The issue arises only if I use pydantic (which is required by FastAPI as dependency)
Copy code
python_sources(name="hello_world")

pex_binary(
    name="main",
    entry_point="main.py",
    dependencies=[
        ':reqs#pydantic'
    ]
)


docker_image(
    name="image",
    instructions=[
        'FROM python:3.8',
        'ENTRYPOINT ["/bin/main.pex"]',
        'COPY service.cms/main.pex /bin'

    ],
    dependencies=[
        "src/python/hello_world:main"
    ]
)
h
Okay I think what is happening is that for now, Pants creates the binary on your mac beforehand and then copies it into the container. It does not create it in the container (although that is highly requested and we want to do it) So, the binary is being built w/ macOS deps, and failing to run in Linux. The solution is to use
platforms
or
complete_platforms
1
w
It does not create it in the container
Ah, right right - I use FastApi as well, and it just hit me that I provision everything in a Linux container myself. Something similar to this problem was why I did it
h
Opened https://github.com/pantsbuild/pants/issues/16393 to track this "docs bug"
👍 1
f
Kinda related: is there an overarching issue related to "perform build steps in container" functionality?
h
yeah, one of our most requested features: https://github.com/pantsbuild/pants/issues/13682
🙏🏻 1
🙏 1
w
I've had success with creating a Dockerfile.build file which downloads/installs pants and runs on a mounted volume with my source as a workaround
h
We really should prevent you from building platform-specific pexes on a mac and embedding them in a docker image, this is a huge gotcha
5
m
Thanks, this really helped me overcome this issue. I wasted almost a week on such a trivial issue because I never knew of
platform
pex field. Thanks again
h
Oof, sorry Harsh ❤️ I'm glad you reached out. We definitely don't want folks spending that much time confused