Skip to content

Commit

Permalink
feat: add healthcheck command
Browse files Browse the repository at this point in the history
  • Loading branch information
almeidapaulopt committed Oct 28, 2024
1 parent e2deb25 commit fa86805
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 12 deletions.
29 changes: 25 additions & 4 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ env:
- GITHUB_ORG=almeidapaulopt
- DOCKER_ORG=almeidapaulopt
- DOCKERFILE=Dockerfile.goreleaser
- MAIN=./cmd/server/
- BINARY=tsdproxyd

before:
hooks:
Expand All @@ -23,8 +21,9 @@ gomod:
report_sizes: true

builds:
- binary: "{{ .Env.BINARY }}"
main: "{{ .Env.MAIN }}"
- id: server
main: ./cmd/server/main.go
binary: tsdproxyd
env:
- CGO_ENABLED=0
goos:
Expand All @@ -46,6 +45,28 @@ builds:
ldflags:
- -s -w -X "github.com/almeidapaulopt/tsdproxy/core.buildString={{ .Tag }} ({{ .ShortCommit }} {{ .Date }}, {{ .Os }}/{{ .Arch }})" -X "github.com/almeidapaulopt/tsdproxy/core.version={{ .Tag }}"

- id: healthcheck
main: ./cmd/healthcheck/main.go
binary: healthcheck
env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64
- arm
goarm:
- "6"
- "7"
ignore:
- goarch: arm
goos: windows
- goarch: arm64
goos: freebsd

universal_binaries:
- replace: false

Expand Down
9 changes: 5 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ COPY . .

# Compila a aplicação Go
RUN go mod tidy && CGO_ENABLED=0 GOOS=linux go build -o /tsdproxyd ./cmd/server/main.go
RUN CGO_ENABLED=0 GOOS=linux go build -o /healthcheck ./cmd/healthcheck/main.go


FROM scratch

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

# add curl
COPY --from=ghcr.io/tarampampam/curl:8.10.1 /bin/curl /bin/curl
COPY --from=builder /tsdproxyd /tsdproxyd
COPY --from=builder /healthcheck /healthcheck

ENTRYPOINT ["/tsdproxyd"]

EXPOSE 8080
HEALTHCHECK CMD curl --fail http://127.0.0.1:8080/health/ready/
HEALTHCHECK CMD [ "/healthcheck" ]
8 changes: 4 additions & 4 deletions Dockerfile.goreleaser
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ FROM alpine:latest AS certs
RUN apk add --no-cache ca-certificates && update-ca-certificates 2>/dev/null || true

FROM scratch

COPY --from=certs /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
# add curl
COPY --from=ghcr.io/tarampampam/curl:8.10.1 /bin/curl /bin/curl

ENTRYPOINT ["/tsdproxyd"]
COPY tsdproxyd /
COPY healthcheck /

ENTRYPOINT ["/tsdproxyd"]
EXPOSE 8080
HEALTHCHECK CMD curl --fail http://127.0.0.1:8080/health/ready/
HEALTHCHECK CMD [ "/healthcheck" ]
13 changes: 13 additions & 0 deletions cmd/healthcheck/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package main

import (
"net/http"
"os"
)

func main() {
_, err := http.Get("http://127.0.0.1:8080/health/ready/")
if err != nil {
os.Exit(1)
}
}

0 comments on commit fa86805

Please sign in to comment.