Skip to content

Latest commit

 

History

History

py37

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Build builder of python version 3.7

Build py37 stack

bazel run //builders/py37/stack:build

This command creates two images:

openfunctiondev/buildpacks-py37-run:v1
openfunctiondev/buildpacks-py37-build:v1

Build py37 builder

bazel build //builders/py37:builder.image

This command creates one image:

of/py37

Tag and push:

docker tag of/py37 <your container registry>/py37:v1
docker push <your container registry>/py37:v1

Test

bazel test //builders/py37/acceptance/...

Output example:

INFO: Analyzed 2 targets (1 packages loaded, 5 targets configured).
INFO: Found 1 target and 1 test target...
INFO: Elapsed time: 31.606s, Critical Path: 31.33s
INFO: 2 processes: 1 internal, 1 local.
INFO: Build completed successfully, 2 total actions
//builders/py37/acceptance:python_fn_test                            PASSED in 31.3s

Executed 1 out of 1 test: 1 test passes.
INFO: Build completed successfully, 2 total actions

Run Locally

Download gcp samples:

git clone https://github.com/GoogleCloudPlatform/buildpack-samples.git

Build the function:

Add --network host to pack and docker command if they cannot reach internet.

cd buildpack-samples/sample-functions-framework-python/
pack build function-python --builder of/py37 --env FUNC_NAME="hello"
docker run --rm -p8080:8080 function-python

Visit the function:

curl http://localhost:8080

Output example:

hello, world

Run on OpenFunction

  1. Install OpenFunction
  2. Run a function

Definition of a Function for python 3.7 is shown below:

apiVersion: core.openfunction.io/v1alpha1
kind: Function
metadata:
  name: python-sample
spec:
  version: "v1.0.0"
  image: "<your registry name>/sample-python37-func:latest"
  # port: 8080 # default to 8080
  build:
    builder: "openfunctiondev/py37-builder:v1"
    params:
      FUNC_NAME: "hello"
      FUNC_TYPE: "http"
      # FUNC_SRC: "main.py" # for python function
    srcRepo:
      url: "https://github.com/GoogleCloudPlatform/buildpack-samples.git"
      sourceSubPath: "sample-functions-framework-python"
    registry:
      url: "https://index.docker.io/v1/"
      account:
        name: "basic-user-pass"
        key: "username"
    # serving:
    # runtime: "Knative" # default to Knative