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 <rdimitrow@gmail.com>
This commit is contained in:
Radoslav Dimitrov 2018-09-02 23:44:06 +03:00 committed by Alex Ellis
parent c062e4dbde
commit c821585b39
2 changed files with 29 additions and 4 deletions

20
DEV.md
View File

@ -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 . 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 RUN chmod +x /usr/bin/fwatchdog
ENV fprocess="/go/src/app/app" ENV fprocess="/go/src/app/app"
@ -61,7 +61,7 @@ Update the Docker stack with this:
``` ```
FROM alpine:latest 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 RUN chmod +x /usr/bin/fwatchdog
ENV fprocess="wc" ENV fprocess="wc"
@ -81,6 +81,22 @@ Update your Docker stack with this definition:
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 ### Testing your function
You can test your function through a webbrowser against the UI portal on port 8080. You can test your function through a webbrowser against the UI portal on port 8080.

View File

@ -36,7 +36,7 @@ Example Dockerfile for an `echo` function:
``` ```
FROM alpine:3.7 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 RUN chmod +x /usr/bin/fwatchdog
# Define your binary here # Define your binary here
@ -45,6 +45,15 @@ ENV fprocess="/bin/cat"
CMD ["fwatchdog"] 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** **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. 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.