openfaas / of-watchdog

Reverse proxy for STDIO and HTTP microservices
MIT License
262 stars 115 forks source link

Implement a new `static` mode #76

Closed matipan closed 5 years ago

matipan commented 5 years ago

This mode allows the users to use the watchdog as a static server for serving static files. The added benefit over a plain file server is that they get the RED metrics already implemented by the watchdog.

Signed-off-by: Matias Pan matias.pan26@gmail.com

Description

A new mode was added called static. When the users set this mode they must also set the static_path variable that will be the directory the user wants to serve. If none is set we default to /home/app/public.

I also changed the signature of the config.New function, it was returning an error but in the function we were never actually returning an error. I updated the tests with this new change.

Closes #74

Motivation and Context

How Has This Been Tested?

After making the changes I built the binary and tweaked the hugo template for using the watchdog instead of the static server. I then built my personal blog that uses this template and served it locally with:

$ docker run -p 8080:8080 -it matipan/blog-watchdog:debug
2019/08/10 23:44:50 Serving files at /home/server/public
2019/08/10 23:44:50 OperationalMode: static
2019/08/10 23:44:50 Timeouts: read: 10s, write: 10s hard: 10s.
2019/08/10 23:44:50 Listening on port: 8080
2019/08/10 23:44:50 Writing lock-file to: /tmp/.lock
2019/08/10 23:44:50 Metrics listening on port: 8081

You can see that the logs indicate we are making use of the new static mode. I then went to http://localhost:8080 and saw that the website was being properly rendered: of-watchdog

I also executed ./build.sh to make sure all of the binaries are being properly built:

