Build the function locally
pack build python-sample --builder openfunction/gcp-builder:v1 --env GOOGLE_FUNCTION_TARGET=hello_worldThe builder image used above may not be suitable for the MacOS m2 chip (Arm) architecture. For solutions, please refer to Dockerfile and then you can use the newly built builder image like:
pack build python-sample --builder <your dockerhub account>/openfunction-gcp-builder:v1 --env GOOGLE_FUNCTION_TARGET=hello_worldIf it is just for research use, you can also use the image created by @ToviHe hetovi1997/openfunction-gcp-builder:v1
Run the function
docker run --rm --env="FUNC_CONTEXT={\"name\":\"python-sample\",\"version\":\"v1.0.0\",\"port\":\"8080\",\"runtime\":\"Knative\"}" --env="CONTEXT_MODE=self-host" --name python-sample -p 8080:8080 python-sampleSend a request
curl http://localhost:8080
# hello, worldDefinition of a Function for python is shown below:
apiVersion: core.openfunction.io/v1beta2
kind: Function
metadata:
name: python-sample
spec:
version: "v1.0.0"
image: "<your registry name>/sample-python-func:v1"
imageCredentials:
name: push-secret
build:
builder: "openfunction/gcp-builder:v1"
env:
GOOGLE_FUNCTION_TARGET: "hello_world"
GOOGLE_FUNCTION_SIGNATURE_TYPE: "http"
GOOGLE_FUNCTION_SOURCE: "main.py"
srcRepo:
url: "https://github.com/OpenFunction/samples.git"
sourceSubPath: "functions/knative/hello-world-python"
revision: "main"
serving:
runtime: knative # default to knative
template:
containers:
- name: function # DO NOT change this
imagePullPolicy: IfNotPresent
triggers:
http:
port: 8080