Skip to content

Files

go116

Build builder of go version 1.16

Version Matrix

Builder Name Tag description Functions-framework-go version
openfunction/builder-go:v0.2.2-1.16 Buildpacks: v0.2.2, Go: 1.16 v0.0.0-20210628081257-4137e46a99a6
openfunction/builder-go:v0.3.0-1.16 Buildpacks: v0.3.0, Go: 1.16 v0.0.0-20210922063920-81a7b2951b8a
openfunction/builder-go:v0.4.0-1.16 Buildpacks: v0.4.0, Go: 1.16 v0.1.1
openfunction/builder-go:v2-1.16 Buildpacks: v0.5.0, Go: 1.16 v0.2.3
openfunction/builder-go:v2.3.0-1.16 Buildpacks: v0.6.0, Go: 1.16 v0.3.0

Build go116 stack

bazel run //builders/go116/stack:build
# if you are using macOS
bazel run --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //builders/go116/stack:build

This command creates two images:

openfunctiondev/buildpacks-run-go:v2.3.0-1.16
openfunctiondev/buildpacks-go116-build:v2.3.0-1.16

Build go116 builder

bazel build //builders/go116:builder.image
# if you are using macOS
bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //builders/go116:builder.image

This command creates one image:

openfunction/builder-go:v2.3.0-1.16

Tag and push:

docker tag openfunction/builder-go:v2.3.0-1.16 openfunction/builder-go:v2.3.0
docker push openfunction/builder-go:v2.3.0
docker push openfunction/builder-go:v2.3.0-1.16

Test

bazel test //builders/go116/acceptance/...
Output example
INFO: Analyzed 2 targets (8 packages loaded, 205 targets configured).
INFO: Found 1 target and 1 test target...
INFO: Elapsed time: 50.633s, Critical Path: 49.87s
INFO: 10 processes: 3 internal, 6 linux-sandbox, 1 local.
INFO: Build completed successfully, 10 total actions
//builders/go116/acceptance:go_fn_test                                   PASSED in 48.1s

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

Run locally

OpenFunction Samples

Download samples:

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

Build the function:

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

cd samples/functions/Knative/hello-world-go
pack build func-helloworld-go --builder openfunction/builder-go:v2.3.0-1.16 --env FUNC_NAME="HelloWorld"  --env FUNC_CLEAR_SOURCE=true
docker run --rm --env="FUNC_CONTEXT={\"name\":\"HelloWorld\",\"version\":\"v1.0.0\",\"port\":\"8080\",\"runtime\":\"Knative\"}" --env="CONTEXT_MODE=self-host" --name func-helloworld-go -p 8080:8080 func-helloworld-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 openfunction/builder-go:v2.3.0-1.16 --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.16 is shown below:

apiVersion: core.openfunction.io/v1alpha1
kind: Function
metadata:
  name: go-sample
spec:
  version: "v1.0.0"
  image: "<your registry name>/sample-go116-func:latest"
  # port: 8080 # default to 8080
  build:
    builder: "openfunction/builder-go:v2.3.0-1.16"
    params:
      FUNC_NAME: "HelloWorld"
      FUNC_TYPE: "http"
      FUNC_CLEAR_SOURCE: "true"
      # 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