From c821585b395fd5f453fc3109dceab077c60e70ca Mon Sep 17 00:00:00 2001 From: Radoslav Dimitrov Date: Sun, 2 Sep 2018 23:44:06 +0300 Subject: [PATCH] Sample-functions: Get watchdog using curl instead of ADD - Docs Convert all sample-functions to use curl to get the watchdog as it can be cached by Docker. Issue #841 Signed-off-by: Radoslav Dimitrov --- DEV.md | 22 +++++++++++++++++++--- watchdog/README.md | 11 ++++++++++- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/DEV.md b/DEV.md index 045a532b..e4c96ebe 100644 --- a/DEV.md +++ b/DEV.md @@ -35,7 +35,7 @@ RUN go get github.com/microcosm-cc/bluemonday && \ RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o app . -ADD https://github.com/openfaas/faas/releases/download/0.8.0/fwatchdog /usr/bin +ADD https://github.com/openfaas/faas/releases/download/0.9.0/fwatchdog /usr/bin RUN chmod +x /usr/bin/fwatchdog ENV fprocess="/go/src/app/app" @@ -61,7 +61,7 @@ Update the Docker stack with this: ``` FROM alpine:latest -ADD https://github.com/openfaas/faas/releases/download/0.8.0/fwatchdog /usr/bin +ADD https://github.com/openfaas/faas/releases/download/0.9.0/fwatchdog /usr/bin RUN chmod +x /usr/bin/fwatchdog ENV fprocess="wc" @@ -78,7 +78,23 @@ Update your Docker stack with this definition: networks: - functions environment: - fprocess: "wc" + fprocess: "wc" +``` + +**Tip:** +You can optimize Docker to cache getting the watchdog by using curl, instead of ADD. +To do so, replace the related lines with: +``` +RUN apt-get update && apt-get install -y curl \ + && curl -sL https://github.com/openfaas/faas/releases/download/0.9.0/fwatchdog > /usr/bin/fwatchdog \ + && chmod +x /usr/bin/fwatchdog \ + && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* +``` +or with the following for Alpine based images: +``` +RUN apk --no-cache add curl \ + && curl -sL https://github.com/openfaas/faas/releases/download/0.9.0/fwatchdog > /usr/bin/fwatchdog \ + && chmod +x /usr/bin/fwatchdog ``` ### Testing your function diff --git a/watchdog/README.md b/watchdog/README.md index 7c794a6e..687e342f 100644 --- a/watchdog/README.md +++ b/watchdog/README.md @@ -36,7 +36,7 @@ Example Dockerfile for an `echo` function: ``` FROM alpine:3.7 -ADD https://github.com/openfaas/faas/releases/download/0.8.0/fwatchdog /usr/bin +ADD https://github.com/openfaas/faas/releases/download/0.9.0/fwatchdog /usr/bin RUN chmod +x /usr/bin/fwatchdog # Define your binary here @@ -45,6 +45,15 @@ ENV fprocess="/bin/cat" CMD ["fwatchdog"] ``` +**Tip:** +You can optimize Docker to cache getting the watchdog by using curl, instead of ADD. +To do so, replace the related lines with: +``` +RUN apk --no-cache add curl \ + && curl -sL https://github.com/openfaas/faas/releases/download/0.9.0/fwatchdog > /usr/bin/fwatchdog \ + && chmod +x /usr/bin/fwatchdog +``` + **Implementing a health-check** At any point in time, if you detect that your function has become unhealthy and needs to restart, then you can delete the `/tmp/.lock` file which invalidates the check and causes Swarm to re-schedule the function.