Hi all, I'm transitioning our codebase to Pants, a...
# general
r
Hi all, I'm transitioning our codebase to Pants, and have some
pex
related difficulties. First, on packaging our
pex
file to the docker image (for a different platform than I'm building with), and pushing it to Google Cloud, when it attempt to run I get
failed to load /workspace/protean-bin.pex: exec format error
. Searching around, I see that I need to either make it executable in my Dockerfile or add a shebang statement at the top. I've done both, but to no effect. Perhaps related, but when running the executable on my machine, it does run but errors out immediately saying it can't find
google.cloud.sql
, but the
cloud_sql_python_connector
is not there. I'm unsure why it isn't being pulled in to the
pex
file, Pants should understand that dependency by looking at the source code.
Perhaps the issue is that I'm specifying a platform when building docker as an extra argument, but not in my Pants
pex_binary
rule. I'll see if that helps.
Unfortunately, once I do that, I start having lots of issues with pants not being able to infer dependencies that it used to be able to infer. Very weird.
To close this out, evidently the dependency issues just sometimes show up as warnings as sometimes don't, it seems somewhat random. But unrelated.
And the issue with my
pex_binary
is because the way I was setting the platform was incorrect. I tried many different ways to do this with Pants, but eventually just put
--platform=linux/amd64
in my
FROM
statement in the Dockerfile.
h
Yeah, if you want to build a pex on platform A and run it on platform B (B != A) then you need to set a platform on the
pex_binary
, and you need the entire transitive closure of requirements to be available as wheels for platform B, since A can't built sdists into wheels for B
Not sure why that would affect dep inference though
Is it failing to infer deps on 3rdparty code, or on code in your repo?
r
Setting the platform wasn't enough, though. Or actually, setting the
complete_platform
wasn't enough, you have to set the
platform
too, somewhere. But, evidently, not in the
pex_binary
build rule, since it is deprecated there. These seem to do two different things,
complete_platform
makes sure the
pex
file is built with the right wheels, but doesn't change the Dockerfile compatibility itself (makes sense,
pex_binary
doesn't know anything about the Dockerfile).
It doesn't seem to actually have anything to do with dependency inference, that was just me not having the right mappings for requirements, and, confusingly, the warnings showing up sometimes, and then not showing up until something changes that I don't understand. So I thought I was affecting the dependency issue, but no, it was just only sometimes showing me the warnings.
h
Ah, gotcha
yeah, if inferred deps are resolved from the in-memory rule cache then you won't see the warnings, the code has to actually run for that
r
Thanks for the clarification, @happy-kitchen-89482!