Hi all, I’m trying to build / deploy a google clou...
# general
d
Hi all, I’m trying to build / deploy a google cloud function from my MacOS machine using environments feature with docker.
Copy code
[environments-preview.names]
linux = "//:linux"
macos = "//:macos"
docker = "//:docker"
Copy code
local_environment(
    name="macos",
    compatible_platforms=["macos_arm64"],
)

local_environment(
    name="linux",
    compatible_platforms=["linux_x86_64"],
    fallback_environment="docker",
)

docker_environment(
    name="docker",
    platform="linux_x86_64",
    image="multiply_base",
    python_bootstrap_search_path=["<PATH>"],
)
In my google cloud function I’ve tagged the environment as
linux
and I can see it’s using the docker environment I’ve specified above
Copy code
python_google_cloud_function(
    name="cloud_function",
    runtime="python311",
    handler="./main.py:example",
    type="http",
    environment="linux",
    dependencies=["//:reqs0#greenlet"]
)
when I run
pants package fns:cloud_function
to package my cloud function / target I get the following error
Copy code
A distribution for greenlet could not be resolved for cp311-cp311-linux_x86_64.
Found 1 distribution for greenlet that do not apply:
1.) The wheel tags for greenlet 3.0.0 are cp311-cp311-manylinux_2_24_x86_64, cp311-cp311-manylinux_2_28_x86_64 which do not match the supported tags of cp311-cp311-linux_x86_64:
cp311-cp311-manylinux2014_x86_64
It’s complaining that
cp311-cp311-manylinux_2_24_x86_64 != cp311-cp311-linux_x86_6
for a particular package. What’s the usual solution for this kind of error? I’ve loosely specified everything in my
BUILD
as
linux_x86_64
but this doesn’t seem to satisfy pex. When building regular pex binaries this seems to work fine, it’s only when using the
cloud_function
target.
👀 1
c
from what I’ve gleaned off of previous threads on this topic is that you want to use
complete_platforms
to get predictable results.
d
is that still necessary if I’m using docker ?
c
I’m no expert on this, but there’s plenty to read through in the slack history here..
but I think, yes
d
Copy code
docker_environment(
    name="docker",
    platform="linux_x86_64",
    image="multiply_base",
    python_bootstrap_search_path=["<PATH>"],
)
So I launched that exact docker image, installed pex and ran
pex3 interpreter inspect --markers --tags
to list of complete platforms. Copied that into a
platform.json
file Then added:
Copy code
file(name="platform", source="platform.json")

python_google_cloud_function(
    name="cloud_function",
    runtime="python311",
    handler="./main.py:example",
    type="http",
    environment="linux",
    dependencies=["//:reqs0#greenlet"],
    complete_platforms=["//:platform"],
)
And it’s made some progress because now I’m getting a different error
Copy code
A single target is required for creating a flat sys.path directory entry.
There were 2 targets selected:
1. cp311-cp311-linux_x86_64
2. cp311-cp311-manylinux_2_36_x86_64
Will keep looking and see what I find
c
I think you need to remove the
platform
field from your docker env
(I’ve no idea, it’s from memory of another thread)
d
Removing the platform makes docker complain about my image not being the right platform
linux/arm64, actual: linux/amd64
I tried removing the platform and just using
python:3.11-slim
and I get the same
Copy code
A single target is required for creating a flat sys.path directory entry.
There were 2 targets selected:
1. cp311-cp311-linux_x86_64
2. cp311-cp311-manylinux_2_36_x86_64
c
ah, ok. so not exactly right then.. I’d suggest digging through this slack history for anything relating to docker and platforms, I think your answer is in there..
d
👍 1
c
ah, that was it. Thanks.