Output of build.sh: ``` $ ./build.sh [+] Building 27.2s (17/17) FINISHED => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load build definition from Dockerfile 0.0s => => transferring dockerfile: 1.11kB 0.0s => [internal] load metadata for docker.io/library/golang:1.10 2.2s => [1/12] FROM docker.io/library/golang:1.10@sha256:6d5e79878a3e4f1b30b7aa4d24fb6ee6184e905a9b172fc72593935633be4c46 0.0s => [internal] load build context 0.0s => => transferring context: 1.01MB 0.0s => CACHED [2/12] RUN mkdir -p /go/src/github.com/openfaas-incubator/of-watchdog 0.0s => CACHED [3/12] WORKDIR /go/src/github.com/openfaas-incubator/of-watchdog 0.0s => CACHED [4/12] COPY vendor vendor 0.0s => [5/12] COPY config config 0.0s => [6/12] COPY executor executor 0.0s => [7/12] COPY metrics metrics 0.0s => [8/12] COPY metrics metrics 0.0s => [9/12] COPY main.go . 0.0s => [10/12] RUN test -z "$(gofmt -l $(find . -type f -name '*.go' -not -path "./vendor/*"))" 0.4s => [11/12] RUN go test -v ./... 2.3s => [12/12] RUN CGO_ENABLED=0 GOOS=linux go build -a -ldflags "-s -w" -installsuffix cgo -o of-watchdog . && CGO_ENABLED=0 GOOS=darwin go build -a -ldflags "-s -w" -installsuffix cgo -o of-watchdog-d 21.2s => exporting to image 0.8s => => exporting layers 0.8s => => writing image sha256:47d8f0eb00de161216117c6c4b252c7fa9aff831cf7e14717097f410bd9e2970 0.0s => => naming to docker.io/openfaas/of-watchdog:build 0.0s [+] Building 0.2s (6/6) FINISHED => [internal] load build definition from Dockerfile.packager 0.0s => => transferring dockerfile: 223B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/openfaas/of-watchdog:build 0.0s => [build 1/1] FROM docker.io/openfaas/of-watchdog:build 0.0s => => resolve docker.io/openfaas/of-watchdog:build 0.0s => [stage-1 1/1] COPY --from=build /go/src/github.com/openfaas-incubator/of-watchdog/of-watchdog ./fwatchdog 0.0s => exporting to image 0.1s => => exporting layers 0.1s => => writing image sha256:d371050872a22e51571683749fb3c213091ab6bb2b02def46680509d20af3da2 0.0s => => naming to docker.io/openfaas/of-watchdog:latest-dev-darwin 0.0s [+] Building 0.1s (6/6) FINISHED => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load build definition from Dockerfile.packager 0.0s => => transferring dockerfile: 47B 0.0s => [internal] load metadata for docker.io/openfaas/of-watchdog:build 0.0s => CACHED [build 1/1] FROM docker.io/openfaas/of-watchdog:build 0.0s => [stage-1 1/1] COPY --from=build /go/src/github.com/openfaas-incubator/of-watchdog/of-watchdog ./fwatchdog 0.0s => exporting to image 0.0s => => exporting layers 0.0s => => writing image sha256:d5620b3ac0dfea9df2f38d1b51b0a0d6210548d18cb576bbe021ccd63fefa945 0.0s => => naming to docker.io/openfaas/of-watchdog:latest-dev-armhf 0.0s [+] Building 0.2s (6/6) FINISHED => [internal] load build definition from Dockerfile.packager 0.0s => => transferring dockerfile: 47B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/openfaas/of-watchdog:build 0.0s => CACHED [build 1/1] FROM docker.io/openfaas/of-watchdog:build 0.0s => [stage-1 1/1] COPY --from=build /go/src/github.com/openfaas-incubator/of-watchdog/of-watchdog ./fwatchdog 0.0s => exporting to image 0.1s => => exporting layers 0.1s => => writing image sha256:b6f1615845a8b4c669efe8d0c71c978120d8a374770b1453d0ac351fde42f01d 0.0s => => naming to docker.io/openfaas/of-watchdog:latest-dev-arm64 0.0s [+] Building 0.2s (6/6) FINISHED => [internal] load build definition from Dockerfile.packager 0.0s => => transferring dockerfile: 47B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/openfaas/of-watchdog:build 0.0s => CACHED [build 1/1] FROM docker.io/openfaas/of-watchdog:build 0.0s => [stage-1 1/1] COPY --from=build /go/src/github.com/openfaas-incubator/of-watchdog/of-watchdog ./fwatchdog 0.0s => exporting to image 0.1s => => exporting layers 0.1s => => writing image sha256:a55312cdda8c3f2218df4880b15a0fc0c820fba4ac0327b1638476b6b006c404 0.0s => => naming to docker.io/openfaas/of-watchdog:latest-dev-windows 0.0s [+] Building 0.2s (6/6) FINISHED => [internal] load build definition from Dockerfile.packager 0.0s => => transferring dockerfile: 47B 0.0s => [internal] load .dockerignore 0.0s => => transferring context: 2B 0.0s => [internal] load metadata for docker.io/openfaas/of-watchdog:build 0.0s => CACHED [build 1/1] FROM docker.io/openfaas/of-watchdog:build 0.0s => [stage-1 1/1] COPY --from=build /go/src/github.com/openfaas-incubator/of-watchdog/of-watchdog ./fwatchdog 0.0s => exporting to image 0.1s => => exporting layers 0.0s => => writing image sha256:a4f46d41ea02ce6ab1f35d78295f4016ee95913e8082f08662a5edd4d34ceec0 0.0s => => naming to docker.io/openfaas/of-watchdog:latest-dev-x86_64 0.0s 5bab7edf4e8eedaff0521f932eb5dad8dda4119dd970c39972f0121b316ff6d4 buildoutput ```

Types of changes

Checklist:

alexellis commented 5 years ago

Nice work 💪

Please can you show this website operating through the gateway, where there is a prefixed path?

Alex

alexellis commented 5 years ago

Please can you also?

alexellis commented 5 years ago

@matipan I would like you to acknowledge the comments and provide the feedback I've asked for. Given that you are the only consume at the moment, I'll merge and release the change, but please can you prioritise the feedback?

alexellis commented 5 years ago

You can access the new release via: https://github.com/openfaas-incubator/of-watchdog/releases/tag/0.5.5