From a6eb4c6d31135240d3c4bbe51ed723bf5ffb2da4 Mon Sep 17 00:00:00 2001 From: Soam Vasani Date: Mon, 27 Mar 2017 23:26:59 -0700 Subject: [PATCH] Go build helper script (#163) Create a docker container and a script to call it, to help people build go plugins for use with fission. --- environments/go/README.md | 7 ++++++- environments/go/builder/Dockerfile | 5 +++++ environments/go/builder/go-function-build | 11 +++++++++++ examples/go/README.md | 14 ++++++++------ examples/go/build.sh | 8 -------- 5 files changed, 30 insertions(+), 15 deletions(-) create mode 100644 environments/go/builder/Dockerfile create mode 100755 environments/go/builder/go-function-build delete mode 100755 examples/go/build.sh diff --git a/environments/go/README.md b/environments/go/README.md index e974099e..257ef7a6 100644 --- a/environments/go/README.md +++ b/environments/go/README.md @@ -2,7 +2,7 @@ This is the Go environment for Fission. -It's a Docker image containing a Go 1.8rc3 runtime, along with a dynamic loader. +It's a Docker image containing a Go 1.8 runtime, along with a dynamic loader. ## Build this image @@ -27,3 +27,8 @@ fission env update --name go-runtime --image USER/go-runtime After this, fission functions that have the env parameter set to the same environment name as this command will use this environment. + + +## Creating functions to use this image + +See the [examples README](examples/go/README.md). diff --git a/environments/go/builder/Dockerfile b/environments/go/builder/Dockerfile new file mode 100644 index 00000000..a113b8aa --- /dev/null +++ b/environments/go/builder/Dockerfile @@ -0,0 +1,5 @@ +FROM golang:1.8 + +ENV GOPATH /usr +RUN go get github.com/fission/fission + diff --git a/environments/go/builder/go-function-build b/environments/go/builder/go-function-build new file mode 100755 index 00000000..086e71b1 --- /dev/null +++ b/environments/go/builder/go-function-build @@ -0,0 +1,11 @@ +#!/bin/sh + +if [ $# -eq 0 ] +then + echo "No arguments, building current dir" + filename='.' +else + filename=$1 +fi + +docker run --rm -v $(pwd):/build -w /build fission/go-builder go build -buildmode=plugin -o function.so $filename && echo "Compiled plugin: function.so. Use 'fission function create' to upload to fission." diff --git a/examples/go/README.md b/examples/go/README.md index 934dca34..34ab3668 100644 --- a/examples/go/README.md +++ b/examples/go/README.md @@ -4,8 +4,11 @@ The `go` runtime uses the [`plugin` package](https://golang.org/pkg/plugin/) to ## Requirements -- go 1.8 -- A [go-runtime fission environment](environments/go/README.md) +To use this environment, download the [build helper +script](environments/go/builder/go-function-build). + +The script must be run in the same directory as the function you're +building. ## Examples @@ -13,13 +16,12 @@ The `go` runtime uses the [`plugin` package](https://golang.org/pkg/plugin/) to `hello.go` is an very basic HTTP handler returning `"Hello, World!"`. - ``` -# Build the function as a plugin -$ ./build.sh +# Build the function as a plugin. Outputs result to 'function.so'. +$ go-function-build hello.go # Upload the function to fission -$ fission function create --name hello --env go-runtime --package hello.so +$ fission function create --name hello --env go-runtime --package function.so # Map /hello to the hello function $ fission route create --method GET --url /hello --function hello diff --git a/examples/go/build.sh b/examples/go/build.sh deleted file mode 100755 index 9b2576da..00000000 --- a/examples/go/build.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh - -FISSION_PATH="github.com/fission/fission" - -docker run --rm -v $GOPATH/src/$FISSION_PATH:/usr/src/$FISSION_PATH \ - -e GOPATH=/usr/ \ - -w /usr/src/$FISSION_PATH/examples/go \ - golang:1.8 go build -buildmode=plugin -o hello.so hello.go