diff --git a/Dockerfile b/Dockerfile index dd3cc7b..2f71f07 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,6 +5,7 @@ COPY go.mod go.sum ./ RUN go mod download COPY . ./ RUN CGO_ENABLED=0 GOOS=linux go build -o /hats +RUN CGO_ENABLED=0 GOOS=linux go build -o /healthcheck ./cmd/healthcheck/main.go FROM builder as tester @@ -13,4 +14,5 @@ RUN go test -v FROM scratch COPY --from=builder --chmod=755 /hats /hats +COPY --from=builder --chmod=755 /healthcheck /healthcheck ENTRYPOINT [ "/hats" ] \ No newline at end of file diff --git a/cmd/healthcheck/main.go b/cmd/healthcheck/main.go new file mode 100644 index 0000000..048eae6 --- /dev/null +++ b/cmd/healthcheck/main.go @@ -0,0 +1,22 @@ +package main + +import ( + "os" + + "github.com/go-resty/resty/v2" +) + +func main() { + c := resty.New() + resp, err := c.R().Get("http://127.0.0.1:8888/status") + + if err != nil || !resp.IsSuccess() { + os.Exit(1) + } + + if string(resp.Body()) == "OK" { + os.Exit(0) + } + + os.Exit(1) +}