From a721dc1f314732e60d331a1a7da97d06e0e8b613 Mon Sep 17 00:00:00 2001 From: Oleg Lobanov Date: Sun, 21 Mar 2021 12:30:48 +0100 Subject: [PATCH] feat: add health check handler --- .dockerignore | 1 + Dockerfile | 8 ++++++-- http/http.go | 1 + http/public.go | 5 +++++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/.dockerignore b/.dockerignore index 60b7a312..f3f249a3 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,2 +1,3 @@ * +!.docker.json !filebrowser \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 98700278..8cbc7a5b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,10 @@ FROM alpine:latest -RUN apk --update add ca-certificates -RUN apk --update add mailcap +RUN apk --update add ca-certificates \ + mailcap \ + curl + +HEALTHCHECK --start-period=2s --interval=5s --timeout=3s \ + CMD curl -f http://localhost/health || exit 1 VOLUME /srv EXPOSE 80 diff --git a/http/http.go b/http/http.go index 80c7e92c..6afda6fa 100644 --- a/http/http.go +++ b/http/http.go @@ -36,6 +36,7 @@ func NewHandler( return handle(fn, prefix, store, server) } + r.HandleFunc("/health", healthHandler) r.PathPrefix("/static").Handler(static) r.NotFoundHandler = index diff --git a/http/public.go b/http/public.go index 8dc400d3..26bfffb8 100644 --- a/http/public.go +++ b/http/public.go @@ -136,3 +136,8 @@ func authenticateShareRequest(r *http.Request, l *share.Link) (int, error) { return 0, nil } + +func healthHandler(w http.ResponseWriter, _ *http.Request) { + w.WriteHeader(http.StatusOK) + _, _ = w.Write([]byte(`{"status":"OK"}`)) +}