diff --git a/sample-functions/BaseFunctions/README.md b/sample-functions/BaseFunctions/README.md index 4e9ac28e..c3763c12 100644 --- a/sample-functions/BaseFunctions/README.md +++ b/sample-functions/BaseFunctions/README.md @@ -4,9 +4,10 @@ Examples of base functions are provided here. Each one will read the request from the watchdog then print it back resulting in an HTTP 200. -| Language | Docker image | Notes | -|------------------------|------------------------------------|----------------------------------------| -| Node.js | functions/node:6.9.1-alpine | Node.js built on Alpine Linux | -| Python | functions/python:2.7-alpine | Python 2.7 built on Alpine Linux | -| Java | functions/openjdk:8u121-jdk-alpine | OpenJDK built on Alpine Linux | +| Language | Docker image | Notes | +|------------------------|-----------------------------------------|----------------------------------------| +| Node.js | functions/base:node-6.9.1-alpine | Node.js built on Alpine Linux | +| Golang | functions/base:golang-1.7.5-alpine | Golang compiled on Alpine Linux | +| Python | functions/base:python-2.7-alpine | Python 2.7 built on Alpine Linux | +| Java | functions/base:openjdk-8u121-jdk-alpine | OpenJDK built on Alpine Linux | | Busybox / shell | functions/alpine:latest | Busybox contains useful binaries which can be turned into a FaaS function such as `sha512sum` or `cat` | diff --git a/sample-functions/BaseFunctions/golang/Dockerfile b/sample-functions/BaseFunctions/golang/Dockerfile new file mode 100644 index 00000000..0e1d600e --- /dev/null +++ b/sample-functions/BaseFunctions/golang/Dockerfile @@ -0,0 +1,17 @@ +FROM golang:1.7.5-alpine + +MAINTAINER alexellis2@gmail.com +ENTRYPOINT [] + +WORKDIR /go/src/github.com/alexellis/faas/sample-functions/golang +COPY . /go/src/github.com/alexellis/faas/sample-functions/golang + +RUN go install + +ADD https://github.com/alexellis/faas/releases/download/v0.5-alpha/fwatchdog /usr/bin +RUN chmod +x /usr/bin/fwatchdog + +ENV fprocess "/go/bin/golang" +HEALTHCHECK --interval=1s CMD [ -e /tmp/.lock ] || exit 1 + +CMD [ "/usr/bin/fwatchdog"] diff --git a/sample-functions/BaseFunctions/golang/build.sh b/sample-functions/BaseFunctions/golang/build.sh new file mode 100755 index 00000000..28fb5888 --- /dev/null +++ b/sample-functions/BaseFunctions/golang/build.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +echo "Building functions/base:golang-1.7.5-alpine" +docker build -t functions/base:golang-1.7.5-alpine . diff --git a/sample-functions/BaseFunctions/golang/handler.go b/sample-functions/BaseFunctions/golang/handler.go new file mode 100644 index 00000000..bc351c48 --- /dev/null +++ b/sample-functions/BaseFunctions/golang/handler.go @@ -0,0 +1,16 @@ +package main + +import ( + "fmt" + "io/ioutil" + "log" + "os" +) + +func main() { + input, err := ioutil.ReadAll(os.Stdin) + if err != nil { + log.Fatalf("Unable to read standard input: %s", err.Error()) + } + fmt.Println(string(input)) +} diff --git a/sample-functions/BaseFunctions/java/build.sh b/sample-functions/BaseFunctions/java/build.sh index f686cf16..31697a5a 100755 --- a/sample-functions/BaseFunctions/java/build.sh +++ b/sample-functions/BaseFunctions/java/build.sh @@ -1,4 +1,4 @@ #!/bin/sh -echo "Building functions/openjdk:8u121-jdk-alpine" -docker build -t functions/openjdk:8u121-jdk-alpine . +echo "Building functions/base:openjdk-8u121-jdk-alpine" +docker build -t functions/base:openjdk-8u121-jdk-alpine . diff --git a/sample-functions/BaseFunctions/node/build.sh b/sample-functions/BaseFunctions/node/build.sh index 680f7890..3e095399 100755 --- a/sample-functions/BaseFunctions/node/build.sh +++ b/sample-functions/BaseFunctions/node/build.sh @@ -1,5 +1,5 @@ #!/bin/sh -echo "Building functions/node:6.9.1-alpine" -docker build -t functions/node:6.9.1-alpine . +echo "Building functions/base:node-6.9.1-alpine" +docker build -t functions/base:node-6.9.1-alpine . diff --git a/sample-functions/BaseFunctions/python/build.sh b/sample-functions/BaseFunctions/python/build.sh index 5e2f3ece..b52426a6 100755 --- a/sample-functions/BaseFunctions/python/build.sh +++ b/sample-functions/BaseFunctions/python/build.sh @@ -1,5 +1,5 @@ #!/bin/sh -echo "Building functions/python:2.7-alpine" -docker build -t functions/python:2.7-alpine . +echo "Building functions/base:python-2.7-alpine" +docker build -t functions/base:python-2.7-alpine .