Skip to content

Latest commit

 

History

History
162 lines (117 loc) · 3.12 KB

README.md

File metadata and controls

162 lines (117 loc) · 3.12 KB

Build builder of go version 1.15

Build go115 stack

bazel run //builders/go115/stack:build

This command creates two images:

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

Build go115 builder

bazel build //builders/go115:builder.image

This command creates one image:

of/go115

Tag and push:

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

Test

bazel test //builders/go115/acceptance/...
Output example
INFO: Analyzed 2 targets (0 packages loaded, 0 targets configured).
INFO: Found 1 target and 1 test target...
INFO: Elapsed time: 36.640s, Critical Path: 36.47s
INFO: 7 processes: 1 internal, 5 linux-sandbox, 1 local.
INFO: Build completed successfully, 7 total actions
//builders/go115/acceptance:go_fn_test                                   PASSED in 35.4s

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

Run locally

OpenFunction Samples

Download samples:

git clone https://github.com/OpenFunction/function-samples.git

Build the function:

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

cd function-samples/hello-world-go/
pack build function-go --builder of/go115 --env FUNC_NAME="HelloWorld"
docker run --rm -p8080:8080 function-go

Visit the function:

curl http://localhost:8080

Output example:

hello, world!
GoogleCloudPlatform Samples

Download 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-go/
pack build function-go --builder of/go115 --env FUNC_NAME="HelloWorld"
docker run --rm -p8080:8080 function-go

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 go 1.15 is shown below:

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