this has gotta be some small platform-specific set...
# general
s
this has gotta be some small platform-specific setting / install that I'm missing but I haven't been able to find anything in the docs or online. when I attempt to build a docker image using the
docker_image
target and a simple Dockerfile on a MAC M1, it looks like the
dockerfile
module used by pants in my setup was compiled for
x86_64
but I need the
arm64
one. this feels like it might have something to do with this blurb on Mac interpreters. but changing the
interpreter_search_paths
property doesn't seem to have any affect, I suspect because that is probably referring to setting the python interpreter for the python backend tools and doesn't affect the docker backend tools. how do I get pants to create and use the
arm64
dockerfile module? here's the actual error:
Copy code
Traceback (most recent call last):
  File "/private/var/folders/0k/c0crrpz142n_h62r7nnmpnsr0000gn/T/pants-sandbox-IbPeOY/.cache/pex_root/venvs/3d84392e96bb69d7972ace4055cb0144a30b9e8e/a58c33d44cdb8a7bd8160aa976f1a158437bee6a/pex", line 243, in <module>
    runpy.run_module(module_name, run_name="__main__", alter_sys=True)
  File "/Users/zach/.pyenv/versions/3.7.16/lib/python3.7/runpy.py", line 205, in run_module
    return _run_module_code(code, init_globals, run_name, mod_spec)
  File "/Users/zach/.pyenv/versions/3.7.16/lib/python3.7/runpy.py", line 96, in _run_module_code
    mod_name, mod_spec, pkg_name, script_name)
  File "/Users/zach/.pyenv/versions/3.7.16/lib/python3.7/runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "/Users/zach/.cache/pants/named_caches/pex_root/venvs/s/b9c7c433/venv/lib/python3.7/site-packages/__pants_df_parser.py", line 202, in <module>
    print(json.dumps([asdict(info) for info in main(*sys.argv[1:])]))
  File "/Users/zach/.cache/pants/named_caches/pex_root/venvs/s/b9c7c433/venv/lib/python3.7/site-packages/__pants_df_parser.py", line 202, in <listcomp>
    print(json.dumps([asdict(info) for info in main(*sys.argv[1:])]))
  File "/Users/zach/.cache/pants/named_caches/pex_root/venvs/s/b9c7c433/venv/lib/python3.7/site-packages/__pants_df_parser.py", line 61, in main
    from dockerfile import Command, parse_file, parse_string  # pants: no-infer-dep
