language: go fprocess: ./handler welcome_message: | You have created a new function which uses Golang 1.9.7. To include third-party dependencies, use a vendoring tool like dep: dep documentation: https://github.com/golang/dep#installation
$ cat Dockerfile FROM golang:1.9.7-alpine3.7 as builder
RUN apk --no-cache add curl \ && echo"Pulling watchdog binary from Github." \ && curl -sSL https://github.com/openfaas/faas/releases/download/0.8.9/fwatchdog > /usr/bin/fwatchdog \ && chmod +x /usr/bin/fwatchdog \ && apk del curl --no-cache
WORKDIR /go/src/handler COPY . .
# Run a gofmt and exclude all vendored code. RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./function/vendor/*"))" || { echo"Run \"gofmt -s -w\" on your Golang code"; exit 1; }
RUN CGO_ENABLED=0 GOOS=linux \ go build --ldflags "-s -w" -a -installsuffix cgo -o handler . && \ go test $(go list ./... | grep -v /vendor/) -cover
FROM alpine:3.7 RUN apk --no-cache add ca-certificates
# Add non root user RUN addgroup -S app && adduser -S -g app app RUN mkdir -p /home/app
ADD https://github.com/openfaas/faas/releases/download/0.8.0/fwatchdog /usr/bin RUN chmod +x /usr/bin/fwatchdog
# Define your binary here ENV fprocess="/bin/cat"# 通过环境变量到处 watchdog 需要派生的子进程二进制
CMD ["fwatchdog"] # 必须将 watchdog 作为镜像运行的入口
对于 watchdog 的配置,主要是通过环境变量的方式进行,可以配置的值如下:
Option
Usage
fprocess
The process to invoke for each function call (function process). This must be a UNIX binary and accept input via STDIN and output via STDOUT
cgi_headers
HTTP headers from request are made available through environmental variables - Http_X_Served_Byetc. See section: Handling headers for more detail. Enabled by default
marshal_request
Instead of re-directing the raw HTTP body into your fprocess, it will first be marshalled into JSON. Use this if you need to work with HTTP headers and do not want to use environmental variables via the cgi_headers flag.
content_type
Force a specific Content-Type response for all responses
write_timeout
HTTP timeout for writing a response body from your function (in seconds)
read_timeout
HTTP timeout for reading the payload from the client caller (in seconds)
suppress_lock
The watchdog will attempt to write a lockfile to /tmp/ for swarm healthchecks - set this to true to disable behaviour.
exec_timeout
Hard timeout for process exec’d for each incoming request (in seconds). Disabled if set to 0
write_debug
Write all output, error messages, and additional information to the logs. Default is false
combine_output
True by default - combines stdout/stderr in function response, when set to false stderr is written to the container logs and stdout is used for function response
iflen(hasEnv.Getenv("functions_provider_url")) > 0 { var err error cfg.FunctionsProviderURL, err = url.Parse(hasEnv.Getenv("functions_provider_url")) if err != nil { log.Fatal("If functions_provider_url is provided, then it should be a valid URL.", err) } } // .... }