Hello! I'm a pants n00b and am struggling to build...
# general
m
Hello! I'm a pants n00b and am struggling to build an amd64 docker image on an ARM Mac. I've attempted follow the steps here to generate the markers and tags from within the amd64 container, but I can't seem to get the interpreter tags to be
x86_64
instead of
aarch64
.
Copy code
Failed to find compatible interpreter on path /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin.

Examined the following interpreters:
1.) /usr/bin/python3.10 CPython==3.10.12
2.) /usr/bin/python3.11 CPython==3.11.9

No interpreter compatible with the requested constraints was found:

  A distribution for pendulum could not be resolved for /usr/bin/python3.11.
  Found 1 distribution for pendulum that do not apply:
  1.) The wheel tags for pendulum 2.1.2 are cp311-cp311-manylinux_2_35_x86_64 which do not match the supported tags of /usr/bin/python3.11:
  cp311-cp311-manylinux_2_35_aarch64
BUILD:
Copy code
python_sources()

pex_binary(
    name = 'hello_world',
    entry_point="hello_world.py",
    dependencies = [
        "//:root#pendulum",
    ],
    environment="linux",
    complete_platforms=["//:linux_x86_py311"],
)
root BUILD:
Copy code
docker_environment(
  name="linux",
  platform="linux_x86_64",
  image="<http://X.dkr.ecr.us-east-1.amazonaws.com/image:tag|X.dkr.ecr.us-east-1.amazonaws.com/image:tag>"
)

file(
  name="linux_x86_py311",
  source="linux.json",
)
linux.json is large. I've attempted to remove everything but the tag I want, but that leads to a
division by zero
error. Help me Obi-Wan :p
b
Sorry for the trouble! Can you share the exact command you used to generate the json file?
m
Copy code
docker run -it --platform linux/amd64 <http://X.dkr.ecr.us-east-1.amazonaws.com/image:tag|X.dkr.ecr.us-east-1.amazonaws.com/image:tag> /bin/bash -c 'pip install pex; pex3 interpreter inspect --markers --tags' > linux.json
b
Seems reasonable! Hmmm… What command are you running that sees the error? What platform are you running it on?
b
Sort of unrelated, but I am curious to know, @many-waiter-76097 why are you using
docker_environment
target? What purpose does it serve?
m
Hi Mohit. I'm aiming to build a linux_x86_64 image, but building on an aarch64 Mac. My (admittedly limited) understanding is that
docker_environment
causes pants to build the project in the specified image?
Huon, I'm running on an ARM Mac. The command:
pants run project/path:name
b
Robert , thanks for sharing your approach. I also tried with your approach and was able to run my code. My usecase is also similar, I am on macos, but want to build images specific to linux/amd64. However I made few changes. I added
docker_environment
name in my
pants.toml
file under the section:
Copy code
[environments-preview.name]
linux="//:linux"
then I use this name in
pex_binary(environment="linux", ...)
. with this I also didn't need to mention
complete_platforms
. I used the same options for
docker_environment
as yours. This worked on my local, but it failed in CI. In CI, I got the following error:
Copy code
ProcessExecutionFailure: Process 'Extract environment variables from the Docker image python:3.11.9-slim' failed with exit code 126.
| stdout:
| OCI runtime exec failed: exec failed: unable to start container process: chdir to cwd ("/pants-sandbox/pants-sandbox-NA71HL") set in config.json failed: no such file or directory: unknown
(Reference: https://www.pantsbuild.org/2.19/docs/using-pants/environments)
👀 1
p
I think I tracked down the issue. Somewhere in the docker defaults, it was deciding that it wanted to use linux/aarch64 as the platform when building containers, but when pants was building PEXes it was building them for x86_64/amd64. Setting a default build_platform=["linux/amd64"] seems to have fixed this. Tracking this down was a bit complicated by the fact that there is something wrong with the pants/docker cache here and trying to use the
FROM --platform=linux/amd64
syntax in Dockerfiles was not working unless I used --no-pants-cache to kick it in the pants.
👀 1