Docker healthcheck

pull/94/head
Hunter Long 2018-11-05 17:34:02 -08:00
parent 5502179144
commit 41f944c237
4 changed files with 19 additions and 2 deletions

View File

@ -2,11 +2,14 @@ ARG VERSION
FROM hunterlong/statup:base-v${VERSION}
MAINTAINER "Hunter Long (https://github.com/hunterlong)"
# Locked version of Statup for 'latest' Docker tag
RUN apk --no-cache add curl jq
ENV IS_DOCKER=true
ENV STATUP_DIR=/app
WORKDIR /app
VOLUME /app
EXPOSE 8080
HEALTHCHECK --interval=5s --timeout=5s --retries=5 CMD curl -s "http://localhost:8080/health" | jq -r -e ".online==true"
CMD ["statup"]

View File

@ -4,7 +4,7 @@ MAINTAINER "Hunter Long (https://github.com/hunterlong)"
# Statup 'test' image for running a full test using the production environment
ENV DEP_VERSION=v0.5.0
RUN apk add --no-cache libstdc++ gcc g++ make git ca-certificates linux-headers wget curl
RUN apk add --no-cache libstdc++ gcc g++ make git ca-certificates linux-headers wget curl jq
RUN curl -L -s https://github.com/golang/dep/releases/download/$DEP_VERSION/dep-linux-amd64 -o /go/bin/dep && \
chmod +x /go/bin/dep
@ -25,4 +25,7 @@ RUN make install
WORKDIR /app
VOLUME /app
EXPOSE 8080
HEALTHCHECK --interval=5s --timeout=5s --retries=5 CMD curl -s "http://localhost:8080/health" | jq -r -e ".online==true"
ENTRYPOINT statup

View File

@ -16,6 +16,7 @@
package handlers
import (
"encoding/json"
"github.com/hunterlong/statup/core"
"github.com/hunterlong/statup/types"
"github.com/hunterlong/statup/utils"
@ -30,6 +31,15 @@ func indexHandler(w http.ResponseWriter, r *http.Request) {
executeResponse(w, r, "index.html", core.CoreApp, nil)
}
func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
health := map[string]interface{}{
"services": len(core.Services()),
"online": core.Configs != nil,
}
json.NewEncoder(w).Encode(health)
}
func trayHandler(w http.ResponseWriter, r *http.Request) {
executeResponse(w, r, "tray.html", core.CoreApp, nil)
}

View File

@ -119,6 +119,7 @@ func Router() *mux.Router {
r.Handle("/api/notifier/{notifier}", http.HandlerFunc(apiNotifierGetHandler)).Methods("POST")
r.Handle("/metrics", http.HandlerFunc(prometheusHandler))
r.Handle("/health", http.HandlerFunc(healthCheckHandler))
r.Handle("/tray", http.HandlerFunc(trayHandler))
r.NotFoundHandler = http.HandlerFunc(error404Handler)
return r