Skip to content

Commit

Permalink
added a healthcheck command to make sure the cal-proxy is healthy
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Mar 20, 2024
1 parent 5b78b42 commit 06ad64e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21.5-alpine3.17 as builder
FROM golang:1.22-alpine3.19 as builder

# Ca-certificates are required to call HTTPS endpoints.
RUN apk update && apk add --no-cache ca-certificates tzdata alpine-sdk bash && update-ca-certificates
Expand All @@ -18,12 +18,15 @@ COPY internal internal
ARG version=dev
# Compile statically
RUN CGO_ENABLED=0 go build -ldflags "-w -extldflags '-static' -X internal/app.Version=${version}" -o /proxy cmd/proxy/proxy.go
RUN CGO_ENABLED=0 go build -ldflags "-w -extldflags '-static'" -o /healthcheck cmd/healthcheck/healthcheck.go

FROM scratch

COPY --from=builder /proxy /proxy
COPY --from=builder /healthcheck /healthcheck
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

EXPOSE 4321
HEALTHCHECK --interval=1s --timeout=1s --start-period=2s --retries=3 CMD [ "/healthcheck" ]

CMD ["/proxy"]
15 changes: 15 additions & 0 deletions cmd/healthcheck/healthcheck.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

import (
"log"
"net/http"
"os"
)

func main() {
_, err := http.Get("http://127.0.0.1:4321/health")
if err != nil {
log.Printf("Healthcheck failed: %s\n", err)
os.Exit(1)
}
}
5 changes: 5 additions & 0 deletions internal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ func (a *App) Run() error {
}

func (a *App) configRoutes() {
a.engine.GET("/health", func(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{
"status": "ok",
})
})
a.engine.Any("/", a.handleIcal)
f := http.FS(static)
a.engine.StaticFS("/files/", f)
Expand Down

0 comments on commit 06ad64e

Please sign in to comment.