proud-byte-81916
11/09/2023, 3:29 PMpants package path/to/src/Dockerfile
- the only issue is that the image is built with architecture arm64
instead of x86_64
I managed to build the docker image with the right platform by adding this to the FROM directive: FROM --platform=linux/amd64 python:3.10
The images builds correctly, but I get this error when running it:
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.10 CPython==3.10.13
2.) /usr/bin/python3.11 CPython==3.11.2
No interpreter compatible with the requested constraints was found:
A distribution for matplotlib could not be resolved for /usr/local/bin/python3.10.
Found 1 distribution for matplotlib that do not apply:
1.) The wheel tags for matplotlib 3.7.3 are cp310-cp310-manylinux_2_17_aarch64, cp310-cp310-manylinux2014_aarch64 which do not match the supported tags of /usr/local/bin/python3.10:
cp310-cp310-manylinux_2_36_x86_64
... 839 more ...
I tried to add the complete platform of lambda x86_x64 and reference it, in order to have pip dependencies resolved for x86_64:
python_sources(name="server", sources=["**/*.py"], dependencies=["//:env_file"])
python_tests(
name="tests",
sources=["tests/**/test_*.py"],
dependencies=[":tests_support_files", "//:env_file"],
)
resources(
name="tests_support_files",
sources=["tests/**/*"],
)
pex_binary(name="bin", entry_point="main.py", complete_platforms=["3rdparty/platforms:aws_lambda_python_3_10"])
docker_image(name="docker")
But this now gives this error when running the container:
/usr/bin/env: 'python3.9': No such file or directory
The PEX with the complete platform for py3.10 seems to be looking for python3.9 ๐ค
Does anybody have any solution for this? Would really appreciate some guidance ๐ thanks so much!lemon-yak-80782
11/09/2023, 3:52 PMproud-byte-81916
11/09/2023, 3:52 PMFROM --platform=linux/amd64 python:3.10
ENTRYPOINT ["/bin/main"]
COPY projects.logo_gen.server/bin.pex /bin/main
proud-byte-81916
11/09/2023, 3:52 PMlemon-yak-80782
11/09/2023, 3:53 PMproud-byte-81916
11/09/2023, 3:53 PMlemon-yak-80782
11/09/2023, 3:58 PMlemon-yak-80782
11/09/2023, 3:58 PM[">=3.10,<3.11"]
proud-byte-81916
11/09/2023, 3:59 PMinterpreter_constraints = ["==3.10.*"]
I have this in my pants.tomlproud-byte-81916
11/09/2023, 3:59 PM[">=3.10,<3.11"]
?lemon-yak-80782
11/09/2023, 4:00 PMproud-byte-81916
11/09/2023, 4:00 PMproud-byte-81916
11/09/2023, 4:00 PMcomplete_platforms
for the pex in the BUILD fileproud-byte-81916
11/09/2023, 4:01 PMlemon-yak-80782
11/09/2023, 4:07 PMpython:3.9
in your docker file?proud-byte-81916
11/09/2023, 4:33 PMproud-byte-81916
11/09/2023, 4:33 PMproud-byte-81916
11/09/2023, 4:45 PM16:45:02.57 [INFO] Completed: Building docker image logo-generator:latest
WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested
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.9 CPython==3.9.18
2.) /usr/bin/python3.11 CPython==3.11.2
No interpreter compatible with the requested constraints was found:
A distribution for matplotlib could not be resolved for /usr/local/bin/python3.9.
Found 1 distribution for matplotlib that do not apply:
1.) The wheel tags for matplotlib 3.7.3 are cp310-cp310-manylinux2014_x86_64, cp310-cp310-manylinux_2_17_x86_64 which do not match the supported tags of /usr/local/bin/python3.9:
cp39-cp39-manylinux_2_36_x86_64
... 766 more ...
A distribution for matplotlib could not be resolved for /usr/bin/python3.11.
Found 1 distribution for matplotlib that do not apply:
1.) The wheel tags for matplotlib 3.7.3 are cp310-cp310-manylinux2014_x86_64, cp310-cp310-manylinux_2_17_x86_64 which do not match the supported tags of /usr/bin/python3.11:
cp311-cp311-manylinux_2_36_x86_64
... 912 more ...
lemon-yak-80782
11/09/2023, 5:04 PMproud-byte-81916
11/09/2023, 5:06 PMlemon-yak-80782
11/09/2023, 5:08 PMcp310-cp310-manylinux_2_36_x86_64
to your complete platform file? And then try to run the python 3.10 container.proud-byte-81916
11/09/2023, 5:08 PMproud-byte-81916
11/09/2023, 5:11 PMlemon-yak-80782
11/09/2023, 5:12 PMproud-byte-81916
11/09/2023, 5:13 PMproud-byte-81916
11/09/2023, 5:13 PMlemon-yak-80782
11/09/2023, 5:14 PMcp310-cp310-manylinux_2_36_x86_64
is needed but not found. Adding cp310-cp310-manylinux_2_36_x86_64
to the compatible_tags list should solve the issue.proud-byte-81916
11/09/2023, 5:15 PMlemon-yak-80782
11/09/2023, 5:16 PMcp39-cp39-manylinux_2_36_x86_64
and try 3.9proud-byte-81916
11/09/2023, 5:18 PMproud-byte-81916
11/09/2023, 5:18 PMproud-byte-81916
11/09/2023, 5:21 PMpex_binary(name="bin", entry_point="main.py", complete_platforms=["3rdparty/platforms:aws_lambda_python_3_10"])
in the BUILD file
If i run pants package /path/to/file:bin
I get the same binary file that if I run locally and not in the docker container, I get the same py3.9 errorproud-byte-81916
11/09/2023, 5:21 PMlemon-yak-80782
11/09/2023, 5:22 PMproud-byte-81916
11/09/2023, 5:23 PMx86_64
which is my target architecture - and I thought it should be the same whether is coming from lambda or notproud-byte-81916
11/09/2023, 5:23 PMx86_64
to the pex binary?lemon-yak-80782
11/09/2023, 5:25 PMpublic.ecr.aws/lambda/python:3.10
lemon-yak-80782
11/09/2023, 5:25 PMproud-byte-81916
11/09/2023, 5:29 PMproud-byte-81916
11/09/2023, 5:29 PMproud-byte-81916
11/09/2023, 5:30 PMlemon-yak-80782
11/09/2023, 5:36 PMpex_binary
targets ๐ . Are you running the container on your mac?proud-byte-81916
11/09/2023, 5:36 PMbroad-processor-92400
11/09/2023, 6:53 PMPython:3.10
container youโre usingโฆ but I suspect that wonโt help directly.
This looks like it might be https://github.com/pantsbuild/pants/issues/19514 where thereโs a suggestion of using the shebang
field as a workaround.proud-byte-81916
11/09/2023, 10:59 PMpython_sources(name="server", sources=["**/*.py"], dependencies=["//:env_file"])
python_tests(
name="tests",
sources=["tests/**/test_*.py"],
dependencies=[":tests_support_files", "//:env_file"],
)
resources(
name="tests_support_files",
sources=["tests/**/*"],
)
pex_binary(
name="bin",
entry_point="main.py",
complete_platforms=["3rdparty/platforms:docker_310"],
shebang="#!/usr/bin/env python3"
)
docker_image(name="logo-generator")
With the complete platform being this. I followed the guide here to get it (explained in Python AWS Lambda zip artefacts
).
My docker file is:
FROM --platform=linux/amd64 python:3.10
ENTRYPOINT ["/bin/main"]
COPY projects.logo_gen.server/bin.pex /bin/main