Having an issue building a docker image to be used...
# general
q
Having an issue building a docker image to be used for an aws lambda function. I can build it locally, but get an error in a github actions pipeline:
Successfully built the wheel simplejson-3.17.2-cp39-cp39-linux_x86_64.whl from the sdist simplejson-3.17.2.tar.gz but it is not compatible with the requested foreign target complete platform cp311-cp311-manylinux_2_26_x86_64
b
The error message tells you most of what the problem is - the wheel is being built for Python 3.9 but the target platform is Python 3.11; since it’s an
sdist
the package is built from a source distribution. Is there a difference in Python version between your Github Actions pipeline and your local machine?
q
I'm not sure why it's building with Python 3.9. The interpreter constraints are set to 3.11 in pants.toml and BUILD files, and I'm installing 3.11 in the build pipeline:
Copy code
steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install python
        uses: actions/setup-python@v4
        with:
          python-version: 3.11.5
      - name: Initialize Pants
        uses: pantsbuild/actions/init-pants@v5-scie-pants
      - name: Build
        id: build-image
        run: |
            pants package path/to/docker:image
We have a base BUILD with some defaults:
Copy code
# Set default build values for the component.
__defaults__(
    {
        (
            python_sources,
            python_tests,
            python_test_utils,
            python_aws_lambda_function,
            python_aws_lambda_layer,
            pex_binary,
        ): {
            "resolve": "my_resolve",
        },
        (python_sources, python_tests, python_test_utils, pex_binary): {
            "interpreter_constraints": ["==3.11.*"],
        },
        (python_aws_lambda_function, python_aws_lambda_layer): {"runtime": "python3.11"},
    }
)
And the docker image BUILD is just:
Copy code
docker_image(
    name="image",
    dependencies=["dep/path/main:my_func"],
)
pants.toml has:
Copy code
[python]
interpreter_constraints = ["CPython==3.11.*"]
enable_resolves = true

[python.resolves_to_interpreter_constraints]
my_resolve = ["CPython==3.11.*"]
Also tried setting
complete_platforms = "linux_x86_py311"
for
pex_binary
targets, no luck
b
Hmm, interesting. I notice that your Docker image depends on a specific Python source - is that intentional, or are you intending to package a PEX file into the image instead?
q
It was intentional, but not sure if it's necessary in this case? It's there because it's to be deployed as a python aws lambda function, and this suggests such a base image: https://docs.aws.amazon.com/lambda/latest/dg/python-image.html
b
The dependency in that Pants example is from the Docker image target to the lambda function target, not to a specific source file. That might be the issue, unless
dep/path/main:my_func
is a lambda function
q
It is a lambda function:
Copy code
python_aws_lambda_function(
    name="my_func",
    handler="run.py:lambda_handler",
)
b
Hmm yeah and I see that you already pass in the value of
runtime
via the defaults - but what happens if you explicitly set the lambda function runtime to
python3.11
?
q
I think that should be set as default with this BUILD file at the root? I'll try setting it explicitly in any case
Copy code
__defaults__(
    {
        (
            python_sources,
            python_tests,
            python_test_utils,
            python_aws_lambda_function,
            python_aws_lambda_layer,
            pex_binary,
        ): {
            "resolve": "my_resolve",
        },
        (python_sources, python_tests, python_test_utils, pex_binary): {
            "interpreter_constraints": ["==3.11.*"],
        },
        (python_aws_lambda_function, python_aws_lambda_layer): {"runtime": "python3.11"},
    }
)
Tried setting
runtime
to
python3.11
in
python_aws_lambda_function
, no dice