ImportError: dlopen(/Users/zach/.cache/pants/named_caches/pex_root/venvs/s/b9c7c433/venv/lib/python3.7/site-packages/dockerfile.abi3.so, 0x0002): tried: '/Users/zach/.cache/pants/named_caches/pex_root/venvs/s/b9c7c433/venv/lib/python3.7/site-packages/dockerfile.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/zach/.cache/pants/named_caches/pex_root/venvs/s/b9c7c433/venv/lib/python3.7/site-packages/dockerfile.abi3.so' (no such file), '/Users/zach/.cache/pants/named_caches/pex_root/venvs/s/b9c7c433/venv/lib/python3.7/site-packages/dockerfile.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/Users/zach/.cache/pants/named_caches/pex_root/venvs/3d84392e96bb69d7972ace4055cb0144a30b9e8e/a58c33d44cdb8a7bd8160aa976f1a158437bee6a/lib/python3.7/site-packages/dockerfile.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64')), '/System/Volumes/Preboot/Cryptexes/OS/Users/zach/.cache/pants/named_caches/pex_root/venvs/3d84392e96bb69d7972ace4055cb0144a30b9e8e/a58c33d44cdb8a7bd8160aa976f1a158437bee6a/lib/python3.7/site-packages/dockerfile.abi3.so' (no such file), '/Users/zach/.cache/pants/named_caches/pex_root/venvs/3d84392e96bb69d7972ace4055cb0144a30b9e8e/a58c33d44cdb8a7bd8160aa976f1a158437bee6a/lib/python3.7/site-packages/dockerfile.abi3.so' (mach-o file, but is an incompatible architecture (have 'x86_64', need 'arm64'))
I should note that the docker image doesn't currently have any dependencies on anything else in my repo, I'm just trying to build a simple python container with java to test out the
docker_image
target
it seems like I need to indicate what interpreter pants uses for
docker_image
, or maybe the platform it's building on, but I don't see any options to do so. I found the
docker_environment
target, but that seems to be more for building pex bins in a docker image
r
One way to build a docker image for a particular platform arch is using
platform
arg inside your dockerfile. https://docs.docker.com/build/building/multi-platform/ You can pass it as a build arg using
extra_build_args
as mentioned here https://www.pantsbuild.org/docs/reference-docker_image#codeextra_build_argscode
s
so I had tried using a platform-specific build with the platform arg hardcoded in my dockerfile and I got the same error. I can actually build the image just fine without pants just using raw docker and no platform arguments. from the error I'm getting it doesn't look like it's even getting into building the image, it seems to be failing to load the python files that are used to parse the dockerfile. it looks to me like pants is building a virtual environment with which to build the docker image but that the
dockerfile
module getting installed into that environment by pants doesn't work on arm64.
one thing I'm not quite understanding and feels off is that pants appears to be running in a python 3.7 venv, although I've been trying to run it from 3.9. maybe I set it up with 3.7..
r
do you use some kind of terminal emulator?
s
I've never set one up
r
How are you maintaining multiple versions of python? pyenv?
s
yeah pyenv
r
I had this issue when running pants from source but never otherwise. You might have to set-up this
search_path
as mentioned here https://www.pantsbuild.org/docs/python-backend
Copy code
search_path = ["<PYENV>"]
s
I've been trying it with
Copy code
[python-bootstrap]
search_path = [
  "<PYENV>"
]
and also
Copy code
[python-bootstrap]
search_path = [
  "<PYENV>",
  "/usr/local/bin"
]
and neither seem to help. i'm starting to go down this rabbithole - https://chat.pantsbuild.org/t/9728005/hey-i-m-having-some-python-architecture-issues-when-running-
r
but did you try to start from scratch? Like delete all the existing cache associated with pants?
s
I tried deleting everything at
/Users/zach/.cache/pants/...
yesterday (maybe that's not all the caches I need to delete) and it didn't fix anything, so I was going to try deleting those again and also re-bootstrapping pants (I haven't re-installed / re-bootstrapped pants yet)
alright I did some messing around with interpreter paths, deleting caches, removing older python versions from pyenv and now I think I'm actually getting into the very beginnings of the docker build phase, but am hitting another error that seems to indicate some additional environment config isn't getting passed through:
Copy code
Failed to fire hook: while creating logrus local file hook: user: Current requires cgo or $USER, $HOME set in environment
[2023-03-28T17:12:42.321711000Z][docker-credential-desktop][F] get system info: exec: "sw_vers": executable file not found in $PATH
[goroutine 1 [running, locked to thread]:
[common/pkg/system.init.0()
[       common/pkg/system/os_info.go:32 +0x1bc
#1 [internal] load build definition from Dockerfile
#1 sha256:032127a65a56b6218cb6a39f6c46a2bd1886f25ac038428bb1898700cc83690f
#1 transferring dockerfile: 527B done
#1 DONE 0.0s

#2 [internal] load .dockerignore
#2 sha256:3bfa667b48f39e2780fa18acbe3815dd6ab7742db5f9255a09791dbb232fd7d2
#2 transferring context: 2B done
#2 DONE 0.0s

#3 [internal] load metadata for <http://docker.io/library/python:3.9-slim|docker.io/library/python:3.9-slim>
#3 sha256:f8eb7dab72bf96d7bbead0e5af425ba155d110a0ad106da163686a19dc0c221c
Failed to fire hook: while creating logrus local file hook: user: Current requires cgo or $USER, $HOME set in environment
[2023-03-28T17:12:42.836587000Z][docker-credential-desktop][F] get system info: exec: "sw_vers": executable file not found in $PATH
[goroutine 1 [running, locked to thread]:
[common/pkg/system.init.0()
[       common/pkg/system/os_info.go:32 +0x1bc
Failed to fire hook: while creating logrus local file hook: user: Current requires cgo or $USER, $HOME set in environment
[2023-03-28T17:12:42.852891000Z][docker-credential-desktop][F] get system info: exec: "sw_vers": executable file not found in $PATH
[goroutine 1 [running, locked to thread]:
[common/pkg/system.init.0()
[       common/pkg/system/os_info.go:32 +0x1bc
#3 ERROR: rpc error: code = Unknown desc = error getting credentials - err: exit status 1, out: ``
------
 > [internal] load metadata for <http://docker.io/library/python:3.9-slim|docker.io/library/python:3.9-slim>:
------
failed to solve with frontend dockerfile.v0: failed to create LLB definition: rpc error: code = Unknown desc = error getting credentials - err: exit status 1, out: ``
so now it feels like cgo isn't installed, but I've done
xcode-select --install
and
brew install gcc
(these were done before I started working with pants). I found this very similar thread that indicates some config / env settings need to get passed through, but doesn't indicate which ones or how they should be passed through
both USER and HOME are set in my environment but perhaps those need to be passed through somehow
r
Wow this is can of worms. I don't remember this being so painful. Try passing them in [docker].env_vars inside pants.toml https://www.pantsbuild.org/docs/docker
s
yeah remember when computers were going to make our lives easier?
🫠 1
alright, finally got it going!! I ended up having to add HOME, USER, and PATH to the docker env vars. that was quite a trip. thank you so much for helping point me around @refined-addition-53644
🙏 1
🙌 1