1
0
Fork 0

Add healthcheck command

main
Jordan Hotmann 2024-01-08 14:47:35 -07:00
parent 2369c1d5c9
commit de7af8cc7b
No known key found for this signature in database
GPG Key ID: 01B504170C2A2EA3
2 changed files with 24 additions and 0 deletions

View File

@ -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" ]

22
cmd/healthcheck/main.go Normal file
View File

@ -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)
}